skip to Main Content

I’m using the popular package @gorhom/bottom-sheet for a bottom sheet in React Native documented here. However, I am getting the above error when trying to present the modal.

The above error suggests that I must have a PanGestureHandler as a descendant of the GestureHandlerRootView however, this also crashes the app.

APP.JS:

return (
  <BottomSheetModalProvider>
    <NavigationContainer>
      {user ? <AuthorizedLayout /> : <UnauthorizedLayout />}
    </NavigationContainer>
  </BottomSheetModalProvider>
);

MY MODAL SCREEN

return (
    <>
      {loading ? (
        <ExploreSkeleton />
      ) : (
        <>
          <ExploreHeader
            userData={userData}
            presentCityModal={presentCityModal}
          />
          <FlatList
            data={venues}
            ListHeaderComponent={listHeaderComponent}
            renderItem={renderItem}
            ListFooterComponent={listFooterComponent}
            contentContainerStyle={styles.contentContainerStyle}
            onEndReached={getMoreVenues}
            onEndReachedThreshold={0.5}
          />
          <GestureHandlerRootView>
            <BottomSheetModal snapPoints={snapPoints} ref={bottomSheetModalRef}>
              <View>
                <Text>TESTING MODAL</Text>
              </View>
            </BottomSheetModal>
          </GestureHandlerRootView>
        </>
      )}
    </>
  );

I HAVE TRIED:

<GestureHandlerRootView>
   <PanGestureHandler>
     <BottomSheetModal
       snapPoints={snapPoints}
       ref={bottomSheetModalRef}>
       <View>
         <Text>TESTING MODAL</Text>
       </View>
     </BottomSheetModal>
   </PanGestureHandler>
 </GestureHandlerRootView>

But this gives me;

Argument appears to not be a ReactComponent.

2

Answers


  1. Chosen as BEST ANSWER

    Found the answer here. You need to have the <GestureHandlerRootView> before the <BottomSheetModalProvider>

    Code below;

    APP.JS

    return (
        <GestureHandlerRootView style={{ flex: 1 }}>
          <BottomSheetModalProvider>
            <NavigationContainer>
              {user ? <AuthorizedLayout /> : <UnauthorizedLayout />}
            </NavigationContainer>
          </BottomSheetModalProvider>
        </GestureHandlerRootView>
      );
    

  2. You should add GestureHandlerRootView to APP.JS, not just only wrap PanGestureHandler:

    return (
      <BottomSheetModalProvider>
        <NavigationContainer>
          <GestureHandlerRootView> // <== add this
            {user ? <AuthorizedLayout /> : <UnauthorizedLayout />}
          </GestureHandlerRootView> // <== add this
        </NavigationContainer>
      </BottomSheetModalProvider>
    );
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search