I am using the react-native-restart library for restarting the app so I can change the app language in the runtime. After I restart the app I want to change the first StackNavigator screen in the react-navigation library after restarting the app.
Navigator class is like this
import Screen1 from './Screen1'
import Screen2 from './Screen2'
import Screen3 from './Screen3'
import {StackNavigator} from 'react-navigation';
const Navigator = StackNavigator({
Screen1: {
screen: Screen1
},
Screen2: {
screen: Screen2
},
Screen3: {
screen: Screen3
}
});
export default Navigator;
in screen 2 I change the language and restart the app by the following function:
_onDirectionChange = () => {
I18nManager.forceRTL(true);
// Immediately reload the React Native Bundle
RNRestart.Restart(); }
However, fandro's answer is a good answer but there is a more straightforward answer in the following link:Change StackNavigator order #2683
There is an Option for the router called initialRouteName :
Update: Full Solution:
My Initial Screen
then in Language Screen
Maybe you can save a paramater in the mobile settings and make a condition based on it to load the correct Navigator on load :
The code will be something like :
Where
IsRestarting()
can be a function that check a value store in the mobile after you ask the application to restart. For example if the value is tru you return a custom navigator, if not you return the default.Hope it helps.