Skip to content

[Bug]: BottomSheet Disappears on Android after Location Permissions #2691

Description

@lxr-mwhite

Version

v5

Reanimated Version

v3

Gesture Handler Version

v2

Platforms

Android

What happened?

On Android, the BottomSheet disappears if it's mounted at the same time as a location permission request, after interacting with the dialog and a child component of the BottomSheet is re-rendered.

Using react-native-reanimated v4.3.1.

Reproduction steps

  • Launch an app on Android for the first time, or with location permissions set to "Ask every time"
  • Request permission for the user's location
  • Render a BottomSheet component on launch
  • Trigger a state change that updates a child component

Example:

import React, { useCallback, useEffect, useState } from 'react';
import { StyleSheet, Text } from 'react-native';
import { GestureHandlerRootView } from 'react-native-gesture-handler';
import BottomSheet, { BottomSheetView } from '@gorhom/bottom-sheet';
import Permissions, { PERMISSIONS } from 'react-native-permissions';

const LOCATION_PERMISSION = PERMISSIONS.ANDROID.ACCESS_FINE_LOCATION;

const App = () => {
  const [locationStatus, setLocationStatus] = useState('undetermined');

  const requestLocationPermission = useCallback(async () => {
    const checkStatus = await Permissions.check(LOCATION_PERMISSION);
    let hasLocationPermission = checkStatus === Permissions.RESULTS.GRANTED;
    if (!hasLocationPermission) {
      const requestStatus = await Permissions.request(LOCATION_PERMISSION);
      hasLocationPermission = requestStatus === Permissions.RESULTS.GRANTED;
    }
    return hasLocationPermission;
  }, []);

  useEffect(() => {
    requestLocationPermission().then((hasLocationPermission) =>
      setLocationStatus(hasLocationPermission ? 'authorized' : 'not allowed')
    );
  }, [requestLocationPermission]);

  return (
    <GestureHandlerRootView style={styles.container}>
      <BottomSheet index={2} snapPoints={[120, 500, 750]} enableDynamicSizing={false} animateOnMount={false}>
        <BottomSheetView style={styles.content}>
          <Text>{locationStatus}</Text>
        </BottomSheetView>
      </BottomSheet>
    </GestureHandlerRootView>
  );
};

export default App;

const styles = StyleSheet.create({
  container: {
    ...StyleSheet.absoluteFillObject,
    backgroundColor: '#00ffff'
  },
  content: {
    flex: 1,
    backgroundColor: '#eeeeee',
    padding: 20,
    alignItems: 'center'
  }
});

Reproduction sample

https://snack.expo.dev/@gorhom/bottom-sheet---issue-reproduction-template

Relevant log output

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions