satya164 / react-native-tab-view

A cross-platform Tab View component for React Native
MIT License
5.13k stars 1.07k forks source link

On navigate back doesnt lock the scroll position #856

Closed Chatharaju closed 5 years ago

Chatharaju commented 5 years ago

Current behaviour

My tab view renders a scrollview and mapping a list. When I navigate to a different screen by clicking one of the item, when I navigating back the list automatically goes to the top. Happens only in Android

Expected behaviour

The list should not scroll to top.

Screenshots (if applicable)

device-2019-07-29-151826

Code sample

<TabView navigationState={this.state} renderScene={SceneMap({ current: () => <FlatList data={[{ key: 'a' }, { key: 'b' }, { key: 'c' }, { key: 'd' }, { key: 'e' }, { key: 'f' }, { key: 'g' }, { key: 'h' }, { key: 'i' }, { key: 'j' }, { key: 'k' }, { key: 'l' }, { key: 'm' }, { key: 'n' }, { key: 'o' }, { key: 'p' }, { key: 'q' }, { key: 'R' }]} renderItem={({ item }) => <TouchableOpacity onPress={(props) => onItemPress(props)}> <View style={{ borderWidth: 1 }}> <Text style={{ fontSize: 20, marginBottom: 30 }}>{item.key} } />, past: () => <FlatList data={[{ key: 'a' }, { key: 'b' }, { key: 'c' }, { key: 'd' }, { key: 'e' }, { key: 'f' }, { key: 'g' }, { key: 'h' }, { key: 'i' }, { key: 'j' }, { key: 'k' }, { key: 'l' }, { key: 'm' }, { key: 'n' }, { key: 'o' }, { key: 'p' }, { key: 'q' }, { key: 'R' }]} renderItem={({ item }) => <TouchableOpacity onPress={(props) => onItemPress(props)}> <View style={{ borderWidth: 1 }}> <Text style={{ fontSize: 20, marginBottom: 30 }}>{item.key} } /> />, })} onIndexChange={index => this.setState({ index })} initialLayout={styles.tabSize} renderTabBar={props => <TabBar {...props} getLabelText={({ route }) => route.title} activeColor={Primary.Black} inactiveColor={conGray} indicatorStyle={styles.tabIndicator} style={styles.tabs} labelStyle={styles.labelStyle} /> } />

const styles = StyleSheet.create({ main: { flex: 1, backgroundColor: "#f8f8f8", paddingTop: 6 }, content: { marginBottom: 100 }, noMsg: { marginTop: 50, textAlign: 'center' }, loading: { flex: 1, flexDirection: 'column', justifyContent: 'center', alignItems: 'stretch', } })

software version
android 7.1.1
react-native 0.59.2
react-native-tab-view 2.9.0
react-native-gesture-handler 1.0.16
react-native-reanimated 1.0.0-alpha.12
satya164 commented 5 years ago

Please provide a proper runnable repro as per the issue template

Chatharaju commented 5 years ago

Please have a look at the .gif.

satya164 commented 5 years ago

Please post your code

Chatharaju commented 5 years ago

there you go. I cannot put the original code but pretty much mocked it.

satya164 commented 5 years ago

You're passing inline functions to SceneMap. The docs explicitly say not to do that.

https://github.com/react-native-community/react-native-tab-view#renderscene-required

image