Last active
April 1, 2018 22:44
-
-
Save horacioh/87f05a25118bda6cb08f753c891d7ecc to your computer and use it in GitHub Desktop.
RN Scaffold : MyApp/src/app/App.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// MyApp/src/app/App.js | |
// @flow | |
import * as React from 'react' | |
import { Font } from 'expo' | |
import { isSignedIn } from '../auth/utils/auth' | |
import { createPrivateRootNavigator, createPublicRootNavigator } from './navigators' | |
type State = { | |
fontLoaded: boolean, | |
checkedSignIn: boolean, | |
signedIn: boolean | |
} | |
type Props = { | |
} | |
export default class App extends React.Component<Props, State> { | |
state = { | |
fontLoaded: false, | |
checkedSignIn: false, | |
signedIn: false | |
} | |
async componentDidMount() { | |
await Font.loadAsync({ | |
'roboto-slab': require('./assets/fonts/RobotoSlab-Light.ttf') | |
}).then(() => { | |
this.setState({ fontLoaded: true }) | |
}) | |
await isSignedIn() | |
.then((res: boolean) => this.setState({ signedIn: res, checkedSignIn: true })) | |
.catch(err => alert('An error occurred')) | |
} | |
render() { | |
const { checkedSignIn, signedIn, fontLoaded } = this.state | |
// If we haven't checked AsyncStorage yet, don't render anything (better ways to do this) | |
if (!checkedSignIn && !fontLoaded) { | |
return null; | |
} | |
const Layout = signedIn ? createPrivateRootNavigator() : createPublicRootNavigator(); | |
return <Layout /> | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment