Skip to content

Instantly share code, notes, and snippets.

@danielweinmann
Created February 4, 2016 06:09
Show Gist options
  • Save danielweinmann/4b44271c7d5631177f17 to your computer and use it in GitHub Desktop.
Save danielweinmann/4b44271c7d5631177f17 to your computer and use it in GitHub Desktop.
Now it works!
import React, { AppRegistry, Component, Navigator, View, Text, TouchableHighlight } from 'react-native'
import { Router, Route, Actions } from 'react-native-router-flux'
class First extends Component {
render() {
return (
<View style={{flex: 1, alignItems: 'center', justifyContent: 'center'}}>
<Text>This is shown when not signed in</Text>
<TouchableHighlight onPress={Actions.second}>
<Text>Next</Text>
</TouchableHighlight>
</View>
)
}
}
class Second extends Component {
render() {
return (
<View style={{flex: 1, alignItems: 'center', justifyContent: 'center'}}>
<Text>Now we can sign in</Text>
<TouchableHighlight onPress={this.props.onSignIn}>
<Text>Sign in</Text>
</TouchableHighlight>
</View>
)
}
}
class NotSignedIn extends Component {
componentWillUnmount() {
Actions.currentRouter = null
}
render() {
return (
<Router>
<Route {...this.props} name="first" component={First} initial={true} title="First" />
<Route {...this.props} name="second" component={Second} title="Second" />
</Router>
)
}
}
class SignedIn extends Component {
render() {
return (
<View style={{flex: 1, alignItems: 'center', justifyContent: 'center'}}>
<Text>This is shown when signed in</Text>
<TouchableHighlight onPress={this.props.onSignOut}>
<Text>Sign out</Text>
</TouchableHighlight>
</View>
)
}
}
class Root extends Component {
constructor(props, context) {
super(props, context)
this.state = {
signedIn: false,
}
}
handleSignIn() {
this.setState({signedIn: true})
}
handleSignOut() {
this.setState({signedIn: false})
}
render() {
const { signedIn } = this.state
if (signedIn)
return (<SignedIn onSignOut={this.handleSignOut.bind(this)} />)
return (<NotSignedIn onSignIn={this.handleSignIn.bind(this)} />)
}
}
AppRegistry.registerComponent('RoutesTest', () => Root)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment