-
Notifications
You must be signed in to change notification settings - Fork 24.3k
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
nested text onPress not working on last character #30928
Conversation
Base commit: 4324ca8 |
@@ -359,7 +359,7 @@ public int reactTagForTouch(float touchX, float touchY) { | |||
for (int i = 0; i < spans.length; i++) { | |||
int spanStart = spannedText.getSpanStart(spans[i]); | |||
int spanEnd = spannedText.getSpanEnd(spans[i]); | |||
if (spanEnd > index && (spanEnd - spanStart) <= targetSpanTextLength) { | |||
if (spanEnd >= index && (spanEnd - spanStart) <= targetSpanTextLength) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am asking myself why it did work on non-nested Text.
I need to find the reason spanEnd reaches the index value on the last characted when the Text is nested in another Text
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue was not experienced on non-nested text as normal Text will not generate Spans. Spans are generated by nested Text react tags
I investigated the current failures in the CI and they not are related to this pr. I tried but could not find a solution to the failures, which relate to AppCompat ( Unluckily the Java Unit Test for ReactTextTest were disabled for an issue with Yoga linking t14964130
Related Discussions #11570 #11511 (comment) I will invest my time writing Java tests for other functionalities as this seems pretty hard issues to solve. Thanks |
Base commit: 4324ca8 |
Facing same issue. What are the plans to move it forward ? Thanks @fabriziobertoglio1987 for this. This patch is working for us. |
@charlesbdudley has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
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