首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >关于KeyboardAvoidingView的iOS问题

关于KeyboardAvoidingView的iOS问题
EN

Stack Overflow用户
提问于 2022-09-16 20:35:00
回答 1查看 30关注 0票数 0

我在KeyboardAvoidingView on iOS上遇到一些问题。问题是我不能真正地重现错误。我在一个相对正常的设置中使用KeyboardAvoidingView,以确保输入不隐藏在键盘后面,但在某些特定设备上,它总是发出窃听器,基本上将视图中包含的所有内容从屏幕上推开。示例:

代码语言:javascript
运行
复制
        <Header
          marginTop={screenWidth / 10}
          paddingHorizontal={10}
          onPress={false}
          source={require("../../assets/images/arrowback.png")}
          text={ I18n.t("VERIFY_TITLE")}
        />
        {loading ? (
          <AppIndicator height={screenHeight} position={"absolute"} />
        ) : null}
        
        <View
        style={[sameStyle.flexOne, { paddingHorizontal: 20 }]}
        >
        <KeyboardAvoidingView>
          <ScrollView
            pointerEvents={loading ? "none" : "auto"}
            showsVerticalScrollIndicator={false}
            style={sameStyle.flexOne}
          >
            <Button
                opacity={opacity}
                disabled={false}
                onPress={this.sendVerifyEmail}
                shapeViewWidth={"48%"}
                shapeView2Width={"48%"}
                marginBottom={35}
                marginTop={50}
                name={I18n.t("SEND_VERIFY_MAIL_BUTTON")}
            />
            {/* <DescriptionText
              marginTop={15}
              desc={I18n.t("VERIFY_MAIL_HINT")}
            /> */}
            <Title
              marginTop={40}
              title={I18n.t("VERIFY_MAIL_TITLE")}
              fontFamily={Font.REGULAR}
            />
            <DescriptionText
              marginTop={15}
              desc={I18n.t("VERIFY_MAIL_DESC")}
            />
            <InputWithIcon
              keyboardType={"numeric"}
              returnKeyType={"send"}
              marginTop={20}
              maxLength={60}
              label={'Code'}
              value={this.state.code.toString()}
              onChangeText={(text) => this.setState({ code: text })}
              onSubmitEditing={this.sendVerifyCode}
            />
            <Button
              opacity={opacity}
              disabled={this.state.code == 0 || this.state.code == null}
              onPress={this.sendVerifyCode}
              shapeViewWidth={"48%"}
              shapeView2Width={"48%"}
              marginBottom={50}
              marginTop={50}
              name={I18n.t("COMMON_SEND_BUTTON")}
            />
          </ScrollView>
        </KeyboardAvoidingView>
        </View>```

On most devices the component renders completely as expected, but on some particular phones it looks like this:
[Excuse the text, but basically the screen is empty apart from the Header][1]


  [1]: https://i.stack.imgur.com/nmzub.png

Because of legacy code we are sadly still using React-Native 0.59

This particular user is using an iPhone 12 on iOS 16, but we have also had Users with this problem  using iPhone Xs and also on other versions such as 15.3.6 etc. Like I said, on some devices with exactly the same specs it is working fine, on others it's not. Any help is appreciated.
EN

回答 1

Stack Overflow用户

发布于 2022-09-16 22:16:15

由于无法准确描述,请尝试以下设置:

代码语言:javascript
运行
复制
import { useHeaderHeight } from "@react-navigation/stack";

在您的组件中

代码语言:javascript
运行
复制
const headerHeight = useHeaderHeight();
<KeyboardAvoidingView
            keyboardVerticalOffset={headerHeight}
            behavior={Platform.OS === "ios" ? "padding" : "height"}
>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73750082

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档