slorber / react-native-scroll-into-view

Scroll a ReactNative View into the visible screen. Similar to DOMElement.scrollIntoView() browser function.
https://thisweekinreact.com
MIT License
415 stars 13 forks source link

Using with Flatlist #14

Closed alexpchin closed 4 years ago

alexpchin commented 4 years ago

I have a setup with KeyboardAwareScrollView but for some screens, I use KeyboardAwareFlatList in order to avoid VirtualizedLists should never be nested inside plain ScrollViews with the same orientation.

I would like to do something like:

const ScrollIntoViewScrollView = wrapScrollViewConfigured({
  refPropName: 'innerRef',
})(KeyboardAwareScrollView);

// ScrollIntoView API is not provided in React context. Make sure you wrapped your ScrollView with ScrollIntoViewWrapper
const ScrollIntoViewFlatList = wrapScrollViewConfigured({
  getScrollViewNode: ref => ref,
  refPropName: 'innerRef',
})(KeyboardAwareFlatList);

Has anyone achieved this without changing lots of the package?

slorber commented 4 years ago

Hi,

Unfortunately it is not possible, this lib requires elements to be rendered to compute the appropriate position, so it can't work with virtualization at all, and will only even support ScrollView.

But, FlatList has imperative methods that you can use, like "scrollToIndex": https://reactnative.dev/docs/flatlist#scrolltoindex