[英]KeyboardAvoidingView not working properly on iOS react native, expo even if I tried all solutions including the documentation
I have a react native Expo project.我有一个反应原生的 Expo 项目。 Unfortunately I am blocked by an annoying problem.
不幸的是,我被一个烦人的问题挡住了。
This is how the view looks like:这是视图的样子:
When I click on the second input (Quantity) an empty blank space is added :(当我单击第二个输入(数量)时,会添加一个空白空间:(
Furthermore, when I click the second time on the input, the keyboard overlaps again此外,当我第二次单击输入时,键盘再次重叠
And this is the code:这是代码:
<KeyboardAvoidingView style={{ flex: 1 }} behavior={"height"}>
<View style={style.container}>
<Header
title={t("shoppingList.title")}
view={AppView.SHOPPING_CART}
onDelete={() => setConfirmMultipleDeleteModalVisible(true)}
onSettings={() => setSettingsModalVisible(true)}
/>
<SettingsModal
visible={settingsModalVisible}
onSave={onSaveSettings}
onClose={() => setSettingsModalVisible(false)}
/>
<View style={{ flex: 1 }}>
<FlatList
data={shoppingList}
keyExtractor={(item, index) => index + ""}
ListHeaderComponent={
<ShoppingListTableHeader
columns={columns}
selectedColumn={selectedColumn}
direction={direction}
sort={sortTable}
/>
}
stickyHeaderIndices={[0]}
renderItem={({ item, index }) => {
return (
<GestureHandlerRootView>
<ConfirmMultipleDeleteModal
visible={confirmMultipleDeleteModalVisible}
items={shoppingList.filter(
(item) => selectedItemIds.indexOf(item.id) !== -1
)}
onDelete={multipleDeleteAndCloseConfirmModal}
onClose={() => setConfirmMultipleDeleteModalVisible(false)}
/>
<Pressable
onPress={() => {
handleOnPress(item);
mark(index);
}}
onLongPress={() => {
selectItems(item);
}}
>
<Card
style={{
...generalStyles.card,
backgroundColor: index % 2 == 1 ? "#F0F0F0" : "white",
}}
>
<View style={generalStyles.displayOnRow}>
{selectedItemIds.length > 0 && (
<Checkbox
status={
selectedItemIds.indexOf(item.id!) !== -1
? "checked"
: "unchecked"
}
onPress={() => handleOnPress(item)}
color={"#585858"}
uncheckedColor={"black"}
/>
)}
<ShoppingItem
item={item}
index={index}
marked={shoppingList[index].bought}
/>
</View>
{selectedItemIds.indexOf(item.id!) !== -1 && (
<View style={generalStyles.overlay} />
)}
</Card>
</Pressable>
</GestureHandlerRootView>
);
}}
/>
</View>
{addModalVisible ? (
<AddShoppingListItem
onSave={onSaveItem}
onClose={() => setAddModalVisible(false)}
/>
) : (
<MaterialCommunityIcons
name={"cart-plus"}
size={40}
onPress={() => setAddModalVisible(true)}
style={style.addIcon}
/>
)}
<StatusBar style="auto" />
</View>
</KeyboardAvoidingView>
export const style = StyleSheet.create({ container: { flex: 1, paddingTop: 40, width: "100%", } }); export const style = StyleSheet.create({ container: { flex: 1, paddingTop: 40, width: "100%", } });
I also tried to put the component inside我也试着把组件放在里面
<KeyboardAvoidingView
behavior={Platform.OS === 'ios' ? 'padding' : 'height'}
style={styles.container}>
<TouchableWithoutFeedback onPress={Keyboard.dismiss}>
but it didn't work :(但它没有用:(
I am wondering ifit is related to the fact that I am using我想知道它是否与我正在使用的事实有关
createMaterialBottomTabNavigator();
Any suggestions, pleaseee?有什么建议吗?
The docs suggest using behavior='padding'
on iOS.文档建议在 iOS 上使用
behavior='padding'
。 https://docs.expo.dev/versions/latest/react-native/keyboardavoidingview/ https://docs.expo.dev/versions/latest/react-native/keyboardavoidingview/
If that doesn't work for you, try experimenting with a negative keyboardVerticalOffset
on the KeyboardAvoidingView.如果这对您不起作用,请尝试在 KeyboardAvoidingView 上使用负的
keyboardVerticalOffset
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.