【发布时间】:2020-09-05 15:15:32
【问题描述】:
在我的 React Native 应用程序中,我有一个包含 TextInput 的自定义组件。在使用自定义组件的代码中,我想在TextInput 上调用.focus()。我尝试像这样直接在自定义组件上调用它:
<CustomComponent
ref={ref => {
this.customComponent = ref;
}}
/>
this.customComponent.focus();
但我不能,因为我认为自定义组件没有focus() 方法。我可以找到一种在包装好的TextInput 上调用它的方法,但我想知道是否有一种方法可以直接在自定义组件上调用它。
有人知道我该如何处理吗?
【问题讨论】:
-
可以在CustomComponent中定义焦点函数,调用TextInput的焦点函数。
标签: reactjs react-native focus textinput