當我的一些 textInput 處于焦點時,我想改變我的組件的一些樣式,我使用世博會 34.0.0有兩種方法,我嘗試過:使用 ref 和使用狀態,兩者都有我需要了解的問題。到目前為止,<TextInput>當我通過onFocusTextInput 的函數更改它們時,樣式按預期工作。但是當我嘗試<Text>通過包含或使用按鈕來更改樣式時,refTitle通過調用使用相同的方法進行更改refTitle.current.setNativeProps()不起作用,每次我嘗試更改文本樣式時,它只會返回 refTitle.current.setNativeProps 未定義。const refTitle = useRef(null)const refUser = useRef(null)return ( <Card> <Margin> <Text ref={ refTitle } style={ styles.title }>as</Text> <TextInput ref={ refUser } style={ [styles.input] } onSubmitEditing={ () => refPassword.current.focus() } onFocus={ () => refUser.current.setNativeProps({ style: { borderColor: FOCUS_COLOR } }) } onBlur={ () => refUser.current.setNativeProps({ style: { borderColor: BLUR_COLOR } }) } />因此,如果我將 textInput 中的 onFocus 更改為const handleFocus = () => { refTitle.current.setNativeProps({ style: { color: FOCUS_COLOR } }) refUser.current.setNativeProps({ style: { borderColor: FOCUS_COLOR } }) }我不知道為什么它不起作用,一直在搜索但指南告訴我沒關系,這是最近 React Native 中的錯誤嗎?第二。我確實使用了狀態,這更簡單,但有一種我不明白的錯誤。我只是使用 onFocus 函數來設置新顏色,......每次我點擊 textInput 時,它都會改變顏色......但它并沒有真正聚焦,我必須再次單擊以使其完全聚焦(鍵盤顯示和指示器開始滴答作響)
無法從 ref setNativeProps 更改文本樣式
qq_遁去的一_1
2021-09-30 10:27:42