每次在react-native-bottom-sheet中调用useCallback时,强制BottomSheetFlatList从第一个位置打开

eoigrqb6  于 2022-11-25  发布在  React
关注(0)|答案(1)|浏览(139)

我使用的是带有BottomSheetFlatList的react-native-bottom-sheet。
我想在每次打开BottomSheetFlatList时都在initialPosition处打开它,但我无法做到这一点。当我打开它时,它总是在最后一个滚动位置打开。

<BottomSheet
        ref={bottomSheetRef}
        index={0}
        snapPoints={snapPoints}
        enableDismissOnClose={true}
        handleIndicatorStyle={{display: 'none'}}
        handleStyle={{padding: 0}}>
        <View style={{backgroundColor: '#b2b2b2', alignItems: 'center'}}>
          {!isOpen && (
            <Pressable onPress={() => handleSnapPress(1)}>
              <Image
                source={IconCollapse}
                style={{width: 30, height: 20, backgroundColor: '#b2b2b2'}}
              />
            </Pressable>
          )}

          {isOpen && (
            <Pressable onPress={() => handleClosePress()}>
              <Image
                source={IconExpand}
                style={{width: 30, height: 20, backgroundColor: '#b2b2b2'}}
              />
            </Pressable>
          )}
        </View>
        <View style={{backgroundColor: '#b2b2b2'}}>
          <Text
            style={{
              color: 'white',
              fontSize: 20,
              textTransform: 'uppercase',
              paddingStart: 10,
            }}>
            Select Zone
          </Text>
          <View
            style={{
              borderBottomColor: '#fff',
              borderBottomWidth: 1,

              marginEnd: 10,
              marginStart: 10,
            }}
          />
        </View>
        <BottomSheetFlatList
          data={zoneList}

          keyExtractor={(item, index) => `${index}`}
          renderItem={renderItem}
          
         
                    contentContainerStyle={styles.contentContainer}
        />
      </BottomSheet>
fwzugrvs

fwzugrvs1#

使用属性enableDismissOnClose
如这里所述

相关问题