Skip to content

Commit 89d38b8

Browse files
committed
fix: replace pointerEvents props with styles
By replacing usages of `pointerEvents` to use styles instead of props, we won't get an annoying warning in the logs. The underlying issue in React Native Web which prevented children of a `pointer-events: box-none` element from receiving pointer events is resolved by necolas/react-native-web#2789 Fixes react-navigation#12441
1 parent 69b2c14 commit 89d38b8

File tree

24 files changed

+142
-99
lines changed

24 files changed

+142
-99
lines changed

example/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"react-native-reanimated": "~3.18.0",
3737
"react-native-safe-area-context": "5.5.0",
3838
"react-native-screens": "~4.11.1",
39-
"react-native-web": "~0.20.0"
39+
"react-native-web": "~0.21.0"
4040
},
4141
"devDependencies": {
4242
"@babel/core": "^7.27.4",

packages/bottom-tabs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"devDependencies": {
4848
"@jest/globals": "^30.0.0",
4949
"@react-navigation/native": "workspace:^",
50-
"@testing-library/react-native": "^13.2.0",
50+
"@testing-library/react-native": "^13.2.1",
5151
"@types/color": "^4.2.0",
5252
"@types/react": "~19.0.10",
5353
"del-cli": "^6.0.0",

packages/bottom-tabs/src/views/BottomTabBar.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,12 +380,14 @@ export function BottomTabBar({
380380
paddingHorizontal: Math.max(insets.left, insets.right),
381381
},
382382
],
383+
{
384+
pointerEvents: isTabBarHidden ? 'none' : 'auto',
385+
},
383386
tabBarStyle,
384387
]}
385-
pointerEvents={isTabBarHidden ? 'none' : 'auto'}
386388
onLayout={sidebar ? undefined : handleLayout}
387389
>
388-
<View pointerEvents="none" style={StyleSheet.absoluteFill}>
390+
<View style={[StyleSheet.absoluteFill, { pointerEvents: 'none' }]}>
389391
{tabBarBackgroundElement}
390392
</View>
391393
<View

