Open vinayNdz opened 4 years ago
you are going to handle all of this in one place, consider as your app entry point each time user enters the app you check something and route to different parts of your app.
in this case consider the Launch Screen:
const rootNavigation = createSwitchNavigator( { Launch, AppSwiper, Auth: AuthStackNavigation, Main: MainStackNavigator, }, { initialRouteName: "Launch", }, )
and the Launch screen that opens each time is:
`export default function Launch(props) { React.useEffect(() => { checkStatusAndNavigate() }, [])
async function checkStatusAndNavigate() {
const isVisitedBefore = await getDataFromLocalStorage("isVisitedBefore")
if (isVisitedBefore) {
const currentUser = await getDataFromLocalStorage("isLoggedIn")
if (currentUser) {
props.navigation.navigate("Main")
} else {
props.navigation.navigate("Auth")
}
}
} else {
// first time open app
setDataToLocalStorage(true, "@isVisitedBefore")
props.navigation.navigate("AppSwiper")
}
SplashScreen.hide()
}
return
System: OS: macOS Mojave 10.14.6 CPU: (4) x64 Intel(R) Core(TM) i5-4278U CPU @ 2.60GHz Memory: 69.99 MB / 8.00 GB Shell: 3.2.57 - /bin/bash Binaries: Node: 10.15.3 - /usr/local/bin/node npm: 6.11.3 - /usr/local/bin/npm SDKs: iOS SDK: Platforms: iOS 13.2, DriverKit 19.0, macOS 10.15, tvOS 13.2, watchOS 6.1 IDEs: Android Studio: 3.6 AI-192.7142.36.36.6241897 Xcode: 11.3.1/11C504 - /usr/bin/xcodebuild npmPackages: react: 16.9.0 => 16.9.0 react-native: 0.61.5 => 0.61.5 npmGlobalPackages: react-native-cli: 2.0.1
"react-native-splash-screen": "^3.2.0",
What platform does your issue occur on? (Android/iOS/Both) Both
I want to create a splashscreen without the whitescreen issue using the react-native splash screen and after that I want to check the navigation. Suppose I got 3 screen Splash, Login and Home. If the user is logged in I want to navigate to the Home screen from the Splash screen otherwise I want to navigate it to the Login page from the Splash screen. How do I achieve this using react-native-splash-screen and react-navigation.