Last active
October 1, 2018 15:02
-
-
Save sejas/702ed8988b4b2761bfa2bd3d0a9386a3 to your computer and use it in GitHub Desktop.
Loading React Native MST
This file contains 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
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} /> | |
} | |
} |
This file contains 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
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