React-native-tab-view: How to implement scroll to top function in "onTabPress"

Created on 13 Nov 2019  Â·  3Comments  Â·  Source: satya164/react-native-tab-view

Current behaviour

Currently my renderScene is rendering a custom component which using FlatList. I have done some research on FlatList's scrollToIndex, and they all using something called refs. My question is how do I pass the refs from the FlatList in the custom component back to the parent component?

Expected behaviour

When active tab is "Tab one", and I tab on "Tab one" again, it should scroll to top.

Code sample


https://snack.expo.io/@jasonkw-abc/bd48f8

Screenshots (if applicable)

What have you tried

Your Environment

| software | version
| ---------------------------- | -------
| ios or android | android
| react-native | 0.61.2
| react-native-tab-view | 2.10.0
| react-native-gesture-handler | 1.5.0
| react-native-reanimated | 1.3.2
| node | 10.15
| npm or yarn | 6.4.1

bug

All 3 comments

My question is how do I pass the refs from the FlatList in the custom component back to the parent component

You don't pass ref from child to parent, you use React.createRef to to create ref objects in parent, pass them down to your components and use them.

Please post questions on stack overflow.

@satya164 Thank you so much!

@jasonkw9 do you have a working solution you can show?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

AndriiUhryn picture AndriiUhryn  Â·  3Comments

QuentinBrosse picture QuentinBrosse  Â·  4Comments

chen504554911 picture chen504554911  Â·  3Comments

KingAmo picture KingAmo  Â·  3Comments

ashusdn picture ashusdn  Â·  4Comments