-
Notifications
You must be signed in to change notification settings - Fork 24.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TextInput value can't be change during onChangeText [iOS] #18874
Comments
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
I am seeing a similar issue where I can't filter undesired characters from JS. I attempted to use the changes in the PR I tagged but I saw some issues: The problem is that if you are using onChangeText to do text validation, it will briefly show the undesired character before removing it from the TextInput. I don't know much about the React Native source code but after taking a brief look at the code, I think there might be a problem in textInputShouldChangeTextInRange in RCTBaseTextInputView.m. I think we should be preventing the text from being added until it comes in via the prop. Not entirely sure. |
It seems on iOS, value property is not the one prioritized, instead it shows the actual value typed in. Isn't this supposed to be the same with both platforms? OT: Why is this getting tag with "needs more information" while I already had it in the first place. |
@shergin @PeteTheHeat @cbrevik Any thoughts? Looks like you are the three that contributed most to RCTBaseTextInputView. |
I did some more digging and may have found a temporary fix for my project: I noticed that For my fix, I just returned I don't think I will be PRing this to React Native since it doesn't seem like a universal fix. Here is the diff if anyone is interested:
|
This comment has been minimized.
This comment has been minimized.
Thanks, @rplankenhorn . It works for now. You should submit a PR... |
@zaguini Glad it works for you! I am hesitant to submit a PR because it doesn't fix the underlying issue. onTextInput is undocumented and has been around since very very early on in the project. I know TextInput was just re-written but I think we all need to think about what is the best solution. It could be something as simple as adding an additional prop to TextInput called I can try to come up with a better solution and submit a PR but I am swamped at work currently. |
Yeah it should be ideal to mantain the React Native's |
Upon further testing, I found that modifying
The above fix is more robust as it allows for setting the text to an empty string if it's empty because it's been filtered. |
This comment has been minimized.
This comment has been minimized.
1 similar comment
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Here's a demo about this problem. In the demo, only numbers are accepted in the input. |
This comment has been minimized.
This comment has been minimized.
@shergin This issue very serious, controlled mode of TextInput really broken. Can you please look at this? You the only one who create new Text implementation and probably the best person who can fix this properly in align with philosophy of new implementation! |
@ycai2 @vdlindenmark I thought it's the same problem with Korean character problem. (it's another issue) |
@benevbright Oh I guess that makes sense. I also thought it was related. I saw a bunch issues that are similar, and some of them were referenced in this thread, so I thought it's the same problem. Thanks for the help though! |
Just checking, does 892212b fix the issue described in this thread? |
@hramos Tested applying these changes on 55.3 and did not fix this issue. |
@zhongwuzw I think you picked the wrong guy. I am not able to merge your PR . |
@yairopro 😂 I mean my |
@zhongwuzw ok. Good word dude 👍. Now let's see how this issue will be resolved with your PR😄 |
As of RN56: I started of @rplankenhorn solution, and then forwarded a "controlled" flag to I then created a You can find the module with doc and example here 😀 https://github.com/abelcha/react-native-controlled-input |
@shergin @PeteTheHeat @cbrevik Still no response? In almost 5 months having this major bug open... Everyone in the community experimenting workarounds and messing their own projects doing regressions because the version released is simply not doing its job correctly. Its normal to have bugs when features or code restructuring iterations are made, but this 5 month bug resolving threshold, projects absent commitment. Exactly as @vovkasm said, this is indeed a very strong message for community... |
if the textInput text length is longer than state text length,the text can't be change ,I don't want to change objective-c code,so I try a hack code,like this.
the core method is clear method, if I clear textInput,the textInput text length is shorter than state text length ,it is workaround for me. |
@abelcha thank you for the module, but if this is the way everyone will have to end up using react-native, it would be ridiculous... |
It would seem like the source for this bug is in RCTBaseTextInputView.m, if anyone wants to take a stab at fixing this. Frankly, this is not an issue that has shown up in our own apps, therefore it hasn't become a priority for us to dedicate time to fixing it. Please do send a PR if you'd like to propose a fix. We're also happy with taking @abelcha's approach of using third party modules; in fact, we're working towards a slimmer React Native core, where components such as Text Inputs might all be imported from npm packages outside of the RN core. |
works for me |
I'm concatenating alternated invisible characters to workaround this bug.
You'll probably want to avoid doing this on Android. Some OS versions will print the invisible chars. |
Holy crap. |
Fixed in which version @zaguiini ? |
Latest (v0.57.0), @fernandofranca. Check the CHANGELOG. |
I can confirm, that this bug fixed in RN 0.57, tested with this simple application (branch rn-0.57): https://github.com/vovkasm/react-native-textinput-bug/tree/rn-0.57 Also some flicker exists, it's currently unavoidable due to inter threads communication with controlled text inputs (information should move between UI and JS threads). |
I too have the issue with 0.57 |
@paramadeep Can you create reproducible example as in https://github.com/vovkasm/react-native-textinput-bug/ ? |
Can someone point me to the commit that fixed it? |
@danReynolds, I think it is 2307ea6 |
This is in 0.57.1. |
TextInput's value property does not seem to get in sync when changing state via onChangeText.
An example use case would be blocking non numerical characters from the input.
This works on Android though.
Environment
OS: macOS High Sierra 10.13.3
Node: 8.10.0
Yarn: 1.5.1
npm: 5.6.0
Watchman: 4.9.0
Xcode: Xcode 9.3 Build version 9E145
Android Studio: 3.1 AI-173.4697961
react: ^16.3.0-alpha.1 => 16.3.0-rc.0
react-native: 0.54.3 => 0.54.3
Expected Behavior
TextInput value should be equal to state value even when it is modified during onChangeText.
Actual Behavior
TextInput value is not being modified.
The text was updated successfully, but these errors were encountered: