我在KeyboardAvoidingView on iOS上遇到一些问题。问题是我不能真正地重现错误。我在一个相对正常的设置中使用KeyboardAvoidingView,以确保输入不隐藏在键盘后面,但在某些特定设备上,它总是发出窃听器,基本上将视图中包含的所有内容从屏幕上推开。示例:
<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.
发布于 2022-09-16 22:16:15
由于无法准确描述,请尝试以下设置:
import { useHeaderHeight } from "@react-navigation/stack";
在您的组件中
const headerHeight = useHeaderHeight();
<KeyboardAvoidingView
keyboardVerticalOffset={headerHeight}
behavior={Platform.OS === "ios" ? "padding" : "height"}
>
https://stackoverflow.com/questions/73750082
复制相似问题