React-native-keyboard-aware-scroll-view: FlatList - No scrollToIndex?

Created on 11 Jul 2019  路  6Comments  路  Source: APSL/react-native-keyboard-aware-scroll-view

Getting undefined when calling scrollToIndex from the component.

All 6 comments

Sorry, was using the wrong ref.

@cristianoccazinsp could you please elaborate on how you solved this? thanks

I stopped using this library a while ago so I can't really recall what was the right way to obtain a ref to the original flat list, but it should be simple to debug and find it out!

For whoever stumbles upon this in the future, I managed to solve this problem by doing this:

const scrollRef = useRef<{ flatListRef: Element | undefined }>({ flatListRef: undefined });
...
(scrollRef.current?.flatListRef as any).scrollToIndex(); //scrollToIndex() works
...
<KeyboardAwareFlatList
            innerRef={(ref) => (scrollRef.current.flatListRef = ref)}
...

Hi,

this approach does not work for me using class components. However, a different one does, namely by using callback refs.

Thanks mlthlschr,

Your solution worked for me in combination of using innerRef prop of the keyboardAwareFlatlist

Was this page helpful?
0 / 5 - 0 ratings