【问题标题】:SectionList Scroll to specific sectionSectionList 滚动到特定部分
【发布时间】:2021-02-08 17:04:48
【问题描述】:

当点击按钮时,我正在尝试将 sectionList 滚动到特定部分。 我每次都会收到这个错误:

未捕获的类型错误:scrollRef.scrollToLocation 不是函数。

我错过了什么?

var scrollRef = useRef()


const onScroll = () => {            
        scrollRef.current.scrollToLocation({
            sectionIndex: 1,
            viewPosition: 0,
            itemIndex: 1,
        })
    }

     <SectionList
                style={styles.sectionList}
                ListHeaderComponent={<ChefHighlight chef={props.chef}/>}
                keyExtractor={(item, index) => item.name}
                sections={ data }
                renderSectionHeader={({ section }) => {
                    return (
                        <View style={styles.headerView}>
                            <Text style={[globalStyle.textPrimary, styles.sectionTitle]}>{section.title}</Text>
                            <View style={{paddingLeft: 20, alignItems:'center', flexDirection: 'row'}}>
                                <MaterialIcons name="date-range" size={18} color={colors.textTertiary} />
                                <Text style={{alignSelf: 'center', textAlign: 'center', marginBottom: 6, marginLeft: 8, color: colors.textTertiary, fontSize: 14, marginTop: 8, }}>Delivers on {section.title}'s</Text>
                            </View>
                        </View>
                    );
                }}
                renderItem={({ item }) => {
                    return <ComboCell item={item} onOpen={onOpen}/>
                }}

                onScroll={Animated.event(
                    [{ nativeEvent: { contentOffset:  { y: scrollY }}}],
                    // { useNativeDriver: true }
                  )}
                
                
                ref={scrollRef}
                ListFooterComponent={<View style={{width: '100%', height: 100}}/>}
            />  

【问题讨论】:

    标签: javascript reactjs react-native react-native-sectionlist


    【解决方案1】:

    如果你使用scrollToLocation,你必须添加getItemLayout

    【讨论】:

      猜你喜欢
      • 2017-09-13
      • 1970-01-01
      • 2019-10-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-21
      相关资源
      最近更新 更多