Repository navigation
Commit f4bd6d7
Fix TextInput absorbing scroll gestures on Android (#58678)
Summary:
Fixes the issue described in [#25594](#25594) and [#12167](#12167), where TextInputs on Android absorb scroll gestures when textAlign is set to "center" or "right". For TextInputs inside a ScrollView, starting a scroll gesture on the TextInput would not scroll the ScrollView.
### Root Cause
The root cause is the `onTouchEvent()` function introduced in [commit 372d001](372d001). The smart scroll implementation checks if the TextInput can itself scroll in any direction. If it cannot, then the parent can intercept the gesture to apply normal scroll behavior.
However, when textAlign is set to "center" or "right", `canScrollHorizontally()` returns true, as Android treats the TextInput as capable of scrolling left/right. In these cases, the existing conditional logic blocks all scroll gestures, even if a vertical swipe is applied.
### This PR
Modify `ReactEditText` so that we only check to see if the TextInput can scroll in the direction of the provided touch gesture. If a TextInput can scroll horizontally but not vertically, vertical touch swipes will no longer interfere with the scroll gesture. Touch slop is also used to distinguish intentional swipe gestures from small micro-touch events.
Changelog: [Android][Fixed] Prevent TextInput from preventing scroll gestures
Differential Revision: D1215196761 parent 804c41e commit f4bd6d7
2 files changed
Lines changed: 46 additions & 11 deletions
File tree
- packages
- react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput
- rn-tester/js/examples/ScrollView
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
| 39 | + | |
39 | 40 | | |
40 | 41 | | |
41 | 42 | | |
| |||
91 | 92 | | |
92 | 93 | | |
93 | 94 | | |
| 95 | + | |
94 | 96 | | |
95 | 97 | | |
96 | 98 | | |
| |||
132 | 134 | | |
133 | 135 | | |
134 | 136 | | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
135 | 140 | | |
136 | 141 | | |
137 | 142 | | |
| |||
316 | 321 | | |
317 | 322 | | |
318 | 323 | | |
| 324 | + | |
| 325 | + | |
319 | 326 | | |
320 | 327 | | |
321 | 328 | | |
| |||
324 | 331 | | |
325 | 332 | | |
326 | 333 | | |
327 | | - | |
328 | | - | |
329 | | - | |
330 | | - | |
331 | | - | |
332 | | - | |
333 | | - | |
334 | | - | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
335 | 343 | | |
336 | | - | |
337 | 344 | | |
338 | 345 | | |
339 | 346 | | |
340 | 347 | | |
341 | 348 | | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
342 | 361 | | |
343 | 362 | | |
344 | 363 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
471 | 471 | | |
472 | 472 | | |
473 | 473 | | |
| 474 | + | |
474 | 475 | | |
475 | 476 | | |
476 | 477 | | |
| |||
479 | 480 | | |
480 | 481 | | |
481 | 482 | | |
| 483 | + | |
482 | 484 | | |
483 | 485 | | |
484 | 486 | | |
| |||
634 | 636 | | |
635 | 637 | | |
636 | 638 | | |
637 | | - | |
| 639 | + | |
638 | 640 | | |
639 | 641 | | |
640 | 642 | | |
| |||
645 | 647 | | |
646 | 648 | | |
647 | 649 | | |
648 | | - | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
649 | 655 | | |
650 | 656 | | |
651 | 657 | | |
652 | 658 | | |
| 659 | + | |
653 | 660 | | |
654 | 661 | | |
655 | 662 | | |
656 | 663 | | |
657 | 664 | | |
| 665 | + | |
658 | 666 | | |
659 | 667 | | |
660 | 668 | | |
661 | 669 | | |
662 | 670 | | |
663 | 671 | | |
664 | 672 | | |
| 673 | + | |
665 | 674 | | |
666 | 675 | | |
667 | 676 | | |
| |||
670 | 679 | | |
671 | 680 | | |
672 | 681 | | |
| 682 | + | |
673 | 683 | | |
674 | 684 | | |
675 | 685 | | |
| |||
682 | 692 | | |
683 | 693 | | |
684 | 694 | | |
| 695 | + | |
685 | 696 | | |
686 | 697 | | |
687 | 698 | | |
| |||
711 | 722 | | |
712 | 723 | | |
713 | 724 | | |
| 725 | + | |
714 | 726 | | |
715 | 727 | | |
716 | 728 | | |
717 | 729 | | |
718 | 730 | | |
| 731 | + | |
719 | 732 | | |
720 | 733 | | |
721 | 734 | | |
722 | 735 | | |
723 | 736 | | |
724 | 737 | | |
725 | 738 | | |
| 739 | + | |
726 | 740 | | |
727 | 741 | | |
728 | 742 | | |
| |||
731 | 745 | | |
732 | 746 | | |
733 | 747 | | |
| 748 | + | |
734 | 749 | | |
735 | 750 | | |
736 | 751 | | |
| |||
747 | 762 | | |
748 | 763 | | |
749 | 764 | | |
| 765 | + | |
750 | 766 | | |
751 | 767 | | |
752 | 768 | | |
| |||
0 commit comments