1

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 PostFeedScreen has a "Back" button in its header that navigates to the SubredditListScreen.
  • If the PostsTab tab bar is pressed when on PostFeedScreen, scroll to the top, and if already at the top, navigate to the SubredditListScreen.
  • The SubredditListScreen doesn't have a back button, but the user can drag from the right-edge to return to the PostFeedScreen.

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 the Subreddits screen.
  • Clicking the tab button doesn't take the user to the Subreddits screen.

How can I accomplish the above with React-Navigation? Thank you!

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.