我正在构建一个反应原生的应用程序.我有一个< TextInput>,当出现问题时,我希望引起< TextInput>变得专注. < TextInput>上唯一记录的方法实例是.isFocused()和.clear() – 看起来都不像我在寻找.我显然想要.focus().
我发现这个仅限iOS的selectedState道具似乎提供了我正在寻找的东西. The docs说:
@H_502_10@iOS selectionState DocumentSelectionState
An instance of DocumentSelectionState
,this is some state that is responsible for maintaining selection information for a document.
Some functionality that can be performed with this instance is:
blur()
focus()
update()
You can reference DocumentSelectionState
in vendor/document/selection/DocumentSelectionState.js
我不清楚如何运用这个道具,我没有在网上找到任何例子.在doc页面上发布的冗长示例代码不使用它.
有人能告诉我这可能是什么样子吗?这是我最好的猜测:
import React,{
Component
} from 'react';
import {
// the "DocumentSelectionState.js" file mentioned in the docs
// lives inside react-native,so hopefully it's exported
DocumentSelectionState,TextInput,TouchableHighlight,View
} from 'react-native';
import Styles from './style';
export default class Scene extends Component {
constructor(props) {
super(props);
// get my hands on "An instance of DocumentSelectionState"
// which I can pass to the TextInput,and whose .focus()
// method I can call
this.text1DSS = new DocumentSelectionState();
}
render() {
return (
不幸的是,该代码将无法运行:
@H_502_10@undefined is not a constructor (evaluating ‘new _reactNative.DocumentSelectionState()’)
我认为这意味着react-native不会导出DocumentSelectionState成员(或者至少我的版本不是:0.23,仍然是documents the prop).
我无法弄清楚如何在vanilla RN设置中访问DocumentSelectionState,所以我无法真正测试我的理论.
谁有人在这里工作?