Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scrollToLocation doesn't work as expected #4

Open
DinoZenka opened this issue Mar 20, 2023 · 0 comments
Open

scrollToLocation doesn't work as expected #4

DinoZenka opened this issue Mar 20, 2023 · 0 comments

Comments

@DinoZenka
Copy link

I'm using inverted section list for a chat app. I need to implement scroll to the new received messages. I can calculate the index of section and index of specific item, but scrollToLocation method throw 'undefined is not a function'. If apply same code for built in SectionList, scroll works without errors.

RN version: 0.70.5

useEffect(() => {
if (messages.length && !newMessageScrolled) {
const sectionIndex = batchedMessages.findIndex((section) =>
section?.data?.find((a) => a.messageIndex === newMessagesCount.index)
);
if (sectionIndex !== -1 && newMessagesCount.index > 0 && listRef.current) {
listRef.current.scrollToLocation({ sectionIndex: sectionIndex, itemIndex: newMessagesCount.index });
setNewMessageScrolled(true);
}
}
}, [newMessageScrolled, newMessagesCount]);

<InvertedSectionList
ref={listRef}
contentContainerStyle={getListContainerStyle()}
onScrollToIndexFailed={handleScrollError}
bounces={false}
keyExtractor={listKeyExtractor}
sections={batchedMessages}
scrollEventThrottle={16}
onScroll={handleListScroll}
initialNumToRender={isTablet ? 10 : 16}
renderItem={renderMessage}
renderSectionFooter={renderSectionHeader}
stickyHeaderHiddenOnScroll={true}
stickySectionHeadersEnabled={true}
ListEmptyComponent={renderEmpty}
ListFooterComponent={renderFooter}
/>

Screenshot 2023-03-20 at 15 40 32

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant