在 Select 下拉值后,我试图聚焦TextInput时出错.
这是我用来设置inputRef的函数
let inputRef = useRef<TextInput | null>(null)
const onSelectFormat = (format) => {
setDropdownListVisibility('')
setInputFocused(true)
inputRef.current && inputRef.current.focus()
}
发送inputRef变量的CustomInput组件
<CustomInput
value={value}
onChangeText={onChangeInputText}
isFocused={isInputFocused}
onFocus={() => setInputFocused(true)}
getRef={ref => (inputRef = { current: ref })}
/>
最后,这是我传递ref的子组件.
<TextInput
ref={getRef}
value={value}
onChangeText={onChangeText}
style={styles.input}
onFocus={onFocus}
/>