简体   繁体   English

KeyboardAvoidingView 在 iOS 上无法正常工作,即使我尝试了包括文档在内的所有解决方案,也会做出本机反应

[英]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.

相关问题 带有ScrollView的KeyboardAvoidingView在react-native或expo中不起作用 - KeyboardAvoidingView with ScrollView are Not working in react-native or expo 即使使用 KeyboardAvoidingView,React Native Sticky Footer Input 也被键盘覆盖 - React Native Sticky Footer Input got covered by Keyboard even using KeyboardAvoidingView 我第一次创建了spring maven项目css,js,图片没有加载我试过这里给出的所有解决方案仍然没有工作 - I have create spring maven project for the first time css,js,images are not loading i have tried all solutions given here still not working 每当键盘在本机反应中打开时,如何使用 KeyboardAvoidingView 删除图像? - How to use KeyboardAvoidingView to remove image whenever keypad opens in react native? 在 flex 中查看:1 未扩展到全高,KeyboardAvoidingView 无法正常工作 - View in flex: 1 not expanding to full height, KeyboardAvoidingView not working properly React Native Background Color 属性无法正常工作 - React Native Background Color property is not working properly 转换在 iOS safari 上不起作用 - 尝试了所有不同的后缀 - Transitions not working on iOS safari - tried all the different suffix React Native Expo 图像大小调整 - React Native Expo Image Resizing 显示:无故障。 尝试了建议的解决方案但没有成功 - Display:none not working. Tried suggested solutions to no success Expo / React Native:视频无法调整大小 - Expo / React Native: Video Failing to Resize
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM