2017-06-22 10 views
0

物理デバイスの最初の<TextInput/>ボックスにあるEmailをクリックすると、何が入力されているのかわかりません。 NextPasswordボックスに移動するときだけ、Emailボックスに入力されたものが表示されます。なぜこれはそうですか?ここで何が入力されているのかを<TextInput/>が表示しないのはなぜですか?

App.jsです:

import React, {Component} from 'react'; 
import {View, StyleSheet} from 'react-native'; 
import BackGround from './components/BackGround'; 

export default class App extends Component { 
    render() { 
     return(
      <View style={styles.back}> 
       <BackGround/> 
      </View> 
     ); 
    } 
} 

const styles = StyleSheet.create({ 
    back: { 
     flex: 1 
    } 
}); 

はここLogin.jsです:

import React, {Component} from 'react'; 
import {StyleSheet, TextInput, View, Text, TouchableOpacity, KeyboardAvoidingView} from 'react-native'; 

class Login extends Component { 
    constructor(props) { 
     super(props); 
     this.state = { 
      text: '' 
     }; 
    } 

    updateTextInput = text => this.setState({text}); 

    render() { 
     return(
      <KeyboardAvoidingView behavior={"padding"} style={styles.container}> 
       <View> 
        <TextInput 
         style={styles.input} 
         returnKeyType={"next"} 
         keyboardType={"email-address"} 
         autoCorrect={false} 
         onChangeText={this.updateTextInput} 
         value={this.state.text} 
        /> 

        <TextInput 
         style={styles.input} 
         returnKeyType={"go"} 
         secureTextEntry 
        /> 

        <TouchableOpacity> 
         <Text style={styles.loginAndCA}>Login</Text> 
        </TouchableOpacity> 

        <TouchableOpacity> 
         <Text style={styles.loginAndCA}>Create Account</Text> 
        </TouchableOpacity> 
       </View> 
      </KeyboardAvoidingView> 
     ); 
    } 
} 

const styles = StyleSheet.create({ 
    container: { 
     padding: 20 
    }, 

    input: { 
     backgroundColor: '#DAE5FF', 
     paddingBottom: 20, 
     padding: 20, 
     paddingHorizontal: 15, 
     marginBottom: 10, 
     borderRadius: 15, 
    }, 

    loginAndCA: { 
     fontSize: 40, 
     textAlign: 'center', 
     color: 'white', 
     fontFamily: 'Bodoni 72 Smallcaps', 
     paddingHorizontal: 10 
    }, 

    buttons: { 
     paddingBottom: 50 
    } 
}); 

export default Login; 

ここBackGround.jsです:

import React, {Component} from 'react'; 
import {StyleSheet, Image, View} from 'react-native'; 
import Login from './Login'; 

export default class BackGround extends Component { 
    render() { 
     return(
      <View style={styles.first}> 
       <Image style={styles.container} source={require('../pictures/smoke.jpg')}> 
        <View style={styles.second}> 
         <Login/> 
        </View> 
       </Image> 
      </View> 
     ); 
    } 
} 

const styles = StyleSheet.create({ 
    container: { 
     flex: 1, 
     justifyContent: 'center', 
     alignItems: 'center', 
     width: null, 
     height: null, 
     backgroundColor: 'rgba(0,0,0,0)', 
     resizeMode: 'cover' 
    }, 

    first: { 
     flex: 1 
    }, 

    second: { 
     paddingTop: 290 // Moves both <TextInput> boxes down. 
    } 
}); 
+0

なぜuが画像タグの子としてを置くのですか? – digit

答えて

0

あなたはそれを状態にし、そののTextInputの変更として接続値を与える必要があり、状態値を更新します:

export default class TextInputExample extends Component { 
    constructor(props) { 
    super(props); 
    this.state = { 
     text: '' 
    }; 
    } 
    updateTextInput = text => this.setState({ text }) 

    render() { 
    return (
     <View style={{ flex: 1}}> 
     <TextInput 
      style={{height: 40}} 
      placeholder="Type here!" 
      onChangeText={this.updateTextInput} 
      value={this.state.text} 
     /> 
     </View> 
    ); 
    } 
} 
+0

申し訳ありませんが、私はtextInputに値を追加するのを忘れていました。それでも問題が発生した場合は、それを試して、更新されたコードを投稿してください。 –

+0

オリジナルの投稿を更新しました。それでも動作しません。 –

関連する問題