Avoid multi-line update() app crash by checking first if the focused TextField is a descendant of the ScrollView #322
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
If you have multiple KASVs and multiple text input fields across multiple containers, and wish to use the KASV update() solution to resolve your multi-line scrollView issue - you may come across this particular error screen.
We reference and summarize @alvaromb’s thorough explanation below, regarding checking React node descendants - specifically his discussion around checking if a focused TextInput is a descendent of a specific ScrollView.
For example, say there is a base screen that has ScrollView and multiple input fields. The user then taps on a button and navigates to another screen which also has ScrollView and input fields. Since the base screen did not unmount, both ScrollViews continue to exist and both will receive the keyboard events. This will cause your app to crash when the user taps on an input field on that second screen.
By checking first in the update() function that the focused TextInput field is a descendant of a specific ScrollView, we can avoid the ScrollView (that does not have the focused input as a descendent) attempting to scroll to the focused input and then crashing.