Skip to content

Commit 7ef0701

Browse files
committed
[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
1 parent 728e20f commit 7ef0701

5 files changed

Lines changed: 19 additions & 17 deletions

File tree

packages/react-native-web/src/exports/Picker/index.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,14 @@ const Picker = forwardRef<PickerProps, *>((props, forwardedRef) => {
5454
}
5555
});
5656

57-
usePlatformMethods(hostRef, [], style);
58-
5957
function handleChange(e: Object) {
6058
const { selectedIndex, value } = e.target;
6159
if (onValueChange) {
6260
onValueChange(value, selectedIndex);
6361
}
6462
}
6563

66-
return createElement('select', {
64+
const supportedProps = {
6765
children,
6866
disabled: enabled === false ? true : undefined,
6967
onChange: handleChange,
@@ -72,7 +70,11 @@ const Picker = forwardRef<PickerProps, *>((props, forwardedRef) => {
7270
testID,
7371
value: selectedValue,
7472
...other
75-
});
73+
};
74+
75+
usePlatformMethods(hostRef, supportedProps);
76+
77+
return createElement('select', supportedProps);
7678
});
7779

7880
// $FlowFixMe

packages/react-native-web/src/exports/Text/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ const Text = forwardRef<TextProps, *>((props, forwardedRef) => {
121121
];
122122

123123
useElementLayout(hostRef, onLayout);
124-
usePlatformMethods(hostRef, classList, style);
125124
useResponderEvents(hostRef, {
126125
onMoveShouldSetResponder,
127126
onMoveShouldSetResponderCapture,
@@ -160,6 +159,8 @@ const Text = forwardRef<TextProps, *>((props, forwardedRef) => {
160159
supportedProps.ref = setRef;
161160
supportedProps.style = style;
162161

162+
usePlatformMethods(hostRef, supportedProps);
163+
163164
const element = createElement(component, supportedProps);
164165

165166
return hasTextAncestor ? (

packages/react-native-web/src/exports/TextInput/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,6 @@ const TextInput = forwardRef<TextInputProps, *>((props, forwardedRef) => {
330330
);
331331

332332
useElementLayout(hostRef, onLayout);
333-
usePlatformMethods(hostRef, classList, style);
334333
useResponderEvents(hostRef, {
335334
onMoveShouldSetResponder,
336335
onMoveShouldSetResponderCapture,
@@ -370,6 +369,8 @@ const TextInput = forwardRef<TextInputProps, *>((props, forwardedRef) => {
370369
supportedProps.style = style;
371370
supportedProps.type = multiline ? undefined : type;
372371

372+
usePlatformMethods(hostRef, supportedProps);
373+
373374
return createElement(component, supportedProps);
374375
});
375376

packages/react-native-web/src/exports/View/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ const View = forwardRef<ViewProps, *>((props, forwardedRef) => {
116116
);
117117

118118
useElementLayout(hostRef, onLayout);
119-
usePlatformMethods(hostRef, classList, style);
120119
useResponderEvents(hostRef, {
121120
onMoveShouldSetResponder,
122121
onMoveShouldSetResponderCapture,
@@ -141,6 +140,8 @@ const View = forwardRef<ViewProps, *>((props, forwardedRef) => {
141140
supportedProps.ref = setRef;
142141
supportedProps.style = style;
143142

143+
usePlatformMethods(hostRef, supportedProps);
144+
144145
return createElement('div', supportedProps);
145146
});
146147

packages/react-native-web/src/hooks/usePlatformMethods.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@
77
* @flow
88
*/
99

10-
import type { GenericStyleProp } from '../types';
1110
import type { ElementRef } from 'react';
1211

1312
import UIManager from '../exports/UIManager';
1413
import createDOMProps from '../modules/createDOMProps';
1514
import { useImperativeHandle, useRef } from 'react';
1615

17-
function setNativeProps(node, nativeProps, classList, style, previousStyleRef) {
16+
function setNativeProps(node, nativeProps, classList, pointerEvents, style, previousStyleRef) {
1817
if (node != null && nativeProps) {
1918
const domProps = createDOMProps(null, {
19+
pointerEvents,
2020
...nativeProps,
21-
classList: [nativeProps.className, classList],
21+
classList: [classList, nativeProps.className],
2222
style: [style, nativeProps.style]
2323
});
2424

@@ -45,12 +45,9 @@ function setNativeProps(node, nativeProps, classList, style, previousStyleRef) {
4545
* Adds non-standard methods to the hode element. This is temporarily until an
4646
* API like `ReactNative.measure(hostRef, callback)` is added to React Native.
4747
*/
48-
export default function usePlatformMethods(
49-
hostRef: ElementRef<any>,
50-
classList: Array<boolean | string>,
51-
style: GenericStyleProp<any>
52-
) {
48+
export default function usePlatformMethods(hostRef: ElementRef<any>, props: Object) {
5349
const previousStyleRef = useRef(null);
50+
const { classList, style, pointerEvents } = props;
5451

5552
useImperativeHandle(
5653
hostRef,
@@ -61,9 +58,9 @@ export default function usePlatformMethods(
6158
UIManager.measureLayout(hostNode, relativeToNode, failure, success);
6259
hostNode.measureInWindow = callback => UIManager.measureInWindow(hostNode, callback);
6360
hostNode.setNativeProps = nativeProps =>
64-
setNativeProps(hostNode, nativeProps, classList, style, previousStyleRef);
61+
setNativeProps(hostNode, nativeProps, classList, pointerEvents, style, previousStyleRef);
6562
return hostNode;
6663
},
67-
[classList, hostRef, style]
64+
[hostRef, classList, pointerEvents, style]
6865
);
6966
}

0 commit comments

Comments
 (0)