packages/core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
},
5151
"devDependencies": {
5252
"@jest/globals": "^30.0.0",
53-
"@testing-library/react-native": "^13.2.0",
53+
"@testing-library/react-native": "^13.2.1",
5454
"@types/react": "~19.0.10",
5555
"@types/react-is": "^19.0.0",
5656
"@types/use-sync-external-store": "^1.5.0",

packages/drawer/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
"@babel/core": "^7.27.4",
5656
"@jest/globals": "^30.0.0",
5757
"@react-navigation/native": "workspace:^",
58-
"@testing-library/react-native": "^13.2.0",
58+
"@testing-library/react-native": "^13.2.1",
5959
"@types/react": "~19.0.10",
6060
"del-cli": "^6.0.0",
6161
"react": "19.0.0",

packages/elements/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"@jest/globals": "^30.0.0",
5151
"@react-native-masked-view/masked-view": "0.3.2",
5252
"@react-navigation/native": "workspace:^",
53-
"@testing-library/react-native": "^13.2.0",
53+
"@testing-library/react-native": "^13.2.1",
5454
"@types/react": "~19.0.10",
5555
"@types/use-sync-external-store": "^1.5.0",
5656
"del-cli": "^6.0.0",

packages/elements/src/Header/Header.tsx

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -285,32 +285,45 @@ export function Header(props: Props) {
285285

286286
return (
287287
<Animated.View
288-
pointerEvents="box-none"
289-
style={[{ height, minHeight, maxHeight, opacity, transform }]}
288+
style={[
289+
{
290+
pointerEvents: 'box-none',
291+
height,
292+
minHeight,
293+
maxHeight,
294+
opacity,
295+
transform,
296+
},
297+
]}
290298
>
291299
<Animated.View
292-
pointerEvents="box-none"
293-
style={[StyleSheet.absoluteFill, backgroundContainerStyle]}
300+
style={[
301+
StyleSheet.absoluteFill,
302+
{ pointerEvents: 'box-none' },
303+
backgroundContainerStyle,
304+
]}
294305
>
295306
{headerBackground ? (
296307
headerBackground({ style: backgroundStyle })
297308
) : (
298309
<HeaderBackground
299-
pointerEvents={
300-
// Allow touch through the header when background color is transparent
301-
headerTransparent &&
302-
(backgroundStyle.backgroundColor === 'transparent' ||
303-
Color(backgroundStyle.backgroundColor).alpha() === 0)
304-
? 'none'
305-
: 'auto'
306-
}
307-
style={backgroundStyle}
310+
style={[
311+
{
312+
// Allow touch through the header when background color is transparent
313+
pointerEvents:
314+
headerTransparent &&
315+
(backgroundStyle.backgroundColor === 'transparent' ||
316+
Color(backgroundStyle.backgroundColor).alpha() === 0)
317+
? 'none'
318+
: 'auto',
319+
},
320+
backgroundStyle,
321+
]}
308322
/>
309323
)}
310324
</Animated.View>
311-
<View pointerEvents="none" style={{ height: headerStatusBarHeight }} />
325+
<View style={{ pointerEvents: 'none', height: headerStatusBarHeight }} />
312326
<View
313-
pointerEvents="box-none"
314327
style={[
315328
styles.content,
316329
Platform.OS === 'ios' && frame.width >= IPAD_MINI_MEDIUM_WIDTH
@@ -319,7 +332,6 @@ export function Header(props: Props) {
319332
]}
320333
>
321334
<Animated.View
322-
pointerEvents="box-none"
323335
style={[
324336
styles.start,
325337
!searchBarVisible && headerTitleAlign === 'center' && styles.expand,
@@ -332,7 +344,6 @@ export function Header(props: Props) {
332344
{Platform.OS === 'ios' || !searchBarVisible ? (
333345
<>
334346
<Animated.View
335-
pointerEvents="box-none"
336347
style={[
337348
styles.title,
338349
{
@@ -369,7 +380,6 @@ export function Header(props: Props) {
369380
})}
370381
</Animated.View>
371382
<Animated.View
372-
pointerEvents="box-none"
373383
style={[
374384
styles.end,
375385
styles.expand,
@@ -421,6 +431,7 @@ export function Header(props: Props) {
421431

422432
const styles = StyleSheet.create({
423433
content: {
434+
pointerEvents: 'box-none',
424435
flex: 1,
425436
flexDirection: 'row',
426437
alignItems: 'stretch',
@@ -430,16 +441,19 @@ const styles = StyleSheet.create({
430441
},
431442
title: {
432443
justifyContent: 'center',
444+
pointerEvents: 'box-none',
433445
},
434446
start: {
435447
flexDirection: 'row',
436448
alignItems: 'center',
437449
justifyContent: 'flex-start',
450+
pointerEvents: 'box-none',
438451
},
439452
end: {
440453
flexDirection: 'row',
441454
alignItems: 'center',
442455
justifyContent: 'flex-end',
456+
pointerEvents: 'box-none',
443457
},
444458
expand: {
445459
flexGrow: 1,

packages/elements/src/Header/HeaderSearchBar.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,16 @@ function HeaderSearchBarInternal(
156156

157157
return (
158158
<Animated.View
159-
pointerEvents={visible ? 'auto' : 'none'}
160159
aria-live="polite"
161160
aria-hidden={!visible}
162-
style={[styles.container, { opacity: visibleAnim }, style]}
161+
style={[
162+
styles.container,
163+
{
164+
pointerEvents: visible ? 'auto' : 'none',
165+
opacity: visibleAnim,
166+
},
167+
style,
168+
]}
163169
>
164170
<View style={styles.searchbarContainer}>
165171
<HeaderIcon

packages/elements/src/ResourceSavingView.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@ export function ResourceSavingView({
2727
// @ts-expect-error: hidden exists on web, but not in React Native
2828
hidden={!visible}
2929
style={[
30-
{ display: visible ? 'flex' : 'none' },
30+
{
31+
display: visible ? 'flex' : 'none',
32+
pointerEvents: visible ? 'auto' : 'none',
33+
},
3134
styles.container,
3235
style,
3336
]}
34-
pointerEvents={visible ? 'auto' : 'none'}
3537
{...rest}
3638
>
3739
{children}
@@ -52,7 +54,6 @@ export function ResourceSavingView({
5254
// This is an workaround for a bug where the clipped view never re-appears
5355
Platform.OS === 'ios' || Platform.OS === 'macos' ? !visible : true
5456
}
55-
pointerEvents={visible ? 'auto' : 'none'}
5657
style={visible ? styles.attached : styles.detached}
5758
>
5859
{children}
@@ -68,9 +69,11 @@ const styles = StyleSheet.create({
6869
},
6970
attached: {
7071
flex: 1,
72+
pointerEvents: 'auto',
7173
},
7274
detached: {
7375
flex: 1,
7476
top: FAR_FAR_AWAY,
77+
pointerEvents: 'none',
7578
},
7679
});

packages/elements/src/Screen.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ export function Screen(props: Props) {
7171
<NavigationContext.Provider value={navigation}>
7272
<NavigationRouteContext.Provider value={route}>
7373
<View
74-
pointerEvents="box-none"
7574
onLayout={(e) => {
7675
const { height } = e.nativeEvent.layout;
7776

@@ -111,6 +110,7 @@ const styles = StyleSheet.create({
111110
},
112111
header: {
113112
zIndex: 1,
113+
pointerEvents: 'box-none',
114114
},
115115
absolute: {
116116
position: 'absolute',

0 commit comments

Comments
 (0)