How do I also specify the section index when scrolled to, and make the scrolled object…
- User
How do I also specify the section index when scrolled to, and make the scrolled object at the top?
<SafeAreaView style={{ flex: 1, backgroundColor: theme.colors.onPrimary }}> <SectionList ref={sectionListRef} removeClippedSubviews={true} style={{ margin: 10 }} stickySectionHeadersEnabled={true} sections={foodData} keyExtractor={(item, index) => item + index} renderItem={({ item, index }) => { return ( <FoodPost onPress={() => { console.log(index); sectionListRef.current.scrollToLocation({ viewPosition: 0, sectionItex itemIndex: index, }); }} data={item} /> ) }} renderSectionHeader={({ section: { title } }) => ( <Text style={[styles.titleContainer, { backgroundColor: theme.colors.onPrimary }]}>{title} )} onRefresh={onRefresh} refreshing={refreshing}>
- Assistant
In your
renderItemfunction, you are logging the index of the item, but to scroll to a specific section and ensure that item is at the top, you need to provide both the section index and the item index. Additionally, you need to fix a minor typo in to .