Last active
December 27, 2017 16:58
-
-
Save fatfatson/fac81bb81393fd3a41764def6e6eb381 to your computer and use it in GitHub Desktop.
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
// @flow | |
import React, { Component, PureComponent } from 'react'; | |
import { | |
Platform, | |
StyleSheet, | |
Text, | |
View, | |
Image, | |
TextInput, | |
TouchableOpacity | |
} from 'react-native'; | |
import { BackHandler } from 'react-native'; | |
import { | |
Router, | |
Scene, | |
Actions, | |
ActionConst, | |
Tabs, | |
Stack | |
} from 'react-native-router-flux'; | |
import { Provider, connect } from 'react-redux'; | |
import { store, storage } from '../store'; | |
import About from './About'; | |
import { Login } from './Login'; | |
import { NetState } from './NetState'; | |
import { Home } from './Home'; | |
const styles = StyleSheet.create({ | |
}); | |
const mapStateToProps = (state, ownProps) => { | |
const { loggingIn, loggedIn, refount } = state.auth; | |
//with this, problem comes | |
return { loggingIn }; | |
}; | |
class App extends PureComponent<{}> { | |
constructor(props: Props) { | |
super(props); | |
this.state = {}; | |
console.log('App ctor'); | |
} | |
componentWillReceiveProps(nextProps, nextState) { | |
console.log('app componentWillReceiveProps', nextProps); | |
if (this.props.loggedIn && !nextProps.loggedIn) { | |
console.log('logout checked!'); | |
Actions.reset('Login'); | |
} | |
} | |
componentDidMount() { | |
//this.checkIsLogin(); | |
} | |
checkIsLogin() { | |
storage | |
.load({ | |
key: 'loginState' | |
}) | |
.then(ret => { | |
console.log('loginState:', ret); | |
//Actions.MainFrame(); | |
}) | |
.catch(err => { | |
console.warn(err.message); | |
Actions.Login(); | |
}); | |
} | |
render() { | |
console.log('render app'); | |
return ( | |
<View style={{ backgroundColor: '#f5f5f5', flex: 1 }}> | |
<NetState /> | |
<Router | |
backAndroidHandler={() => { | |
console.log('back...'); | |
console.log(Actions.state); | |
Actions.pop(); | |
return true; | |
}} | |
> | |
<Scene key="root" hideNavBar> | |
<Scene key="Login" component={Login} title="Login" /> | |
<Scene key="Home" component={Home} title="Home" /> | |
<Scene | |
key="About" | |
component={About} | |
title="About" | |
hideNavBar={false} | |
/> | |
</Scene> | |
</Router> | |
</View> | |
); | |
} | |
} | |
const connectedApp = connect(mapStateToProps, mapDispatchToProps)(App); | |
export { connectedApp as App }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment