question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[v4] Entire view being blocked by BottomSheetBackdrop

See original GitHub issue

Bug

The first time it works as expected, but once I move to some other screen and come back, all touch events are blocked by the backdrop overlay. Though, the backdrop component is not visible at that time.

The same app is tested on Android and iOS, but the issue is only present on the Android device.

Environment info

Library Version
@gorhom/bottom-sheet 4
react-native expo: sdk-42.0.0
react-native-reanimated 2.2.0
react-native-gesture-handler 1.10.2

Device Details:

OS: Android 11 (MIUI Global 12.5.8 Stable) Model: Redmi Note 10 Pro (M2101K6P)

Steps To Reproduce

  1. Open the bottom sheet and close it
  2. Change to some other using stack navigator
  3. Come back to this page, touch events should be blocked.

Reproducible sample code

Its all from example code, still I’m adding the code here:

  const bottomSheetRef = useRef();
  const snapPoints = useMemo(() => ["80%"], []);

  const renderBackdrop = useCallback(
    (props) => (
      <BottomSheetBackdrop
        {...props}
        disappearsOnIndex={-1}
        appearsOnIndex={0}
        enableTouchThrough={true}
      />
    ),
    []
  );

  return (
  <KeyboardAvoidingView
      style={styles.groceriesParentView}
      behavior={Platform.OS === "ios" ? "padding" : null}>
      <SafeAreaView style={styles.container}>
        
        <BottomSheet
          ref={bottomSheetRef}
          index={-1}
          snapPoints={snapPoints}
          onChange={handleSheetChanges}
          enablePanDownToClose={true}
          backdropComponent={renderBackdrop}>
             <View>...<View/>
        </BottomSheet>

      </SafeAreaView>
    </KeyboardAvoidingView>
)

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:7
  • Comments:9

github_iconTop GitHub Comments

5reactions
rauchpcommented, Oct 29, 2021

Using the Custom Backdrop example (https://gorhom.github.io/react-native-bottom-sheet/custom-backdrop) I saw the same problem.

I fixed it by adding pointerEvents="none" to the Animated.View in the example.

E.g return <Animated.View pointerEvents="none" style={containerStyle} />;

Does this fix it for you? @Prabindas001

2reactions
farsadfcommented, Nov 4, 2021

For those who are still struggling with this issue. As a temporary fix, it’s possible to introduce a flag and hide the backdrop component by returning null from the render function before the first opening.

The following workaround fixes the issue in Android devices with higher SDK versions, that utilize the animatedSnapPoints value from the useBottomSheetDynamicSnapPoints hook.

const [hasExpandedAtLeastOnce, setHasExpandedAtLeastOnce] = useState(false);

const expand = useCallback(() => {
    if (!bottomSheetRef.current) return;

    bottomSheetRef.current.expand();
    setHasExpandedAtLeastOnce(true);
}, [bottomSheetRef.current]);

const renderBackdrop = useCallback((props: BottomSheetDefaultBackdropProps) => {
    if (!hasExpandedAtLeastOnce)
        return null;

    return <BottomSheetBackdrop disappearsOnIndex={-1} appearsOnIndex={0} {...props} />;
}, [hasExpandedAtLeastOnce]);

Then add this to your BottomSheet component:

backdropComponent={renderBackdrop}
Read more comments on GitHub >

github_iconTop Results From Across the Web

[v4] Adding index={-1} in certain devices blocks the view ...
In certain devices only : Add an index={-1} in the BottomSheet is causing the entire screen to be non-functional. It is as though...
Read more >
BottomSheetBackdrop | React Native Bottom Sheet
A pre-built BottomSheet backdrop implementation with configurable props. Props​. Inherits ViewProps from react-native . animatedIndex ​. Current sheet position ...
Read more >
https://amlormusic.com/wp-content/plugins/gutenber...
Changelog == = 12.5.4 = ### Bug Fixes #### Block Library - Fix and refine core ... user experience with blocks editor when...
Read more >
error warning: function components cannot be given refs ...
As the warning state you cannot assign refs to functional component without the usage the forwardRef. In order to have access to refs...
Read more >
Add state changed callback to SwipeableState [164113834]
Since the bug was filed we adopted the hoisted state approach for swipeable (and many of it's users, like bottom sheet, backdrop, drawers)...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found