question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Question: Set active tab to original scene on stack on tapping a tab item

See original GitHub issue

I think this qualifies more as a question than an issue since i may perhaps be missing some prop or setting.

TLDR;

a) press a tabitem and navigate to the corresponding screen b) Press an inner button here to navigate to another screen (non-tabbed perhaps) c) Press any tabitem(could even be the same item tapped earlier) to get back to the main tab scene for that tab item d) presented with the screen from b) while i expect to see the screen from a)

I have this in my App file:

const stateNavigator = new StateNavigator([
  { key: 'mainmenu', trackCrumbTrail: true },
  { key: 'maindailyspecials', trackCrumbTrail: true },
  { key: 'mainmore', trackCrumbTrail: true },
  { key: 'mainadmin', trackCrumbTrail: true },
]);
 
const { mainmenu, maindailyspecials, mainmore, mainadmin } = stateNavigator.states;
mainmenu.renderScene = () => <MainMenu />;
maindailyspecials.renderScene = () => <MainDailySpecials />;
mainmore.renderScene = () => <MainMore />;
mainadmin.renderScene = () => <MainAdmin />;

const dailySpecialsNavigator = new StateNavigator(stateNavigator);
const mainMoreNavigator = new StateNavigator(stateNavigator);

stateNavigator.navigate('mainmenu');
dailySpecialsNavigator.navigate('maindailyspecials');
mainMoreNavigator.navigate('mainmore');

     <TabBar bottomTabs={true}>
        <TabBarItem title="Menu">
          <NavigationHandler stateNavigator={stateNavigator}>
            <NavigationStack
              primary={true}
              crumbStyle={from => from ? 'scale_in' : 'scale_out'}
              unmountStyle={from => from ? 'slide_in' : 'slide_out'} />
          </NavigationHandler>
        </TabBarItem>
        <TabBarItem
          title="Daily Specials"
          onPress={() => {
          }
          }
        >
          <NavigationHandler stateNavigator={dailySpecialsNavigator}>
            <NavigationStack
              primary={false}
              crumbStyle={from => from ? 'scale_in' : 'scale_out'}
              unmountStyle={from => from ? 'slide_in' : 'slide_out'} />
          </NavigationHandler>
        </TabBarItem>
        .....
        .... more tab items
        .....
        <TabBarItem
          title="More..."

          onPress={() => { }}>
          <NavigationHandler stateNavigator={mainMoreNavigator}>
            <NavigationStack
              primary={false}
              crumbStyle={from => from ? 'scale_in' : 'scale_out'}
              unmountStyle={from => from ? 'slide_in' : 'slide_out'} />
          </NavigationHandler>
        </TabBarItem>
      </TabBar>


I navigate to the More... tab which is basically a screen with a list of further links. An Admin link here will navigate to the Admin screen. I now tap on any tab item to move away from the Admin screen. I then proceed to tap on the More tab item again. I am now presented with the Admin screen while i am expecting to see the More screen.

My More file:

const MainMore: React.FunctionComponent = () => {
    const [submitting, setSubmitting] = useState(false);
    const { stateNavigator } = useContext(NavigationContext)
    const goToAdmin = () => {
        stateNavigator.navigate("mainadmin")
    }
    return (<>
        <View style={{ flex: 1, flexDirection: "column", }}>
            <Text>
                More
                </Text>
            <View style={{ flexDirection: "column", flexGrow: 1, flexShrink: 1, flexBasis: "auto" }}>
                <ActionButton title="To Admin" submitting={submitting} onPress={goToAdmin} type="tertiary" />
            </View>

        </View>
    </>
    )
}
export default MainMore;

How do i reset the screen to More on tapping the tab after i’ve move away from it earlier? I can of course navigate anywhere using buttons within the Admin screen(or even the back buttons/links), but this issue only surfaces on attempting via taps on tab items.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:19 (19 by maintainers)

github_iconTop GitHub Comments

1reaction
grahammendickcommented, Nov 13, 2019

You should turn off the mounting animation for the first scenes of each tab

bottomTab1.unmountStyle = 'none';
bottomTab2.unmountStyle = 'none';
...
<NavigationHandler stateNavigator={stateNavigator}>
  <NavigationStack unmountStyle={(from, state) => state.unmountStyle} />
</NavigationHandler>
1reaction
grahammendickcommented, Nov 13, 2019

Try setting primary={false} on both the inner tab stacks.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Detecting tap on a tab in UITabBarController - Stack Overflow
I can move through tabs perfectrly, Now I have ta tableView in my homeViewController. Which I want to reload when ever user taps...
Read more >
Ability to define a custom onPress for a tab #314 - GitHub
This is a catch-all issue for TabBar onPress , that is: ability to define a custom press handler; press tab to reset active...
Read more >
Creating tabs with TabView and tabItem() - Hacking with Swift
Although you can tap on the left and right parts of that gray space ... First, we need some state to track the...
Read more >
How to create a custom Tab Bar in SwiftUI - BLCKBIRDS
In this SwiftUI tutorial, we will learn how to create our own custom and fully customizable tab bar.
Read more >
TabNavigator reference - React Navigation
tabBarOptions for TabBarTop (default tab bar on Android)​ · activeTintColor - Label and icon color of the active tab. · inactiveTintColor - Label...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found