I am using React Native and the React-Navigation library to replicate the nav behavior in the iOS Reddit app Apollo: https://i.imgur.com/983G04Q.png
My routing structure is as follows:
TabNavigation
|- PostsTab
|- PostsStack
|- SubredditListScreen
|- PostFeedScreen
|- PostDetailsScreen
I want to achieve the following:
- When the app starts, the user sees the
PostFeedScreen. - The
PostFeedScreenhas a "Back" button in its header that navigates to theSubredditListScreen. - If the
PostsTabtab bar is pressed when onPostFeedScreen, scroll to the top, and if already at the top, navigate to theSubredditListScreen. - The
SubredditListScreendoesn't have a back button, but the user can drag from the right-edge to return to thePostFeedScreen.
This is the code I have:
// TabNavigation.tsx
function TabNavigation() {
return (
<Tab.Navigator>
<Tab.Screen name={SCREENS.POSTS} component={PostsStackScreen} />
// ..other non-relevant tabs
</Tab.Navigator>
);
}
// PostsStackScreen.tsx
function PostsStackScreen() {
return (
<PostsStack.Navigator initialRouteName={SCREENS.POSTS_FEED}>
<PostsStack.Screen name={SCREENS.SUBREDDITS_LIST} component={SubredditsScreen} />
<PostsStack.Screen name={SCREENS.POSTS_FEED} component={PostFeedScreen} />
<PostsStack.Screen name={SCREENS.POST_DETAILS} component={PostDetailsScreen} />
</PostsStack.Navigator>
);
}
However, my code doesn't work as expected:
- The app correctly initializes to the
PostFeedScreen, but there is no "Back" button to theSubredditsscreen. - Clicking the tab button doesn't take the user to the
Subredditsscreen.
How can I accomplish the above with React-Navigation? Thank you!