React Native - StackNavigator header has double height - reactjs

I have a similar issue as After upgrading to expo SDK 37.0.0 my stackNavigator header doubled in height, however I had the same problem with Expo SDK 36. I tried to upgrade Expo (37.0.0) and react-navigation version, but it had no effect on the header.
"react-navigation": "^3.13.0",
"react-navigation-drawer": "^1.4.0",
"react-navigation-stack": "^1.7.3",
"react-navigation-tabs": "^1.2.0",
I have an authentication switch (As in react-navigation docs), which then routes to a stack above the BottomTabNavigator. In this way I can have a screen rendered over the bottom bar. Then I have a list of stacks in the BottomTabNavigator.
// Main appNavigator
export default createAppContainer(
createAnimatedSwitchNavigator({
AuthLoading: AuthLoadingScreen,
Auth: AuthStack,
App: AboveBottomTabStack,
}, {
initialRouteName: 'AuthLoading',
})
);
// Components routed here are ABOVE bottom tab navigator
const AboveBottomTabStack = createStackNavigator(
{
Tabs: {
screen: MainTabNavigator,
navigationOptions: {
// Hides the header, in this case the headers of the Stack components inside TabNavigator are shown
header: null,
}
},
ReportScreen: ReportScreen
}
);
// Components routed here are UNDER bottom tab navigator
const MainTabNavigator = createBottomTabNavigator({
HomeStack: HomeStack,
ReportListStack: ReportListStack,
SettingsStack: SettingsStack,
});
// One of the stacks inside the TabNavigator
const HomeStack = createStackNavigator(
{
Dashboard: {
screen: DashboardScreen,
navigationOptions: {
headerStyle: {
//backgroundColor:'#00beb8',
height: 0, // Even with height 0 the header is displayed
}
}
},
}
);
I tried in setting the last stack's header to null (the one in HomeStack for example), and the header actually hides. The problem is the size, even if the height is set to 0, a small portion of header is displayed, you can see pictures in the linked question at the top.

Ok with the help of a friend we managed to find the solution to this problem.
Using the following prop in the navigation options fixed the issue for us:
navigationOptions: {
headerForceInset: { vertical: 'never' },
}
From what I understood from react-navigation docs it creates a SafeAreaView component around the app's content, however why does it create this annoying small bar on the top is still unknown to me.
EDIT: This prop should be written for android only, because on Iphone it creates graphical issues

Related

'transitionConfig' is removed in favor of the new animation APIs

I am working with a react native application, and it shows a warning in the console
import {createStackNavigator} from 'react-navigation-stack';
import {fromRight} from 'react-navigation-transitions';
const ApplyNowNav = createStackNavigator(
{
Home,
Profile,
},
{
headerMode: 'none',
transitionConfig: () => fromRight(),
}
);
WARN Deprecation in 'createStackNavigator':
transitionConfig' is removed in favor of the new animation APIs
Is there any solution to fix this issue?
You need to update your code to use to use the new Animation API: https://reactnavigation.org/docs/en/stack-navigator.html#animations
From the code you posted, you can change it to the following instead to have a slide from right animation:
import { createStackNavigator, TransitionPresets } from 'react-navigation-stack';
const ApplyNowNav = createStackNavigator(
{
Home,
Profile,
},
{
headerMode: 'none',
defaultNavigationOptions: {
...TransitionPresets.SlideFromRightIOS,
},
}
);
Update react-navigation and use creatStackNavigator component instead of StackNavigator.
Check current methods and syntax, there is a lot of changes compare to previous syntax.
Works for me when I updated the code

react-navigation for react native sending to wrong screen

