Advertisement
Guest User

rn_tes

a guest
Apr 9th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * Sample React Native App
  3.  * https://github.com/facebook/react-native
  4.  * @flow
  5.  */
  6.  
  7. import React, {Component} from 'react';
  8. import {
  9.   AppRegistry,
  10.   StyleSheet,
  11.   Text,
  12.   View,
  13.   Alert,
  14.   TextInput
  15. } from 'react-native';
  16. import {List, ListItem, Button} from 'react-native-elements'
  17.  
  18. export default class element_login extends Component {
  19.   constructor(props) {
  20.     super(props);
  21.     this.state = {
  22.       userName: '',
  23.       userPassword: '',
  24.       userNameAutoFocus:true,
  25.       userNameFocus: true,
  26.       userPasswordFocus: false
  27.     }
  28.   }
  29.   componentDidMount(){
  30.     console.log(this.state);
  31.   }
  32.   loginButtonClicked() {
  33.     //prevent annoying focus
  34.     this.setState({userNameFocus: false, userPasswordFocus: false})
  35.   }
  36.   registerButtonClicked() {
  37.     Alert.alert("aa", "this will be replace by navigator")
  38.   }
  39.   resetButtonClicked() {
  40.     this.setState({userName: '', userNameFocus: true, userPassword: '', userPasswordFocus: false});
  41.   }
  42.   nextFormComponent(event) {
  43.     switch (event) {
  44.       case "password":
  45.         // since ref cannot work so we bypass using props
  46.         /** this.refs.passwordField.focus(); **/
  47.         this.setState({userNameFocus: false, userPasswordFocus: true});
  48.         break;
  49.       case "submit":
  50.         // do nothing ..
  51.         break;
  52.       default:
  53.        // Alert.alert("system", "Unknown Request")
  54.     }
  55.   }
  56.   /**
  57.    * Bind Data . the reason using standard   textInputOnChangeText={(text) => this.setState({text})} not working
  58.    * @param {string} id
  59.    * @param {string} value
  60.    */
  61.   bindData(id, value) {
  62.     // seem pretty odd here cannot work this.setState({idx: value});
  63.     switch (id) {
  64.       case "userName":
  65.         this.setState({"userName": value});
  66.         break;
  67.       case "userPassword":
  68.         this.setState({"userPassword": value});
  69.     }
  70.   }
  71.   render() {
  72.     return (
  73.       <View style={styles.container}>
  74.         <Text>This sample user login
  75.         </Text>
  76.         <Text></Text>
  77.         <List>
  78.           <ListItem
  79.             title="Username"
  80.             textInput={true}
  81.             textInputValue={this.state.userName}
  82.             textInputSecureTextEntry={false}
  83.             textInputOnChangeText={this
  84.             .bindData
  85.             .bind(this, 'userName')}
  86.             textInputAutoFocus={this.state.userNameAutoFocus}
  87.             textInputFocus={this.state.userNameFocus}
  88.             textInputKeyboardType="default"
  89.             textInputPlaceHolder="Type your Username Here"
  90.             textInputContainerStyle={styles.inputFormStyle}
  91.             textInputOnSubmitEditing={this
  92.             .nextFormComponent
  93.             .bind(this, 'userPassword')}
  94.             textInputReturnKeyType="next"></ListItem>
  95.           <ListItem
  96.             title="Password"
  97.             textInputSecureTextEntry={true}
  98.             textInput={true}
  99.             textInputValue={this.state.userPassword}
  100.             textInputOnChangeText={this
  101.             .bindData
  102.             .bind(this, 'userPassword')}
  103.             textInputFocus={this.state.userPasswordFocus}
  104.             textInputKeyboardType="default"
  105.             textInputPlaceHolder="Type Your Password Here"
  106.             textInputContainerStyle={styles.inputFormStyle}
  107.             textInputOnSubmitEditing={this
  108.             .nextFormComponent
  109.             .bind(this, 'submit')}
  110.             textInputReturnKeyType="done">></ListItem>
  111.         </List>
  112.         <Button
  113.           title="login"
  114.           onPress={this
  115.           .loginButtonClicked
  116.           .bind(this)}></Button>
  117.         <Text></Text>
  118.         <Button
  119.           title="Register"
  120.           onPress={this
  121.           .registerButtonClicked
  122.           .bind(this)}></Button>
  123.         <Text></Text>
  124.         <Button
  125.           title="Reset"
  126.           onPress={this
  127.           .resetButtonClicked
  128.           .bind(this)}></Button>
  129.       </View>
  130.     );
  131.   }
  132. }
  133.  
  134. const styles = StyleSheet.create({
  135.   inputFormStyle: {
  136.     flex: 1
  137.   }
  138. });
  139.  
  140. AppRegistry.registerComponent('element_login', () => element_login);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement