react-native - 避免在底部的项目上使用键盘 - React Native
问题描述
我有这个 React Native proyect(带有 Expo),我在容器底部有 2 个按钮。当我打开键盘写东西时,这些东西会随键盘一起出现。¿我怎样才能避免这种情况?
这是容器代码->
render() {
return (
<View style={{flex: 1}}>
<Text style={styles.titulo}>Nueva Tarjeta</Text>
<View style={{ flex: 1}}>
<CreditCardInput
requiresName={true}
allowScroll={true}
labels={{
name: "Nombre del titular",
number: "Número de tarjeta",
expiry: "Venc",
cvc: "CVC",
}}
cardScale={1}
labelStyle={{ fontFamily: "OpenSansRegular" }}
placeholders={{
name: "Juan Perez",
number: "1234 1234 1234 1234",
expiry: "MM/AA",
cvc: "123",
}}
onChange={this._onChange}
/>
</View>
<View style={{ flexDirection: "row", alignSelf: "center",
justifyContent: 'flex-end', marginBottom: 10}}>
<TouchableOpacity style={styles.botonVolver}>
<Text style={styles.textoVolver}>Volver</Text>
</TouchableOpacity>
<TouchableOpacity style={styles.botonAceptar}>
<Text style={styles.textoAceptar}>Aceptar</Text>
</TouchableOpacity>
</View>
</View>
);
}
提前致谢!
解决方案
您可以尝试在 Android 上使用其prop 设置为的KeyboardAvoidingView :behavior
'height'
const screenHeight = Dimensions.get("window").height;
export default function App() {
return (
<KeyboardAvoidingView behavior="height" style={{ flex: 1 }}>
<View style={{ height: screenHeight - 75 }}>
<Text style={styles.titulo}>Nueva Tarjeta</Text>
<CreditCardInput
requiresName={true}
allowScroll={true}
labels={{
name: "Nombre del titular",
number: "Número de tarjeta",
expiry: "Venc",
cvc: "CVC",
}}
cardScale={1}
labelStyle={{ fontFamily: "OpenSansRegular" }}
placeholders={{
name: "Juan Perez",
number: "1234 1234 1234 1234",
expiry: "MM/AA",
cvc: "123",
}}
/>
</View>
<View
style={{
flexDirection: "row",
alignSelf: "center",
justifyContent: "flex-end",
marginBottom: 10,
}}
>
<TouchableOpacity style={styles.botonVolver}>
<Text style={styles.textoVolver}>Volver</Text>
</TouchableOpacity>
<TouchableOpacity style={styles.botonAceptar}>
<Text style={styles.textoAceptar}>Aceptar</Text>
</TouchableOpacity>
</View>
</KeyboardAvoidingView>
);
}
我还使用 更改了View
包含CreditCardInput
要基于屏幕高度的高度,因为在设置Dimensions
时过渡出现故障。flex
View
请务必Dimensions
从KeyboardAvoidingView
.'react-native'
推荐阅读
- sql - 使用 RegexLike 检查 Oracle SQL 中的特定日期格式
- python - 使用 apache 运行多个烧瓶应用程序
- python - 仅在使用 GUI 时适用于 Tensorflow 的“ImportError: libcublas.so.10.0”
- lotus-notes - 单击按钮将文档复制到另一个视图
- javascript - 有没有办法一次性取消链接 Google 幻灯片演示中的所有图表?
- google-app-maker - Google App maker 中的客户端计算模型不适用于 SuggestBox 小部件
- php - 如何在 Laravel 中获取关系的最新记录
- angular - 如何使用引导程序和角度 7 折叠表格
- java - 如何打破循环并将参数分配给数组对象
- python - socket.gaierror: [Errno 8] 使用套接字时提供的节点名和服务名