Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to handle Android Hardware Back Button #1818

Open
salahbm opened this issue Apr 27, 2024 · 1 comment
Open

How to handle Android Hardware Back Button #1818

salahbm opened this issue Apr 27, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@salahbm
Copy link

salahbm commented Apr 27, 2024

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 salahbm added the enhancement New feature or request label Apr 27, 2024
Copy link

@salahbm: hello! 👋

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant