react-native - KeyboardAwareScrollView 有额外的底部填充?
问题描述
我遇到这个问题已经有一段时间了KeyboardAwareScrollView
,它的底部有一些额外的填充(黄色)。在这里,我希望我的表单始终位于屏幕底部,这似乎这个填充不允许这样做。
export const LoginView: React.FC = () => {
return (
<View style={styles.container}>
<KeyboardAwareScrollView
style={styles.scrollContainer}
showsHorizontalScrollIndicator={false}
showsVerticalScrollIndicator={false}
>
<View
style={{
justifyContent: "space-between",
backgroundColor: "green",
}}
>
<View style={styles.imageContainer}>
<Image></Image>
</View>
<View style={styles.formConstainer}>
<Formik></Formik>
</View>
</View>
</KeyboardAwareScrollView>
</View>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
},
scrollContainer: {
backgroundColor: "yellow",
},
imageContainer: {
alignItems: "center",
justifyContent: "center",
},
formConstainer: {},
});
这是它现在的样子。
解决方案
根据键盘隐藏和视图使 contentInset 成为动态的。根据您的设计设置 contentBottom 值。
解决方案中的值基于我的设计
const [contentBottom, setContentBottom] = useState(0);
<KeyboardAwareScrollView
style={{
flex: 1,
backgroundColor: Color.white,
}}
keyboardOpeningTime={0}
extraScrollHeight={150}
enableResetScrollToCoords
onKeyboardWillHide={() => setContentBottom(0)}
onKeyboardWillShow={() => setContentBottom(200)}
contentInset={{ bottom: contentBottom }}
>
推荐阅读
- android - Jetpack Compose Canvas BlendMode.SRC_IN 使背景变得透明
- javascript - jQuery 如何获取当前年份?
- javascript - React 功能组件随着数组状态的变化呈指数级重新渲染
- ios - @google-cloud/translate 导致 React Web 应用程序在 Safari 中出现空白屏幕
- node.js - ParallelSaveError:无法并行保存()同一个文档。文档:
- powershell - 如何处理错误输入的日期和密码复杂性?
- php - WooCommerce 彩票号码:在彩票号码中添加前导零
- c - 关于使用 sprintf 和 snprintf 中的指针构建字符串的新手 C 问题
- reactjs - 如何在“react-native-webrtc”中播放音频
- r - R情绪分析;找不到“词典”;