【发布时间】:2021-03-19 07:56:13
【问题描述】:
我正在努力将文本输入字段与 iOS / Android 系统键盘同步,以便它粘在键盘的顶部,在 react native Keyboard 模块的文档中提到了这种方法:
scheduleLayoutAnimation
static scheduleLayoutAnimation(event)对于同步 TextInput(或其他键盘附件视图)大小很有用 的位置随键盘移动而变化。
但是到目前为止,我似乎找不到任何进一步的文档或示例,以及我当前的实现
Keyboard.scheduleLayoutAnimationscheduleLayoutAnimation((event: any ) => {
console.log('[TextEditor] keyboard event:', event)
})
抛出以下错误:
ExceptionsManager.js:179 类型错误: _reactNative.Keyboard.scheduleLayoutAnimationscheduleLayoutAnimation 不是函数
有人对这种方法有经验吗?
我目前正在使用 React Native 0.63.3 并在 iOS 14.2 上进行测试,非常感谢任何帮助,谢谢!
编辑
我能够通过调用获得函数签名:
Keyboard.scheduleLayoutAnimationscheduleLayoutAnimation.toString()
产生这个定义:
function (event) {
var duration = event.duration,
easing = event.easing;
if (duration != null && duration !== 0) {
LayoutAnimation.configureNext({
duration: duration,
update: {
duration: duration,
type: easing != null && LayoutAnimation.Types[easing] || 'keyboard'
}
});
}
}
也许这是 TypeScript 中严格模式的问题?
【问题讨论】:
-
也找到了这个方法。你知道怎么用了吗?
-
@likern 我还没有,我想你可能会在 Animated.Event 中遇到 pass 但不确定...
-
有任何更新或同步文本输入和键盘的替代解决方案吗? @Asleepace
-
@AlexBishka 还没有运气,我会更新这个!
-
很好奇如何使用它。
标签: react-native keyboard