Skip to content

Instantly share code, notes, and snippets.

@sejas
Last active October 1, 2018 15:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sejas/702ed8988b4b2761bfa2bd3d0a9386a3 to your computer and use it in GitHub Desktop.
Save sejas/702ed8988b4b2761bfa2bd3d0a9386a3 to your computer and use it in GitHub Desktop.
Loading React Native MST
import * as React from "react"
import { observer } from "mobx-react"
import {Register} from "../register"
import {Home} from "../home"
import { MSTUser } from "../../app/models/user"
import { NavigationScreenProps } from "react-navigation"
export interface PreLoadingScreenProps extends NavigationScreenProps<{}> {}
// @inject("mobxstuff")
@observer
export class PreLoading extends React.Component<PreLoadingScreenProps, {}> {
componentWillMount(){
MSTUser.onAuthChanges()
}
render() {
return (MSTUser.isLogged)
? <Home navigation={this.props.navigation} {...this.props} />
: <Register navigation={this.props.navigation} {...this.props} />
}
}
import { types, flow } from "mobx-state-tree"
import { firebaseAuth } from "../../services/api/firebase"
export const User = types
.model({
uuid: "",
firebaseId: "",
name: "",
surname: "",
selfImage: "",
passport: "",
scannedPassport: "",
token: "",
pushToken: "",
isLogged: false
})
.actions(self => ({
onAuthChanges: () => firebaseAuth.onAuthStateChanged(self.onAuthChangesCallback),
onAuthChangesCallback(user){
console.tron.log("onAuthChanges logged:", user)
if (user) {
self.isLogged = true
}
},
}))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment