React Native-如何将TouchableWithoutFeedback与KeyboardAvoidingView结合使用?

时间:2018-10-11 18:37:48

标签: react-native

这是我的代码:

        <TouchableWithoutFeedback onPress={Keyboard.dismiss}>

                <KeyboardAvoidingView style={styles.container} behavior="padding" enabled>
                    <Text style={styles.title}>Login</Text>

                    <ActivityIndicator size="large" color="#0000ff" animating={this.state.isProcessing} />

                    <View style={styles.inputContainer}>
                        <TextInput
                            style={styles.textInput}
                            onChangeText={(email) => this.setState({ email })}
                            value={this.state.email}
                            keyboardType="email-address"
                            textContentType="emailAddress"
                            placeholder="Email"
                            editable={!this.state.isProcessing}
                        />
                    </View>

                    <View style={styles.inputContainer}>
                        <TextInput
                            style={styles.textInput}
                            onChangeText={(password) => this.setState({ password })}
                            value={this.state.password}
                            secureTextEntry={true}
                            placeholder="Password"
                            editable={!this.state.isProcessing}
                        />
                    </View>

                    <View style={styles.inputContainer}>
                        <TouchableOpacity
                            style={styles.button}
                            onPress={this.logIn.bind(this)}
                            disabled={this.state.isProcessing}
                        >
                            <Text style={{ color: '#fefffe' }}>Login</Text>
                        </TouchableOpacity>
                    </View>
                </KeyboardAvoidingView>

            </TouchableWithoutFeedback>

Keyboard.dismiss可以正常工作,但是KeyboardAvoidingView不能完全工作。

如果我触摸TextInput,KeyboardAvoidingView将不会根据键盘的位置调整位置。

为什么会这样?

请帮助我。非常感谢。

0 个答案:

没有答案