mirror of
https://github.com/zoriya/react-native-web.git
synced 2026-06-02 02:25:22 +00:00
[fix] setNativeProps and pointerEvent prop
The pointerEvent prop is converted into a DOM style property and needs to be accounted for by setNativeProps. Close #1656 Fix #1655
This commit is contained in:
+6
-4
@@ -54,8 +54,6 @@ const Picker = forwardRef<PickerProps, *>((props, forwardedRef) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
usePlatformMethods(hostRef, [], style);
|
|
||||||
|
|
||||||
function handleChange(e: Object) {
|
function handleChange(e: Object) {
|
||||||
const { selectedIndex, value } = e.target;
|
const { selectedIndex, value } = e.target;
|
||||||
if (onValueChange) {
|
if (onValueChange) {
|
||||||
@@ -63,7 +61,7 @@ const Picker = forwardRef<PickerProps, *>((props, forwardedRef) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return createElement('select', {
|
const supportedProps = {
|
||||||
children,
|
children,
|
||||||
disabled: enabled === false ? true : undefined,
|
disabled: enabled === false ? true : undefined,
|
||||||
onChange: handleChange,
|
onChange: handleChange,
|
||||||
@@ -72,7 +70,11 @@ const Picker = forwardRef<PickerProps, *>((props, forwardedRef) => {
|
|||||||
testID,
|
testID,
|
||||||
value: selectedValue,
|
value: selectedValue,
|
||||||
...other
|
...other
|
||||||
});
|
};
|
||||||
|
|
||||||
|
usePlatformMethods(hostRef, supportedProps);
|
||||||
|
|
||||||
|
return createElement('select', supportedProps);
|
||||||
});
|
});
|
||||||
|
|
||||||
// $FlowFixMe
|
// $FlowFixMe
|
||||||
|
|||||||
+2
-1
@@ -121,7 +121,6 @@ const Text = forwardRef<TextProps, *>((props, forwardedRef) => {
|
|||||||
];
|
];
|
||||||
|
|
||||||
useElementLayout(hostRef, onLayout);
|
useElementLayout(hostRef, onLayout);
|
||||||
usePlatformMethods(hostRef, classList, style);
|
|
||||||
useResponderEvents(hostRef, {
|
useResponderEvents(hostRef, {
|
||||||
onMoveShouldSetResponder,
|
onMoveShouldSetResponder,
|
||||||
onMoveShouldSetResponderCapture,
|
onMoveShouldSetResponderCapture,
|
||||||
@@ -160,6 +159,8 @@ const Text = forwardRef<TextProps, *>((props, forwardedRef) => {
|
|||||||
supportedProps.ref = setRef;
|
supportedProps.ref = setRef;
|
||||||
supportedProps.style = style;
|
supportedProps.style = style;
|
||||||
|
|
||||||
|
usePlatformMethods(hostRef, supportedProps);
|
||||||
|
|
||||||
const element = createElement(component, supportedProps);
|
const element = createElement(component, supportedProps);
|
||||||
|
|
||||||
return hasTextAncestor ? (
|
return hasTextAncestor ? (
|
||||||
|
|||||||
@@ -330,7 +330,6 @@ const TextInput = forwardRef<TextInputProps, *>((props, forwardedRef) => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
useElementLayout(hostRef, onLayout);
|
useElementLayout(hostRef, onLayout);
|
||||||
usePlatformMethods(hostRef, classList, style);
|
|
||||||
useResponderEvents(hostRef, {
|
useResponderEvents(hostRef, {
|
||||||
onMoveShouldSetResponder,
|
onMoveShouldSetResponder,
|
||||||
onMoveShouldSetResponderCapture,
|
onMoveShouldSetResponderCapture,
|
||||||
@@ -370,6 +369,8 @@ const TextInput = forwardRef<TextInputProps, *>((props, forwardedRef) => {
|
|||||||
supportedProps.style = style;
|
supportedProps.style = style;
|
||||||
supportedProps.type = multiline ? undefined : type;
|
supportedProps.type = multiline ? undefined : type;
|
||||||
|
|
||||||
|
usePlatformMethods(hostRef, supportedProps);
|
||||||
|
|
||||||
return createElement(component, supportedProps);
|
return createElement(component, supportedProps);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -116,7 +116,6 @@ const View = forwardRef<ViewProps, *>((props, forwardedRef) => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
useElementLayout(hostRef, onLayout);
|
useElementLayout(hostRef, onLayout);
|
||||||
usePlatformMethods(hostRef, classList, style);
|
|
||||||
useResponderEvents(hostRef, {
|
useResponderEvents(hostRef, {
|
||||||
onMoveShouldSetResponder,
|
onMoveShouldSetResponder,
|
||||||
onMoveShouldSetResponderCapture,
|
onMoveShouldSetResponderCapture,
|
||||||
@@ -141,6 +140,8 @@ const View = forwardRef<ViewProps, *>((props, forwardedRef) => {
|
|||||||
supportedProps.ref = setRef;
|
supportedProps.ref = setRef;
|
||||||
supportedProps.style = style;
|
supportedProps.style = style;
|
||||||
|
|
||||||
|
usePlatformMethods(hostRef, supportedProps);
|
||||||
|
|
||||||
return createElement('div', supportedProps);
|
return createElement('div', supportedProps);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
+7
-10
@@ -7,18 +7,18 @@
|
|||||||
* @flow
|
* @flow
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import type { GenericStyleProp } from '../types';
|
|
||||||
import type { ElementRef } from 'react';
|
import type { ElementRef } from 'react';
|
||||||
|
|
||||||
import UIManager from '../exports/UIManager';
|
import UIManager from '../exports/UIManager';
|
||||||
import createDOMProps from '../modules/createDOMProps';
|
import createDOMProps from '../modules/createDOMProps';
|
||||||
import { useImperativeHandle, useRef } from 'react';
|
import { useImperativeHandle, useRef } from 'react';
|
||||||
|
|
||||||
function setNativeProps(node, nativeProps, classList, style, previousStyleRef) {
|
function setNativeProps(node, nativeProps, classList, pointerEvents, style, previousStyleRef) {
|
||||||
if (node != null && nativeProps) {
|
if (node != null && nativeProps) {
|
||||||
const domProps = createDOMProps(null, {
|
const domProps = createDOMProps(null, {
|
||||||
|
pointerEvents,
|
||||||
...nativeProps,
|
...nativeProps,
|
||||||
classList: [nativeProps.className, classList],
|
classList: [classList, nativeProps.className],
|
||||||
style: [style, nativeProps.style]
|
style: [style, nativeProps.style]
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -45,12 +45,9 @@ function setNativeProps(node, nativeProps, classList, style, previousStyleRef) {
|
|||||||
* Adds non-standard methods to the hode element. This is temporarily until an
|
* Adds non-standard methods to the hode element. This is temporarily until an
|
||||||
* API like `ReactNative.measure(hostRef, callback)` is added to React Native.
|
* API like `ReactNative.measure(hostRef, callback)` is added to React Native.
|
||||||
*/
|
*/
|
||||||
export default function usePlatformMethods(
|
export default function usePlatformMethods(hostRef: ElementRef<any>, props: Object) {
|
||||||
hostRef: ElementRef<any>,
|
|
||||||
classList: Array<boolean | string>,
|
|
||||||
style: GenericStyleProp<any>
|
|
||||||
) {
|
|
||||||
const previousStyleRef = useRef(null);
|
const previousStyleRef = useRef(null);
|
||||||
|
const { classList, style, pointerEvents } = props;
|
||||||
|
|
||||||
useImperativeHandle(
|
useImperativeHandle(
|
||||||
hostRef,
|
hostRef,
|
||||||
@@ -61,9 +58,9 @@ export default function usePlatformMethods(
|
|||||||
UIManager.measureLayout(hostNode, relativeToNode, failure, success);
|
UIManager.measureLayout(hostNode, relativeToNode, failure, success);
|
||||||
hostNode.measureInWindow = callback => UIManager.measureInWindow(hostNode, callback);
|
hostNode.measureInWindow = callback => UIManager.measureInWindow(hostNode, callback);
|
||||||
hostNode.setNativeProps = nativeProps =>
|
hostNode.setNativeProps = nativeProps =>
|
||||||
setNativeProps(hostNode, nativeProps, classList, style, previousStyleRef);
|
setNativeProps(hostNode, nativeProps, classList, pointerEvents, style, previousStyleRef);
|
||||||
return hostNode;
|
return hostNode;
|
||||||
},
|
},
|
||||||
[classList, hostRef, style]
|
[hostRef, classList, pointerEvents, style]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user