react-native - react-native 中的 KeyboardAvoidingView keyboardVerticalOffset 错误
问题描述
我曾经在react-nativekeyboardVerticalOffset
中使用静态按钮。KeyboardAvoidingView
但
红色箭头显示意外行为。如您所见,正在添加额外的空间,但它是一个白色区域。
这是我的代码。
const Code = () => {
const emailInput = useRef(null);
const birthInput = useRef(null)
const scrollViewRef = useRef(null);
const [email, setEmail] = useState<string>('');
const scrollToEmail = () => {
// I want to scroll the y position of the scroll to the center where the TextInput's cursor is focused.
};
return (
<SafeAreaView style={{ flex: 1}}>
<KeyboardAvoidingView style={{flex: 1}} behavior={'height'} keyboardVerticalOffset={73 + 50}>
<ScrollView keyboardShouldPersistTaps="always" ref={scrollViewRef}>
<InputBox> <== height: 50
<TextInput
ref={emailInput}
onFocus = {() => scrollToEmail()}
/>
</InputBox>
<InputBox> <== height: 50
<TextInput
ref={birthInput}
onFocus = {() => scrollToBirth()}
/>
</InputBox>
</ScrollView>
</KeyboardAvoidingView>
<View style={{position: 'absolute', bottom: 0, width: '100%'}}>
<BottomBtn check={check} onPress={submit} text={`ok`} /> <== height: 73
</View>
</SafeAreaView>
);
};
export default Code;
并且<KeyboardAvoidingView behavior={'padding'} keyboardVerticalOffset={73}/>
不工作。键盘立即关闭。
我希望 Sticky 按钮和 TextInput 的空间完美契合。我应该怎么办?
解决方案
我KeyboardAvoidingView
之前也在滚动视图上使用过高度,但得到了相同的结果。我的建议是尝试不同behaviour
,但我认为最好使用react-native-keyboard-aware-scroll-view。它具有更多的属性并且更易于使用。
推荐阅读
- c# - 单击上传按钮时我无法显示文件路径
- android - 如何防止 Flutter 构建输出带回旧的调试输出?
- jpa - JPA Spring Data原生查询和子实体初始化
- conditional-statements - getter 方法中的条件语句
- javascript - 模型方法未识别
- kotlin - Kotlin 中的私有构造函数是做什么用的?
- visual-studio-code - vscode vim扩展重新映射了UP和DOWN键在按住时不起作用
- javascript - JavaScript 使用复杂的 json 文件
- android - DataBinding onClickListener 使用“::”给出错误
- node.js - Firebase 函数预部署错误:命令以非零退出代码终止