我正在做一个登录屏幕使用react原生和我试图使它完全像reddit登录屏幕,但当我使用KeyboardAwareScrollView和KeyboardAvoidingView键盘不出现。它不断打开和关闭。Login.js:
Expo SDK:46平台:机器人
<View style={{ flex: 1 }}>
<KeyboardAvoidingView behavior={Platform.OS === "ios" ? "padding" : "height"}>
<KeyboardAwareScrollView style={{ height: 500 }}>
<View
style={{
paddingRight: 10,
flex: 0.05,
flexDirection: "row",
alignItems: "center",
justifyContent: "space-between",
}}
>
<Appbar.BackAction onPress={() => navigation.navigate("Home")} />
<Text style={{ fontSize: 24, fontWeight: "bold", color: "#ff4757" }}>
WA
</Text>
<TouchableOpacity onPress={() => navigation.navigate("Regist")}>
<Text style={{ color: "#ff4757" }}>Sign up</Text>
</TouchableOpacity>
</View>
<View style={styles.centeredView}>
<View style={{ flex: 0.9 }}>
<Text style={styles.loginTitleText}>Log in to WearAble</Text>
<View style={styles.continueWithGA}>
<TouchableOpacity
style={styles.buttonlogoStyle}
activeOpacity={0.5}
>
<Image source={googleimg} style={styles.buttonImageIconStyle} />
<Text style={styles.buttonTextStyle}>Continue with Google</Text>
</TouchableOpacity>
<TouchableOpacity
style={styles.buttonlogoStyle}
activeOpacity={0.5}
>
<Image source={appleimg} style={styles.buttonImageIconStyle} />
<Text style={styles.buttonTextStyle}>Continue with Apple</Text>
</TouchableOpacity>
</View>
<View
style={{
flexDirection: "row",
justifyContent: "center",
width: "100%",
alignItems: "center",
marginTop: 20,
marginBottom: 25,
}}
>
<View style={styles.line} />
<Text
style={{
marginLeft: 13,
marginRight: 13,
fontSize: 15,
fontWeight: "bold",
}}
>
OR
</Text>
<View style={styles.line} />
</View>
<View style={{ marginBottom: 10 }}>
<TextInput
mode="outlined"
label="Username"
outlineColor="gray"
activeOutlineColor="#ff4757"
style={{ backgroundColor: "none" }}
/>
</View>
<View style={{ marginBottom: 10 }}>
<TextInput
mode="outlined"
label="Password"
secureTextEntry={!showPass}
right={
<TextInput.Icon
icon={!showPass ? "eye-off" : "eye"}
color={!showPass ? "black" : "lightblue"}
onPress={eyeShow}
/>
}
outlineColor="gray"
activeOutlineColor="#ff4757"
style={{ backgroundColor: "none" }}
/>
</View>
<TouchableOpacity>
<Text>Forgot Password?</Text>
</TouchableOpacity>
<HelperText type="error" visible={errorCheck}>
Your Username or Password was incorrect!
</HelperText>
</View>
<TouchableOpacity style={{ flex: 0.1 }} onPress={() => {}}>
<Text style={{ fontSize: 17 }}>
By continuing, you agree to out{" "}
<Text style={{ color: "#ff4757", textDecorationLine: "underline" }}>
User Agreement
</Text>{" "}
and{" "}
<Text style={{ color: "#ff4757", textDecorationLine: "underline" }}>
Privacy Policy
</Text>
.
</Text>
</TouchableOpacity>
</View>
<TouchableWithoutFeedback onPress={Keyboard.dismiss}>
<View style={{ flex: 0.07 }}>
<TouchableOpacity
style={styles.loginButton}
onPress={() => LoginUser(email, pass)}
>
<Text style={styles.loginButtonText}>Continue</Text>
</TouchableOpacity>
</View>
</TouchableWithoutFeedback>
</KeyboardAwareScrollView>
</KeyboardAvoidingView>
</View>;
我想页面的行为像reddit登录屏幕
1条答案
按热度按时间vc6uscn91#
我解决了我的问题。通过将keyboardAvoidingView组件移动到只包含Continue按钮和KeyboardAwareScrollView的页面内容中,代码现在是这样的: