简体   繁体   English

React Native:无法使用 ref 在 returnKeyType="next" 上切换到下一个 TextInput

[英]React Native : Not able to switch to next TextInput on returnKeyType="next" using ref

I am trying to move the focus from one TextInput to another on keyboard next press like in the below code in typescript我正在尝试将焦点从一个TextInput移动到键盘上的另一个下一次按下,就像 typescript 中的以下代码一样

But it shows "Property 'focus' does not exist on type 'never'.ts(2339)" error但它显示“类型'never'.ts(2339)上不存在属性'焦点'”错误

Is there any other method to do the same functionality有没有其他方法可以做同样的功能

const emailRef = React.useRef()
const passwordRef = React.useRef()

<TextInput
     ref={emailRef }                             // Current TextInput Ref
     onSubmitEditing={()=>passwordRef .current?.focus()}  // Changing focus
     secureTextEntry={isSecured}
     placeholder={placeHolder}
     placeholderTextColor={GREY[400]}
     selectionColor={GREY[900]}
     style={styles.inputText}
     onChangeText={onChangeText}
     keyboardType={keyboardType}
     onEndEditing={onEndEditing}
     autoFocus={autoFocus}
     returnKeyType={returnKeyType}
/>

you can try this你可以试试这个

inputRef = React.createRef<TextInput>();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM