mirror of
https://github.com/zhigang1992/react-navigation.git
synced 2026-01-27 09:08:37 +08:00
43 lines
995 B
JavaScript
43 lines
995 B
JavaScript
import React from 'react';
|
|
import PropTypes from 'prop-types';
|
|
import { connect } from 'react-redux';
|
|
import { Button, StyleSheet, Text, View } from 'react-native';
|
|
import { NavigationActions } from 'react-navigation';
|
|
|
|
const styles = StyleSheet.create({
|
|
welcome: {
|
|
fontSize: 20,
|
|
textAlign: 'center',
|
|
margin: 10,
|
|
},
|
|
});
|
|
|
|
const LoginStatusMessage = ({ isLoggedIn, dispatch }) => {
|
|
if (!isLoggedIn) {
|
|
return <Text>Please log in</Text>;
|
|
}
|
|
return (
|
|
<View>
|
|
<Text style={styles.welcome}>
|
|
{'You are "logged in" right now'}
|
|
</Text>
|
|
<Button
|
|
onPress={() =>
|
|
dispatch(NavigationActions.navigate({ routeName: 'Profile' }))}
|
|
title="Profile"
|
|
/>
|
|
</View>
|
|
);
|
|
};
|
|
|
|
LoginStatusMessage.propTypes = {
|
|
isLoggedIn: PropTypes.bool.isRequired,
|
|
dispatch: PropTypes.func.isRequired,
|
|
};
|
|
|
|
const mapStateToProps = state => ({
|
|
isLoggedIn: state.auth.isLoggedIn,
|
|
});
|
|
|
|
export default connect(mapStateToProps)(LoginStatusMessage);
|