Skip to content

Instantly share code, notes, and snippets.

@AllGistsEqual
Created May 2, 2021 19:28
Show Gist options
  • Save AllGistsEqual/8522896f09e1397d19e71df07ec9269f to your computer and use it in GitHub Desktop.
Save AllGistsEqual/8522896f09e1397d19e71df07ec9269f to your computer and use it in GitHub Desktop.
// File: sc/screens/AppCheckScreen.tsx (partial)
import React, { useCallback } from 'react'
import { Text, View, StyleSheet } from 'react-native'
import { useFocusEffect } from '@react-navigation/native'
import { MainNavigationProp } from '../../routing/types'
import { MainRoutes } from '../../routing/routes'
import { useReduxSelector } from '../../redux'
import { selectLogin } from '../../redux/ducks/user'
type AppCheckScreenProps = {
navigation: MainNavigationProp<MainRoutes.AppCheck>
}
const AppCheckScreen = ({ navigation }: AppCheckScreenProps): React.ReactElement => {
const isLoggedIn = useReduxSelector(selectLogin)
const getRoute = useCallback(() => (
isLoggedIn
? MainRoutes.AppLoading
: MainRoutes.SignIn
), [isLoggedIn])
useFocusEffect(
useCallback(() => {
setTimeout(() => {
/*
* fake timer where you would instead
* load and check the app version
* and possible breaking changes before
* you send the user to the App Stack
*/
navigation.navigate(getRoute())
}, 1500)
}, [navigation, getRoute]),
)
return (
<View style={styles.page}>
<Text>loading App Data...</Text>
</View>
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment