Guest User

Untitled

a guest
May 8th, 2018
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 KB | None | 0 0
  1. class LoginScreen extends Component {
  2.  
  3. static PropTypes = {
  4. dispatch: PropTypes.func,
  5. fetching: PropTypes.bool,
  6. attemptLogin: PropTypes.func
  7. }
  8.  
  9. isAttempting = false
  10.  
  11. constructor (props) {
  12. super(props)
  13.  
  14. this.state = {
  15. username: '',
  16. password: '',
  17. isLoaded: {false}
  18. }
  19.  
  20. }
  21.  
  22. componentDidMount(){
  23. const { username, password } = this.state
  24. this._getSavedUsername();
  25.  
  26. // AsyncStorage
  27. // .getItem('@MobAppCorpStore:username')
  28. // .then((v_username) => { this.setState({ username: v_username, isLoaded: true }) });
  29.  
  30. }
  31.  
  32. async _getSavedUsername() {
  33. const { username } = this.state
  34.  
  35. try {
  36. const value = await AsyncStorage.getItem('@MobAppCorpStore:username');
  37. if (value !== null){
  38. this.setState({ username: value});
  39. }
  40. } catch (error) {
  41. // Error retrieving data
  42. alert('Containers/LoginScreen - _getSavedUsername error')
  43. console.log('Containers/LoginScreen - get username error : ', error)
  44. }
  45. }
  46.  
  47. ...
  48.  
  49. render () {
  50. ...
  51.  
  52. <Form style={styles.form_style}>
  53. <Item floatingLabel >
  54. <Label>{I18n.t('Global.username')}</Label>
  55. <Input
  56. style={styles.input_style}
  57. //autoFocus = {true}
  58. returnKeyType='next'
  59. value={username}
  60. onChangeText={username => this.setState({username})}
  61. autoCapitalize="none"
  62. blurOnSubmit={false}
  63. />
  64. </Item>
  65. <Item floatingLabel last >
  66. <Label>{I18n.t('Global.password')}</Label>
  67. <Input
  68. style={styles.input_style}
  69. returnKeyType='go'
  70. secureTextEntry={true}
  71. value={password}
  72. onChangeText={password => this.setState({password})}
  73. onSubmitEditing={this._handlePressLogin}
  74. autoCapitalize="none"/>
  75. </Item>
  76. </Form>
  77.  
  78. ...
  79. }
  80.  
  81. ...
  82.  
  83. }
  84.  
  85. Warning: Can't call setState (or forceUpdate) on an unmounted component.
  86. This is a no-op, but it indicates a memory leak in your application. To fix,
  87. cancel all subscriptions and asynchronous tasks in the componentWillUnmount
  88. method.
Add Comment
Please, Sign In to add comment