Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class LoginScreen extends Component {
- static PropTypes = {
- dispatch: PropTypes.func,
- fetching: PropTypes.bool,
- attemptLogin: PropTypes.func
- }
- isAttempting = false
- constructor (props) {
- super(props)
- this.state = {
- username: '',
- password: '',
- isLoaded: {false}
- }
- }
- componentDidMount(){
- const { username, password } = this.state
- this._getSavedUsername();
- // AsyncStorage
- // .getItem('@MobAppCorpStore:username')
- // .then((v_username) => { this.setState({ username: v_username, isLoaded: true }) });
- }
- async _getSavedUsername() {
- const { username } = this.state
- try {
- const value = await AsyncStorage.getItem('@MobAppCorpStore:username');
- if (value !== null){
- this.setState({ username: value});
- }
- } catch (error) {
- // Error retrieving data
- alert('Containers/LoginScreen - _getSavedUsername error')
- console.log('Containers/LoginScreen - get username error : ', error)
- }
- }
- ...
- render () {
- ...
- <Form style={styles.form_style}>
- <Item floatingLabel >
- <Label>{I18n.t('Global.username')}</Label>
- <Input
- style={styles.input_style}
- //autoFocus = {true}
- returnKeyType='next'
- value={username}
- onChangeText={username => this.setState({username})}
- autoCapitalize="none"
- blurOnSubmit={false}
- />
- </Item>
- <Item floatingLabel last >
- <Label>{I18n.t('Global.password')}</Label>
- <Input
- style={styles.input_style}
- returnKeyType='go'
- secureTextEntry={true}
- value={password}
- onChangeText={password => this.setState({password})}
- onSubmitEditing={this._handlePressLogin}
- autoCapitalize="none"/>
- </Item>
- </Form>
- ...
- }
- ...
- }
- Warning: Can't call setState (or forceUpdate) on an unmounted component.
- This is a no-op, but it indicates a memory leak in your application. To fix,
- cancel all subscriptions and asynchronous tasks in the componentWillUnmount
- method.
Add Comment
Please, Sign In to add comment