Javascript 对react native中scrollToLocation的回调

Javascript 对react native中scrollToLocation的回调,javascript,reactjs,react-native,scroll,react-native-sectionlist,Javascript,Reactjs,React Native,Scroll,React Native Sectionlist,在我的react native分区列表中的滚动动量完成后,我尝试运行一个函数 在参考文档后,我发现了关于onMomentumScrollEnd。但是问题是只有当我们手动滚动节列表时,onMomentumScrollEnd的才起作用。但是我在一个函数中使用了scrollToLocation来滚动到特定的部分。当在MomentumScrollEnd上使用该时,似乎不会触发。使用scrollToLocation <SectionList sections={groupActi

在我的react native分区列表中的滚动动量完成后,我尝试运行一个函数

在参考文档后,我发现了关于
onMomentumScrollEnd
。但是问题是只有当我们手动滚动节列表时,onMomentumScrollEnd的
才起作用。但是我在一个函数中使用了
scrollToLocation
来滚动到特定的部分。当在MomentumScrollEnd上使用该
时,似乎不会触发。使用
scrollToLocation

<SectionList
          sections={groupActivities}
          keyExtractor={(item) => item?.id?.toString()}
          ref={sectionList}
          getItemLayout={getItemLayout}
          onMomentumScrollEnd={() => console.log('ends')}
          renderItem={({ section: { title }, item, index }) => {
            const sectionTitle = String(title);
            return (
              <View style={activityContainer}>
                <MCard
                  startTime={getFormattedStartTime(item.duration?.start)}
                />
              </View>
            );
          }}
          renderSectionHeader={({ section: { title } }) => (
            <MText>
              {setSectionTitle}
            </MText>
          )}
          refreshing={groupActivityLoading}
          onRefresh={handleRefresh}
        />
item?.id?.toString()}
ref={sectionList}
getItemLayout={getItemLayout}
onMomentumScrollEnd={()=>console.log('ends')}
renderItem={({节:{title},项,索引})=>{
const sectionTitle=字符串(标题);
返回(
);
}}
renderSectionHeader={({section:{title}}})=>(
{setSectionTitle}
)}
刷新={groupActivityLoading}
onRefresh={handleRefresh}
/>

您是如何触发
滚动定位的

请使用参考文献检查我的示例:

  const Example = () => {
  const sectionListRef = useRef(null);

  return (
    <SafeAreaView style={styles.container}>
      <Button
        title="Scroll"
        onPress={() => {
          sectionListRef.current.scrollToLocation({
            itemIndex: 6,
          });
        }}
      />
      <SectionList
        ref={sectionListRef}
        onMomentumScrollEnd={() => alert('ends')}
        sections={DATA}
        keyExtractor={(item, index) => item + index}
        renderItem={({item}) => <Item title={item} />}
        renderSectionHeader={({section: {title}}) => (
          <Text style={styles.header}>{title}</Text>
        )}
      />
    </SafeAreaView>
  );
};
const示例=()=>{
const sectionListRef=useRef(null);
返回(
{
sectionListRef.current.scrollToLocation({
项目索引:6,
});
}}
/>
警报('ends')}
节={DATA}
keyExtractor={(项,索引)=>item+index}
renderItem={({item})=>}
renderSectionHeader={({section:{title}}})=>(
{title}
)}
/>
);
};


完整代码: 如果要在设备上进行测试,请参阅以下完整代码: