Skip to content

Instantly share code, notes, and snippets.

@anghelalexandra
Last active May 15, 2018 20:32
Show Gist options
  • Save anghelalexandra/a567c659b2b6296fecfdbd8d8f3325dc to your computer and use it in GitHub Desktop.
Save anghelalexandra/a567c659b2b6296fecfdbd8d8f3325dc to your computer and use it in GitHub Desktop.
iOS and Android apps with React Native - Switching between screens with React Navigation
import React from 'react';
import PropTypes from 'prop-types';
class LoginScreen extends React.Component {
// ...
componentWillReceiveProps(newProps) {
if (newProps.authenticated === true) {
this.handleSuccessfulLogin();
}
}
handleSuccessfulLogin() {
const { navigate } = this.props.navigation;
navigate('Home');
}
render() {
// ..
}
}
LoginScreen.propTypes = {
authenticated: PropTypes.bool.isRequired,
navigation: PropTypes.shape({
navigate: PropTypes.func.isRequired,
}).isRequired,
};
export default LoginScreen;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment