gpt4 book ai didi

android - KeyboardAvoidingView 中的高度 vs 位置 vs 填充 "behavior"

转载 作者:可可西里 更新时间:2023-11-01 03:00:10 25 4
gpt4 key购买 nike

KeyboardAvoidingView 中有一个“行为”属性,例如:

import { KeyboardAvoidingView } from 'react-native';

<KeyboardAvoidingView style={styles.container} behavior="padding" enabled>
... your UI ...
</KeyboardAvoidingView>

它可以被选为以下三个选项之一:'height''position''padding'。区别不解释in the documentation .它只是说不需要设置属性,并且有一个注释:

Note: Android and iOS both interact with this prop differently. Android may behave better when given no behavior prop at all, whereas iOS is the opposite.

这些设置应该有什么效果?

最佳答案

我同意这里缺少文档令人沮丧。如果你深入研究 KeyboardAvoidingView 的源代码, 你会在 behavior 周围找到一个开关: https://github.com/facebook/react-native/blob/92073d4a71d50a1ed80cf9cb063a6144fcc8cf19/Libraries/Components/Keyboard/KeyboardAvoidingView.js#L157

看起来发生了以下情况:

height

A <View>返回的样式试图为 View 设置静态高度,该高度可以是屏幕高度,也可以是屏幕高度减去键盘(当键盘存在时)。

position

嵌套 <View>返回,其中外部 View 应用了您的样式,内部 View 具有 bottom应用的样式试图在键盘存在时匹配键盘高度。

padding

<View>paddingBottom 处返回如果键盘存在,样式将应用于键盘的高度。


鉴于可用的任意选项,使用 KeyboardAvoidingView 时看起来像您应该反复试验,并检查两种设备以获得您想要的结果。理论上所有三个选项都应该有效,但正如文档所说,设备类型之间存在一些细微差别。

在我看来,这个组件应该被废弃,取而代之的是随着时间的推移返回键盘高度的辅助函数,这样您就可以直接根据键盘的可见性应用您自己的风格想法。

关于android - KeyboardAvoidingView 中的高度 vs 位置 vs 填充 "behavior",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47661480/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com