是否可以使键盘始终在屏幕上可见?
屏幕上有:
TextInput
(多行)FlatList
当我在TextInput
中键入内容时可以,但是当我将内容更改为FlatList时,键盘被隐藏了
无论我在屏幕上做什么,我都希望键盘始终可见
我测试了什么
keyboardShouldPersistTaps='always'
无法正常工作autoFocus
设置为TextInput
,并且在隐藏键盘时进行了每次更改,请再次显示它。我以为可以做到这一点,以使过渡不可见,但无法正常运行componentDidUpdate() {
setTimeout(() => {
this.nameInput.focus();
}, 1);
}
有什么办法吗?
答案 0 :(得分:0)
您应在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