是否可以让键盘在屏幕上始终可见?
屏幕有:
- 一个
TextInput
(多行)
- 两个
FlatList
当我在 TextInput
中输入内容时没问题,但是当我将内容更改为 FlatList 时,键盘被隐藏了
无论我在屏幕上做什么,我都希望键盘始终可见
我测试的内容:
keyboardShouldPersistTaps='always'
不工作
- 一开始我将
autoFocus
设置为 TextInput
并在隐藏键盘时再次显示它。我以为我可以做到这一点,这样过渡就看不到了,但它并没有像它应该的那样工作
componentDidUpdate() {
setTimeout(() => {
this.nameInput.focus();
}, 1);
}
有什么办法吗?
您应该向 keyboardWillHide
添加一个事件监听器,并在事件触发时聚焦您的 nameInput
TextField
。
像这样:
import React, { Component } from "react";
import { Keyboard, TextInput } from "react-native";
class MyComponent extends Component {
componentDidMount() {
this.keyboardWillHideListener = Keyboard.addListener(
"keyboardWillHide",
this._keyboardWillHide,
);
}
componentWillUnmount() {
this.keyboardWillHideListener.remove();
}
_keyboardWillHide() {
// Focus the input
}
render() {
// Your UI here
}
}
可在此处找到更多信息:https://facebook.github.io/react-native/docs/keyboard.html