Skip to content

Instantly share code, notes, and snippets.

@csorlandi csorlandi/index.js
Created Mar 26, 2019

Embed
What would you like to do?
import React, { Component, Fragment } from 'react';
import PropTypes from 'prop-types';
import {
View, Text, Image, TouchableOpacity, AsyncStorage,
} from 'react-native';
import styles from './styles';
export default class Main extends Component {
static propTypes = {
navigation: PropTypes.shape({
navigate: PropTypes.func,
}).isRequired,
};
static navigationOptions = {
header: null,
};
state = {
loading: true,
data: null,
};
componentDidMount() {
const { navigation } = this.props;
this.navListener = navigation.addListener('didFocus', this.loadData);
}
componentWillUnmount() {
this.navListener.remove();
}
loadData = async () => {
this.setState({ loading: true });
const data = JSON.parse(await AsyncStorage.getItem('@TwoFactor:data'));
this.setState({ loading: false, data });
};
renderCode = () => <Text>Seu código</Text>;
renderAddAccount = () => {
const { navigation } = this.props;
return (
<Fragment>
<Text style={styles.welcome}>Adicionar uma conta</Text>
<TouchableOpacity
style={styles.buttonContainer}
onPress={() => navigation.navigate('BarCodeScanner')}
>
<Text style={styles.buttonText}> Ler um código de barras</Text>
</TouchableOpacity>
</Fragment>
);
};
render() {
const { data } = this.state;
return (
<View style={styles.container}>
<Image
source={require('~/images/rocketseat_logo.png')}
style={styles.logo}
resizeMode="contain"
/>
{data ? this.renderCode() : this.renderAddAccount()}
</View>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.