I'm building a react-native app for iOS and Android.
I'm using react-navigation to deal with routing and navigation as follows:
const AppDrawerNavigation = createDrawerNavigator({
Login: {
screen: Screens.Auth.Login,
path: '/login'
},
Register: {
screen: Screens.Auth.Register,
path: '/register'
},
Forgotten: {
screen: Screens.Auth.Forgotten,
path: '/forgotten'
},
Profile: {
screen: Screens.Profile,
path: '/profile'
}
})
And then I render this in React
export default class App extends React.Component {
render() {
return <AppDrawerNavigation persistenceKey="AppDrawerNavigationState2" />
}
}
Worked fine at the beginning but now when I navigate it sends me to the wrong page or refers to pages that I have removed.
This is happening because of the persistence. It is remembering routes that it has stored.
For safety, everytime you add, remove and/or change the routing, you should change the persistenceKey to erase the it's previous value and store again.
Example:
<AppDrawerNavigation persistenceKey="AppDrawerNavigationState" />
to
<AppDrawerNavigation persistenceKey="AppDrawerNavigationState1" />
I added a "1" at the end of my persistenceKey name

react-navigation Screen that conceals TabBar from nested StackNavigator

I'm new to react-navigation and trying to wrap my head around how to do the following:
Given this navigation structure:
RootTabNavigator
LoggedOut_StackNavigator
...
LoggedIn_StackNavigator
LoggedIn_TabNavigator <-- TabBar rendered by this Navigator
TabA_StackNavigator
ScreenA
ScreenB
I would like to be able to navigate from ScreenA to ScreenB using the typical "slide in from right" transition, in such a way that the TabBar is visible on ScreenA, but is not visible on ScreenB. In other words, when I navigate to ScreenB, I want it to take up the entire window.
Once the user transitions from ScreenA to ScreenB, they can either press the back button to return back to ScreenA, or navigate to new routes using the same transition with the TabBar still not visible.
What I've tried:
navigationOptions.tabBarVisible: this property only seems to work when applied to TabA_StackNavigator itself, which means that all of the screens in its stack also conceal the TabBar. Adding it to the screens inside the StackNavigator has no effect.
Adding a new AllScreens_StackNavigator as a sibling of LoggedIn_TabNavigator and navigating to routes inside this navigator, I get the error: Expect nav state to have routes and index, {"routeName":"ScreenB", "params": {}, "key": "init-id-1516..."}. The navigation action I dispatched to try to do this:
{
"action": Object {
"params": Object {},
"routeName": "ScreenB",
"type": "Navigation/NAVIGATE",
},
"params": Object {},
"routeName": "AllScreens_StackNavigator",
"type": "Navigation/NAVIGATE",
}
Any help is greatly appreciated!
Edit: this answer is relevant to react-nagivation v1.~ (pre v2.0)
As suggested in the comments, see this issue:
https://github.com/react-navigation/react-navigation-tabs/issues/19
Apparently, the navigationOptions of an inner component affect the containing navigator's parent navigator as well.
Solution
That means this code should work for you:
class ScreenB extends React.Component {
static navigationOptions = {
header: () => null, //this will hide the Stack navigator's header (TabA_StackNavigator)
tabBarVisible: false //this will hide the TabBar navigator's header (LoggedIn_TabNavigator)
}
Explanation
First, you can set the navigation options per individual screen (component). You can see how in the code snippet above or here: React Navigation - Screen Navigation Options
Second, you tried:
Adding it to the screens inside the StackNavigator has no effect.
It didn't work because hiding the StackNavigator's header requires setting the header field to null.
From the React Navigation documentation:
React Element or a function that given HeaderProps returns a React
Element, to display as a header. Setting to null hides header
Third, using tabBarVisible is actually correct, but it affects only the TabNavigator. And to make it disappear only for one tab and not for all the tabs, you need to set it on the specific screen. ScreenB in your case.
Hope this helps!
The following is what ended up working for me, so I'm posting it the hopes that it helps others. I haven't had a chance to try #talzaj's implementation so I'll leave it up to others to upvote whatever works best for them. The following solution has been working well for me, including inside nested navigators.
I updated my navigation structure such that:
LoggedIn_StackNavigator still has LoggedIn_TabNavigator as one of its screens, and this LoggedIn_TabNavigator is the initial route of LoggedIn_StackNavigator as set using initialRouteName.
LoggedIn_StackNavigator also contains a route for every screen that will ever need to be shown full screen and conceal the tab bar. (If you are re-using screens, where some are shown with the tab bar visible and others where it is not, make sure to use unique keys for routes that re-use the same screen.
Navigation Structure
So, the navigation structure looks like:
RootTabNavigator
LoggedOut_StackNavigator
LoggedIn_StackNavigator
ScreenA // ( reuse screen component, different route key )
ScreenB // ( reuse screen component, different route key )
LoggedIn_TabNavigator <-- TabBar rendered by this Navigator
TabA_StackNavigator
ScreenA
ScreenB
LoggedIn_StackNavigator:
And LoggedIn_StackNavigator looks like:
import { StackNavigator } from 'react-navigation';
import LoggedIn_TabNavigator from './LoggedIn_TabNavigator';
import {
ScreenA,
ScreenB,
} from './LoggedIn_TabNavigator/TabA_StackNavigator/Screens';
const LoggedIn_StackNavigator = StackNavigator({
WithoutTabBar_ScreenA: {
screen: ScreenA
},
WithoutTabBar_ScreenB: {
screen: ScreenB
},
LoggedIn_TabNavigator: {
screen: LoggedIn_TabNavigator
}
}, {
initialRouteName: 'LoggedIn_TabNavigator'
});
export default LoggedIn_StackNavigator;
From there, I wrote a helper HOC for pushing full screen routes:
import React from 'react';
import { withNavigation } from 'react-navigation';
import { fullScreenRoutePrefix } from './somewhere';
export default function withNavigateFullScreen(Child) {
#withNavigation
class WithNavigateFullScreenHOC extends React.Component {
navigateToFullScreenRoute = (routeName, params) => {
this.props.navigation.navigate(
`${fullScreenRoutePrefix}${routeName}`, params
);
}
render() {
return (
<Child
{...this.props}
navigateFullScreen={this.navigateToFullScreenRoute}
/>
);
}
}
return WithNavigateFullScreenHOC;
}
And then I can navigate to full screen routes like so:
import React from 'react';
import { withNavigateFullScreen } from 'components/higher-order';
import { Text } from 'react-native';
#withNavigateFullScreen
export default class ScreenA extends React.Component {
goToScreenB = () => {
this.props.navigateFullScreen('ScreenB');
}
render() {
return <Text onPress={this.goToScreenB}>Go To Screen B</Text>;
}
}

React Navigation trigger when routeName changed

I'm using react navigation for navigate screen. I used nested navigation, TabNavigator and StackNavigator. How can I know in current screen has been swipe / change to other screen and change the state inside the screen without using Redux . I try to get this.props.navigation.state.routeName , it get the routeName of the screen, but how to trigger when routeName has change
const mainNav = TabNavigator({
Home: {
screen: HomeScreen,
},
Live: {
screen: LiveScreen,
},
Radio: {
screen: RadioScreen,
},
} );
export const mainStack = StackNavigator({
Home: { screen: mainNav},
Content: { screen: ContentScreen },
});
At present there is no way to track swipe gestures in react navigation. You can use hacks to achieve this, But mostly all of them requires hooking react navigation with redux.
Best way to track your screens will be to use react redux and hook the state with appState. This will give you most control over navigation and you can also use redux actions to control navigations along with other business stuff f in the app.
Simplest method to use react navigation with redux
You can refer
https://github.com/react-community/react-navigation/issues/1063

I18n working everywhere but not in contentComponent

I followed an example that uses I18n to implement multi-language. Everything was working fine until I tried to use the I18n on a sideMenu. I create a drawer with DrawerNavigator and set the SideMenu as contentComponent
const AppDrawer = DrawerNavigator(
{
Home: {
path: '/',
screen: WelcomeContainer,
},
Category: {
path: '/other',
screen: other,
},
},
{
contentComponent: SideMenu,
initialRouteName: 'Home',
contentOptions: {
activeTintColor: '#4edb6d',
},
}
);
In sideMenu I use I18n exactly as in the other components
<Text>
{ I18n.t('menu.title') }
</Text>
Even if I change the language the text is always in English which is the default language. The text language changed one time after multiple language change. Do you have an idea about the problem or how to solve it?
Edit:
I just noticed that the text language change only after I click on an item from the sideMenu. Any idea?

Resources