react-native-bottom-sheet icon indicating copy to clipboard operation
react-native-bottom-sheet copied to clipboard

How to handle Android Hardware Back Button

Open salahbm opened this issue 1 year ago • 1 comments

Feature Request

1. I have tried this way and couple other options. but still not perfectly working. Sometimes it blocks to navigate back.

Why it is needed

  1. To Close the Open Bottom Sheet with button

Possible implementation

  1. Please check Code down Below

Code sample

  const handleAndroidBackButton = useCallback(() => {
    if (Platform.OS === 'android' && updateIndex >= 0) {
      console.log(`updateIndex:`, updateIndex);
      bottomSheetModalLayoutRef.current?.close();
      setUpdateIndex(-1);
      return true; // Consume the back press event
    }
    return false; // Allow default back press behavior if bottom sheet is closed
  }, [updateIndex, bottomSheetModalLayoutRef]);

  useEffect(() => {
    const backHandlerSubscription = BackHandler.addEventListener(
      'hardwareBackPress',
      handleAndroidBackButton,
    );

    return () => {
      backHandlerSubscription.remove();
    };
  }, [handleAndroidBackButton]);

salahbm avatar Apr 27 '24 05:04 salahbm

@salahbm: hello! :wave:

This issue is being automatically closed because it does not follow the issue template.

github-actions[bot] avatar Apr 27 '24 05:04 github-actions[bot]

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar May 27 '24 09:05 github-actions[bot]

This issue was closed because it has been stalled for 5 days with no activity.

github-actions[bot] avatar Jun 01 '24 09:06 github-actions[bot]