Skip to content

Commit

Permalink
fix(web): replace setNativeProps with useState (#1076)(by @RobertSasak)
Browse files Browse the repository at this point in the history
React-native-web do not handle setNativeProps
  • Loading branch information
RobertSasak committed Sep 9, 2022
1 parent 29af238 commit 625049f
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions src/components/bottomSheetBackdrop/BottomSheetBackdrop.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { memo, useCallback, useMemo, useRef } from 'react';
import React, { memo, useCallback, useMemo, useState } from 'react';
import { ViewProps } from 'react-native';
import Animated, {
interpolate,
Extrapolate,
Expand Down Expand Up @@ -46,8 +47,9 @@ const BottomSheetBackdropComponent = ({
//#endregion

//#region variables
const containerRef = useRef<Animated.View>(null);
const pointerEvents = enableTouchThrough ? 'none' : 'auto';
const [pointerEvents, setPointerEvents] = useState<
ViewProps['pointerEvents']
>(enableTouchThrough ? 'none' : 'auto');
//#endregion

//#region callbacks
Expand All @@ -62,13 +64,7 @@ const BottomSheetBackdropComponent = ({
}, [snapToIndex, close, disappearsOnIndex, pressBehavior]);
const handleContainerTouchability = useCallback(
(shouldDisableTouchability: boolean) => {
if (!containerRef.current) {
return;
}
// @ts-ignore
containerRef.current.setNativeProps({
pointerEvents: shouldDisableTouchability ? 'none' : 'auto',
});
setPointerEvents(shouldDisableTouchability ? 'none' : 'auto');
},
[]
);
Expand Down Expand Up @@ -118,8 +114,8 @@ const BottomSheetBackdropComponent = ({
return pressBehavior !== 'none' ? (
<TapGestureHandler onGestureEvent={gestureHandler}>
<Animated.View
ref={containerRef}
style={containerStyle}
pointerEvents={pointerEvents}
accessible={true}
accessibilityRole="button"
accessibilityLabel="Bottom Sheet backdrop"
Expand All @@ -131,11 +127,7 @@ const BottomSheetBackdropComponent = ({
</Animated.View>
</TapGestureHandler>
) : (
<Animated.View
ref={containerRef}
pointerEvents={pointerEvents}
style={containerStyle}
>
<Animated.View pointerEvents={pointerEvents} style={containerStyle}>
{children}
</Animated.View>
);
Expand Down

0 comments on commit 625049f

Please sign in to comment.