- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我正在使用 React Natives KeyboardAvoidingView
设置显示键盘时我的 View
的高度。但是,当我在应用程序中关闭键盘时,View 的高度并没有变回原来的值。
<KeyboardAvoidingView behavior="height" style={styles.step}>
<View style={styles.stepHeader}>
// my content
</View>
</KeyboardAvoidingView>
在我打开和关闭键盘之前,带有红色轮廓的 View 确实占据了整个空间。
最佳答案
关于Nisarg的更详细解释的答案。
为 KeyboardAvoidingView
创建 key 在构造函数中
constructor(props) {
this.state = {
keyboardAvoidingViewKey: 'keyboardAvoidingViewKey',
}
}
在键盘的 will/did 隐藏上添加监听器(并在 willUnmount 中将其删除)
import { KeyboardAvoidingView, Keyboard, Platform } from 'react-native'
componentDidMount() {
// using keyboardWillHide is better but it does not work for android
this.keyboardHideListener = Keyboard.addListener(Platform.OS === 'android' ? 'keyboardDidHide': 'keyboardWillHide', this.keyboardHideListener.bind(this));
}
componentWillUnmount() {
this.keyboardHideListener.remove()
}
更新keyboardAvoidingViewKey
在keyboardHideListener
函数,每次都应该是一个新值(我使用了时间戳)并在呈现 KeyboardAvoidingView
时使用此键元素。
keyboardHideListener() {
this.setState({
keyboardAvoidingViewKey:'keyboardAvoidingViewKey' + new Date().getTime()
});
}
render() {
let { keyboardAvoidingViewKey } = this.state
return (
<KeyboardAvoidingView behavior={'height'} key={keyboardAvoidingViewKey} style={...}>
...
</KeyboardAvoidingView>
)
}
注意:请记住,这将重新创建 KeyboardAvoidingView
中的元素。 (即:将调用他们的 constructor
函数,我不太清楚为什么,我会在深入调查后更新答案),所以你必须跟踪任何可能被覆盖的状态/ Prop 值
经过更深入的调查,我现在知道为什么在更改 key 后会重新创建 View 。要想真正理解为什么会这样,必须要熟悉react-native是如何将render commands派发到native端的,这个具体解释比较长,感兴趣的可以看看我的回答here .简而言之,react-native 使用 Reactjs 来比较应该呈现的变化,然后将这些差异作为命令发送到名为 UIManager
的组件。 ,它发送转换为布局树的命令式命令,布局树根据 diff 命令更改布局。一旦你在一个组件上设置了一个键,reactjs 就使用这个键来识别对所述组件的更改,如果这个键发生变化,reactjs 将该组件识别为一个全新的组件,作为返回发送初始命令来创建所述组件,使其成为从头开始创建子项,因为在新布局树中有新元素被识别,删除旧树并创建新树而不是仅仅调整差异
如果您愿意,您实际上可以通过将以下代码添加到您的 App.js
来监视这些发送的消息文件:
import MessageQueue from 'react-native/Libraries/BatchedBridge/MessageQueue'
const spyFunction = (msg) => {
console.log(msg);
};
MessageQueue.spy(spyFunction);
如果这样做,您会在日志中注意到每次 key 更改时,返回的命令是 createViews
,如上所述,它创建了嵌套在所述组件下的所有元素。
关于javascript - KeyboardAvoidingView - 隐藏键盘时重置高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41616457/
enter image description here 当前行为KeyBoardAvoidingView 隐藏了登录按钮。在 Android 和 iPhone 上都一样。在 Android 平板电脑
我正在使用 React Natives KeyboardAvoidingView 设置显示键盘时我的 View 的高度。但是,当我在应用程序中关闭键盘时,View 的高度并没有变回原来的值。
上面的黄色区域是 Textarea 和一个按钮面板,预计会始终粘在屏幕底部。然而,当用户尝试输入时,键盘将阻止 View ,如下所示 我已经实现了 KeyboardAvoidingView 但它未能使
我搜索了很多关于这个问题,我现在不知道该怎么做,所以我决定在这里问,任何帮助将不胜感激。在我的注册屏幕中,我有一些 input该用户必须填写,最后一个我需要避免键盘覆盖。所以我用了 KeyboardA
我正在使用 react native 开发一个应用程序,我们有我们的设计师制作的屏幕布局。但我无法正确实现预期的行为。基本上它是一个带有一些文本输入和一个按钮的屏幕,当键盘出现时我需要一些东西来正确调
KeyboardAvoidingView 无法正常工作 我正在尝试将 KeyboardAvoidingView 与 behavior="padding" 一起使用。 出于某种原因,当我尝试在 Text
在我的 React-Native Expo 应用程序中,我似乎无法使用键盘来推送内容。我正在通过从我的开发机器发布它来从 expo App 测试它。 尽我所能,当键盘进入焦点时,似乎没有任何东西可以插
在我的 React-Native Expo 应用程序中,我似乎无法使用键盘来推送内容。我正在通过从我的开发机器发布它来从 expo App 测试它。 尽我所能,当键盘进入焦点时,似乎没有任何东西可以插
我遇到了 KeyboardAvoidingView 的问题,我有 3 个 TextInput,当我想在最后一个 TextInput 上写东西时,这个 TextInput 就被我的键盘偷走了。 expo
我有一个 TextInput按下时会被键盘覆盖。所以我把它包裹在 KeyboardAvoidingView .但不管我为此 View 设置的行为如何,TextInput不会在键盘上方移动。使用 pos
我在 tabnavigator 中有组件。在我的组件中,我有多行文本,所以当我在 InputText 键盘上输入多行时,我想使用 KeyboardAvoidingView 在键盘显示时推送屏幕。 这是
当使用具有behavior =“position”属性的KeyboardAvoidingView时,如果该KeyboardAvoidingView组件包含一个包含多个项目的View,则所有内部组件都会
我正在尝试将 KeyboardAvoidingView 与 behavior="padding"一起使用。 当我尝试在 TextInput 中输入任何文本时,TextInput 字段没有向上移动。我在
我使用 keyboardAvoidingView 来显示输入并使用下一个焦点。但是,当我点击第一个输入(打印标签 1623 - Acidez)时,这是隐藏的。如何显示这个?
I am using keyboardavoidingview in the following scroll to move up keyboard so that the submit butto
我有一个 FlatList 组件,每行内都有一个 Input。当我选择输入时,我希望它在键盘上方向上滚动。 我的代码: return ( } ListFooterCompo
我正在使用 React Native 的 Keyboard Avoiding View行为设置为填充(在 Android 上测试)。 我的屏幕上有多个 TextInput。当我单击最后一个 TextI
我正在尝试创建一个 KeyboardAvoidingView注册表单的区域。我已经将组件放到了一个在 iOS 和 Android 上可以进行实际键盘调整的地方。 但是,KeyboardAvoiding
我无法让 KeyboardAvoidingView 正常工作。对于类似的屏幕,它工作得很顺利,但是,对于另一个屏幕,它会将内容在屏幕上推得太远,在两者之间添加过多的空间。有修复吗? 代码:
我想知道如何在 React Native 中使用键盘。 当我点击输入内容(“发送”)时,没有键盘显示。 我尝试使用“KeyboardAvoidingView”,但键盘不显示。 ChatScreen.j
我是一名优秀的程序员,十分优秀!