react-native-bottom-sheet: [v4] | [v2] BottomSheetFooter on top of BottomSheetFlatList items when there are a few items that don't cover entire screen

Bug

So I have a BottomSheetFlatList which has only 2 items and I am using BottomSheetFooter to show a sticky footer.

Even though I have 2 items, I see only one item and I have to scroll to see other ones while the modal doesn’t even cover half of the screen so there is enough space for the modal to expand more to show the remaining items.

If I add 3 more items for example the modal expands more and all the items are shown on the screen without the need to scroll. For users, it’s very difficult to think that there is another item in there and they need to scroll.

Environment info

Library Version
@gorhom/bottom-sheet 4.6.1
react-native 0.72.5
react-native-reanimated 3.5.4
react-native-gesture-handler 2.12.1

Describe what you expected to happen:

1.The footer should be shown and all the items should be visible in the screen since there is more than enough space.

Reproducible sample code

<BottomSheetModal
          enableDynamicSizing
          enablePanDownToClose
          index={0}
          handleIndicatorStyle={modalStyles.handleStyle}
          keyboardBlurBehavior="restore"
          keyboardBehavior={keyboardBehavior}
          android_keyboardInputMode="adjustPan"
          maxDynamicContentSize={DYNAMIC_CONTENT_MAX_HEIGHT}
          ref={bottomSheetModalRef}
          footerComponent={
            showFooter
              ? props => (
                <BottomSheetFooter {...props}>
                  <ModalFooter
                    primaryButtonProps={primaryButtonProps}
                    textButtonProps={textButtonProps}
                  />
                </BottomSheetFooter>
                )
              : undefined
          }
        >
          <BottomSheetFlatList
              keyboardShouldPersistTaps="always"
              keyboardDismissMode="interactive"
              {...flatListProps}
              contentContainerStyle={[
                modalStyle,
                onSearchText && modalStyles.flatListSearch,
              ]}
              scrollEnabled={scrollEnabled}
              data={data}
              ListHeaderComponent={headerComponent}
              enableFooterMarginAdjustment
            />
        </BottomSheetModal>

Screenshot from 2024-07-05 15-29-13 Screenshot from 2024-07-05 15-30-11

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 3
  • Comments: 16

Most upvoted comments

By analyzing the BottomSheetFlatList props, I was able to find a solution to get around the problem: you need to use the “enableFooterMarginAdjustment” property on the BottomSheetFlatList so that the footer doesn’t hide the listing.

const Comment = () => {
  return (
    <BottomSheet
      ref={ref}
      index={1}
      snapPoints={snapPoints}
      enablePanDownToClose
      enableDynamicSizing={false}
      handleIndicatorStyle={{ backgroundColor: colors.black[80] }}
      backgroundStyle={{ backgroundColor: colors.black[100] }}
      backdropComponent={renderBackdrop}
      onClose={handleClose}
      keyboardBehavior={Platform.OS === "ios" ? "extend" : "interactive"}
      keyboardBlurBehavior="restore"
      android_keyboardInputMode="adjustResize"
      footerComponent={(props) => {
        return (
          <BottomSheetFooter {...props}>
            <MyInput />
          </BottomSheetFooter>
        );
      }}
    >
      <BottomSheetFlatList
        data={[]}
        keyExtractor={(item) => "key-" + item.id}
        renderItem={renderItem}
        contentContainerStyle={{ padding: 20 }}
        keyboardDismissMode="none"
        showsVerticalScrollIndicator={false}
        enableFooterMarginAdjustment // THIS
        ListEmptyComponent={() => {
          if (!loading) {
            return (
              <View className="flex flex-col justify-center items-center flex-1 py-10">
                <Text className="font-medium text-white text-lg">OK</Text>
              </View>
            );
          }
        }}
        onEndReached={handleLoadMore}
      />
    </BottomSheet>
  );
};