1

The biggest problem of StackNavigator is that components won't be unmounted, i.e., componentWillUnmount() won't be invoked.

But I need this component stage to unbind event, or to do other things. And that's why I started using DrawerNavigator.

But this brings another issue which StackNavigator would solve automatically.

I have a component which loads data from the server. In this component, I just show the summery, and whenever a user clicks on that, another component appears to show details. That means there are two components (screen). So, a user navigates to detail screen, (AppNavigator.router.getStateForAction(NavigationActions.navigate({routeName: action.route}), currentState);) and then he/she pressed (hardware) back button, as I override the default behavior of this event (close the app), he/she will navigate to list screen. Now, the problem is, say he/she was in 15th data, now when he/she navigated from detail screen, the scrollbar is in first data! Had I used StackNavigator, the scrollbar would have been in 15th data.

I implemented this using ScrollView, and FlatList. Used onMomentumScrollEnd props to get more data from the server.

So, how can I solve this, the scrollbar should be placed where it was last time, and at the same time get the feature of componetWillUnmount?

emtiajium
  • 81
  • 9
  • save that scroll position and then use ListView.scrollTo and get last stored position form your cache – Atif AbbAsi Apr 11 '18 at 12:58
  • Would you please tell me how to get current scroll position? – emtiajium Apr 13 '18 at 05:11
  • calculated height, and used `this.flatListRef.scrollToOffset({offset: value})` to scroll to a position. – emtiajium Apr 18 '18 at 05:49
  • https://stackoverflow.com/questions/29503252/get-current-scroll-position-of-scrollview-in-react-native?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa check this answer – Atif AbbAsi Apr 18 '18 at 06:47

0 Answers0