USEREF()在Android应用中不起作用(React Antial)
我有几个在数学应用程序上使用的文本输入。用户可以放置一个数字,然后在结束时单击按钮,该文本输入显示正确的答案。我使用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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用
setNativeProps
阅读有关它的更多信息:
https://reactnative.dev/dev/docs/0.66/direct-manipulation
所以将是这样的:
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:
这是因为用于更改这些值的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.