I am using Native Base and TabNavigator to display custom tabs.
How can I change the "active" property of the Button element to reflect the custom active tab?
Solved by adding:
active={props.navigation.state.index === 0}
Here is the logged value:
Also, you can go to state.routes to get the list of the screens.
Related
I have a react native app which uses react navigation (V6.x for sure). My app has a main navigator which is a bottom-tabs navigator and contains three screens (tabs). Every one of these screens are stack navigators themselves. Let's say one of my tabs is named Wallet (others are Settings and Transactions). Inside this Wallet screen (which is a stack navigator), i have a HomePage screen, a Receive screen and a Send screen. I want to achieve the following behavior (like below screenshot from designs):
Whenever the user goes to one of Send or Receive screens, i want all the tab bar buttons become unfocused (tab bar is still visibe though). And whenever the user gets back to HomePage screen (or going to Settings or Transactions tab by pressing the corresponding tab button), I want the relevant tab button to get focused again. How can i achieve that with react navigation itself?
(My project is managed by redux, but i prefer not to use state management tools and use react navigation itself)
You can do that, but checking child navigation state inside your TabNavigator's screenOptions.
screenOptions={({ route, navigation }) => {
// get wallet stack route
const walletStack = navigation.getState().routes.find((route) => route.name === 'Wallet');
// get current wallet stack focused screen
const walletRouteName = getFocusedRouteNameFromRoute(walletStack);
const shouldBeUnfocused =
walletRouteName === 'Send' || walletRouteName === 'Receive';
{...}
}
Based on shouldBeUnfocused you can render proper icons and colors. Here is the snack with example code. You can red here about customizing tab bar's appearance.
I have a button on my header right that open up a drop down component. The component allow user to make some selection and apply it after the user hit the 'apply' button.
After the apply button pressed, it should be able to pass the value back to the 'main screen' component. How do I pass the value back to the 'main screen' ?
This is my interface , if you're wondering what I'm trying to do.
edit
I tried to pass in the useState function to the header component to update the state after the apply button pressed by passing it using the setParam from react navigation props. Is there any other better way to get the value ??
You can do it simply like:
props.navigation('Home', { state: SOME_VALUE });
Here is the react navigation doc to do this.
React navigation passing params to previous screen
Or you can use redux store.
I'm using BottomTabNavigator for my React Native application. I've 4 tabs named TabA, TabB, TabC and TabD.
Basically, React Native render the tabs once they're focused however in my situation i would like to pre-render TabC even it's not focused jet so my question is how can i pre-render a Tab without focusing on it?
You have to set the lazy property to false.
By default, it will be set to true. So each tab will render only when appears on the screen.
You have to change it explicitly by
createBottomTabNavigator({
viewProfile: ViewProfileScreen,
calendar: CalendarScreen,
},
lazy: false
);
I'd like to pass the values from Tab to another Tab and I follow instructions from this tutorial https://reactnavigation.org/docs/en/params.html
I got the values at the end but i don't want to change the screen suddenly.
I tried to use 'setParams' instead but it doesn't work.
Setting tab (Selection) :
onPress={() => {
console.log('Select : '+ item.code);
this.props.navigation.navigate('A-page', {adCode: item.code});
}}
First tab (A-page) :
this.setState ({
AirportCode : this.props.navigation.getParam('adCode','----')
})
Any ideas for passing values across Tab navigation or method to stop changing the screen suddenly?
This looks more like a Redux use case then a React Navigation one. If you wanna change properties that influence more than one screen in your app, you should store these properties at the redux store.
I'm developing my first react native app. I've an issue with the nested navigations in the app.
I've the following navigations:
Main App Navigator : createStackNavigator
Authentication Navigator : createStackNavigator
Bottom Bar Navigator : createBottomTabNavigator
Top Tab Navigator : createMaterialTopTabNavigator
My too nested Navigator : createStackNavigator
What i want ?
I'm trying to hide the BottomBar & TopTab Navigators headers form a screen in the last nested navigator.
What I did?
Ive tried to set the header as null in my nested nav, but thats hides the nested header not the parents headers.
I also tried to set the parents headers as nulls, but thats hide them from all screen.
I need to only hide them in this nested screen. Can I change the parents headers property from my nested React Class?
Unfortunately, I didn't figure how to do that without using redux.
So I had to do a workaround.
I declared my Nested Navigator directly in the Main Navigator. "in the same level as Authentication & Bottom Bar Navigations" and set the header as null for this specific nav.
And then, navigate to that nested whenever i want.
Also, I had to add my custom icon to navigate the user back. because in our case there is no history in the new navigator in order to navigate back to.
so, i did like this:
static navigationOptions = ({ navigation }) => ({
headerLeft: (
<Icon
name="chevron-left"
color="#fff"
underlayColor="#4BA6F8"
onPress={() => {
const backAction = NavigationActions.back();
navigation.dispatch(backAction);
}}
/>
),
});
I know this is not the real answer for my question, but at least it solved my issue.