Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/383.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 无法从ref setNativeProps更改文本样式_Javascript_React Native_Dom_React Hooks_Ref - Fatal编程技术网

Javascript 无法从ref setNativeProps更改文本样式

Javascript 无法从ref setNativeProps更改文本样式,javascript,react-native,dom,react-hooks,ref,Javascript,React Native,Dom,React Hooks,Ref,当我的一些文本输入处于焦点时,我想改变我的组件的一些样式 我使用expo 34.0.0 我尝试过两种方法:使用ref和使用state,它们都有我需要理解的问题 到目前为止,中的样式在我通过TextInput中的onFocus函数进行更改时,工作正常 但是,当我试图通过调用refTitle.current.setNativeProps()以相同的方法在中包含或使用按钮更改refTitle的样式时,该方法无效,每次尝试更改文本样式时,它只返回refTitle.current.setNativePro

当我的一些文本输入处于焦点时,我想改变我的组件的一些样式

我使用expo 34.0.0

我尝试过两种方法:使用ref和使用state,它们都有我需要理解的问题

到目前为止,
中的样式在我通过TextInput中的
onFocus
函数进行更改时,工作正常

但是,当我试图通过调用
refTitle.current.setNativeProps()
以相同的方法在
中包含或使用按钮更改
refTitle
的样式时,该方法无效,每次尝试更改文本样式时,它只返回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 } }) }
            />
我不知道为什么它不起作用,一直在搜索,但向导告诉我这没关系,这是最近的一个错误吗

第二。我确实使用了state,这更简单,但有一种bug我不明白


我只需使用onFocus函数设置新颜色,…每次单击文本输入,它都会更改颜色。。。但它不是真正的对焦,我必须再次单击以使其完全对焦(键盘显示,指示灯开始滴答作响)

您必须使用参考来使用setNativeProps

 <TextInput
 ref={ref => {this.referencedeTF = ref;
          }}
/>
  this.referencedeTF.setNativeProps({
        borderColor: "red",
        borderWidth: 1
      });
{this.referencedeTF=ref;
}}
/>
this.referencedeTF.setNativeProps({
边框颜色:“红色”,
边框宽度:1
});

您使用的引用方式错误。

结果表明我使用的是不同的
,而不是来自react native。。。解决了这个问题,但我仍然很困惑,如果使用state强制我点击两次以触发焦点,而第一次按下时已经改变了颜色,可能是因为文本不是react native的本源,因为我使用的是useRef。。。但是我已经解决了我的问题。。。原来我忘了我的
不是react native软件包中的本机软件。。。无论如何,谢谢你的回答
 <TextInput
 ref={ref => {this.referencedeTF = ref;
          }}
/>
  this.referencedeTF.setNativeProps({
        borderColor: "red",
        borderWidth: 1
      });