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] Adding index={-1} in certain devices blocks the view (Example device: Oneplus 5)

See original GitHub issue

Bug

In certain devices like the OnePlus 5, adding an index={-1} is causing the entire screen to be non-functional, i.e, we’re unable to click anywhere on the screen. If we remove this prop, then everything seems to be working fine. But of course we need the BottomSheet to be in closed state initially, hence not adding this prop is not a solution. But this does work fine on other devices we’ve tested.

This issue is affecting many users in Production, since we’re using BottomSheet in many screens and the Users are unable to use those screens.

Environment info

Library Version
@gorhom/bottom-sheet 4.1.5
react-native 0.64.2
react-native-reanimated 2.2.4
react-native-gesture-handler 1.10.3

Steps To Reproduce

In certain devices only : Add an index={-1} in the BottomSheet is causing the entire screen to be non-functional. It is as though there’s an overlay on top of the screen which doesn’t let us access whatever is currently rendered.

Describe what you expected to happen:

It should not render the screen non-functional.

Reproducible sample code

import React, { useCallback } from 'react';
import { StyleSheet, Keyboard } from 'react-native';
import PropTypes from 'prop-types';
import { bottomSheetHeaderHandler } from 'colors';
import {
  heightPercentageToDP as hp,
  widthPercentageToDP as wp,
} from 'react-native-responsive-screen';

const renderBackdrop = props => (
  <BottomSheetBackdrop {...props} disappearsOnIndex={-1} appearsOnIndex={0} />
);

const BottomSheet = React.forwardRef((props, ref) => {
  const { children, onChange, ...restProps } = props;

  const handleChange = useCallback(index => {
    if (index === -1) {
      // When the BottomSheet is closed, dismiss any open Keyboard
      Keyboard.dismiss();
    }
    // Call the actual onChange handler passing in the index
    onChange?.(index);
  }, []);

  return (
    <BottomSheetGorhom
      index={-1}
      enablePanDownToClose
      backdropComponent={renderBackdrop}
      handleIndicatorStyle={styles.handleIndicatorStyle}
      ref={ref}
      onChange={handleChange}
      {...restProps}
    >
      {children}
    </BottomSheetGorhom>
  );
});

const styles = StyleSheet.create({
  handleIndicatorStyle: {
    width: wp('12.6%'),
    height: hp('0.65%'),
    borderRadius: 4,
    backgroundColor: bottomSheetHeaderHandler,
  },
});

BottomSheet.propTypes = {
  children: PropTypes.node,
  onChange: PropTypes.func,
};

export default BottomSheet;

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:9
  • Comments:21 (2 by maintainers)

github_iconTop GitHub Comments

7reactions
vinkimcommented, Jan 19, 2022

I looked into this issue a bit myself on my Samsung S8+ device that is able to reproduce this issue.

In the BottomSheetBackDrop component you have the following code.

  //#region effects
  useAnimatedReaction(
    () => animatedIndex.value <= disappearsOnIndex,
    (shouldDisableTouchability, previous) => {
      if (shouldDisableTouchability === previous) {
        return;
      }
      runOnJS(handleContainerTouchability)(shouldDisableTouchability);
    },
    [disappearsOnIndex]
  );
  //#endregion

Which will call into handleContainerTouchability and set the pointerEvents prop.

  const handleContainerTouchability = useCallback(
    (shouldDisableTouchability: boolean) => {
      if (!containerRef.current) {
        return;
      }
      // @ts-ignore
      containerRef.current.setNativeProps({
        pointerEvents: shouldDisableTouchability ? 'none' : 'auto',
      });
    },
    []
  );

On my Samsung Galaxy S8+ the animatedIndex.value is reported as:

 // Samsung
 LOG  [ SM-G955F ] animatedIndex.value:  -1
 LOG  [ SM-G955F ] animatedIndex.value:  -0.9999999548556524
 // Simulator
 LOG  [ Android SDK built for x86 ] animatedIndex.value:  -1
 LOG  [ Android SDK built for x86 ] animatedIndex.value:  -1

As seen above, the animatedIndex.value <= disappearsOnIndex ( -0.9999999548556524 <= -1 ) will result in false, and the pointerEvents will be set to ‘none’, and the input will be blocked.

2reactions
omar-diopcommented, Feb 24, 2022

I encountered the same problem: on some Xiaomi or Samsung device the whole screen becomes freezed.

The only workaround i found is to set index={0} and provide a 0 snap point that has 0 height like the following:

const snapPoints = useMemo( () => ( [0, "60%", "80%"] ), [], );
<BottomSheet
      ref={ensureRef}
      index={Platform.OS === "android" ? 0 : -1}
      snapPoints={snapPoints}
      backdropComponent={BottomSheetBackdrop}
      backgroundComponent={() => <View style={styles.background} />}
      onChange={handleSheetChange}>
     {...children}
    </BottomSheet>
Read more comments on GitHub >

github_iconTop Results From Across the Web

[CM11S] Fresh CM11S Installation Guide - OnePlus Community
Power on your device and do the following steps: 1. USB Debugging - On your phone go to Settings > About phone >...
Read more >
Secret Codes on OnePlus
If your mobile phone is stolen, you can call or go to the nearest service center of your mobile network and give that...
Read more >
[Nord 2] Video freezes in Chrome, audio & captions continue
I mostly experience this issue while using Chrome to view high-resolution videos embedded in my timeline on Facebook; I think I've also seen...
Read more >
(closed )OnePlus Gcam Issue
To give you an idea of where I'm coming from, I can use all cameras and use full resolution (48MP in my case)...
Read more >
[The Lab] OnePlus 7 Pro Review - dnagpaldg
4. Benchmarks and real-life performance 5. Battery and Warp Charge 30 6. Telephony 7. OxygenOS and software-based features 8. Camera 9. How the...
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