USEREF()在Android应用中不起作用(React Antial)

发布于 2025-02-10 02:43:14 字数 638 浏览 3 评论 0原文

我有几个在数学应用程序上使用的文本输入。用户可以放置一个数字,然后在结束时单击按钮,该文本输入显示正确的答案。我使用USEREF来处理此值,因为我不希望使用Usestate重新租赁。我在浏览器中使用Expo和测试,这一切都可以,但是一旦我对Android进行测试,与Useref一起使用的唯一一件事就很明显。

示例

<TextInput
    onChangeText={ActionChange} 
    ref={refTextInput}
    style={styles.somestyles} 
    keyboardType='numeric'  
    placeholder="?"
    ></TextInput>

我使用reftextinput.current.clear() 然后显示我使用的结果:

reftextinput.current.style.style.color ='red' - 在浏览器上不在Android中工作 reftextinput.current.value = valueOne+valuetwo-在浏览器上工作,而不是在android

onChangeText中的浏览器也无问题地在任何地方工作。

我正在寻找我还能做什么,或者为什么它不起作用。 谢谢

I have several TextInput that I am using on a math app. The user can put a number and at the end click on a button and that textInput shows the right answer. I use useRef to work with this values as I don't want re-renders with UseState. I use expo and testing in a browser , it all works but once I test on android, the only thing that works with useRef is clear.

example

<TextInput
    onChangeText={ActionChange} 
    ref={refTextInput}
    style={styles.somestyles} 
    keyboardType='numeric'  
    placeholder="?"
    ></TextInput>

I use refTextInput.current.clear() that works
and then on showing the results I use:

refTextInput.current.style.color='red' - works on browser not in android
refTextInput.current.value=ValueOne+ValueTwo - works on browser not in android

onChangeText is also working everywhere without problem.

I am looking how else I can do it or why it does not work.
Thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

千笙结 2025-02-17 02:43:15

您可以使用 setNativeProps

阅读有关它的更多信息:
https://reactnative.dev/dev/docs/0.66/direct-manipulation

所以将是这样的:

 function changeColor(e) {
      if(Platform.OS == "android") 
         refTextInput.current.setNativeProps({backgroundColor:"red"}) // android
      else if(Platform.OS == "web")
         e.target.style.backgroundColor="red"// web 
      }
    onChangeText={(e)=>changeColor(e)}

You can use setNativeProps

to read more about it:
https://reactnative.dev/docs/0.66/direct-manipulation

so your code will be something like that:

 function changeColor(e) {
      if(Platform.OS == "android") 
         refTextInput.current.setNativeProps({backgroundColor:"red"}) // android
      else if(Platform.OS == "web")
         e.target.style.backgroundColor="red"// web 
      }
    onChangeText={(e)=>changeColor(e)}
白馒头 2025-02-17 02:43:15

这是因为用于更改这些值的API在Web和Android上不同。在Android上,您不能使用style.Color,但是在Web上可以使用它。

This is because the api for changing those values is not the same on web and android. On android you cannot use style.color, but on web you can use it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文