nested text onPress not working on last character #30928
Closed
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.
Summary
This issue fixes #22747 nested text does not allow you to press on the last character.
The method reactTagForTouch filters touches based on coordinates x and y. Nested Texts are converted into Spans on Android
react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactBaseTextShadowNode.java
Lines 111 to 112 in 28fb41a
https://developer.android.com/guide/topics/text/spans
reactTagForTouch iterates over the span and triggers the onPress handler if the x,y coordinates correspond to one of the span characters.
Changelog
[Android] [Fixed] - Nested Text Android onPress does not work with last character
Test Plan
This changes fix the Java API which can not be tested as explained in commit 709a441
The java TextTest was excluded from the test suite in commit 709a441 as they need the Yoga libraries to run
TEST - Clicking on the last letter triggers the callback
Clicking on the last letter does not invoke the onPress callback (in this case a console.warn)
Clicking on the last letter does invoke the onPress callback (in this case a console.warn)
TEST - Adding and removing Text
2021-02-10.17-41-44.mp4
TEST - Different type of languages
2021-02-10.17-44-20.mp4
TEST - Testing other Examples that use onPress handler
2021-02-10.17-46-24.mp4
TEST - Text with Inline Images