Skip to content
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

[FR] Disable automatic scrolling of ScrollView due to changes in focus #107

Closed
Jesse205 opened this issue Feb 19, 2024 · 0 comments
Closed

Comments

@Jesse205
Copy link
Contributor

SVID_20240219_080243_1.mp4

Translated from Baidu Translate

In Android, if textIsSelectable is set to TextView, it will automatically enable focusInTouchMode. (Although this may not be entirely reasonable, the fact is that it is.)

And in Android, if a View gains focus, Android will view it to display it fully on the screen.

This creates a situation in the video where when long pressing the selection button, ScrollView will immediately scroll to the position of TextView, causing a decrease in user experience (selecting multiple unrelated lines of text and potentially confusing the user).

In traditional android.widget.ScrollView, we only need to set 'setRevealOnFocusHint' to TextView, but this value does not work when using NestedScrollView because NestedScrollView was not evaluated during implementation.

So we need to use other methods. That is, after inheriting NestedView, rewrite the computeScrollDeltaToGetChildRectOnScreen method and return 0. I have tested in another project and it will work.

Translated from ERNIE Bot

In Android, when the textIsSelectable property is enabled for a TextView, the focusInTouchMode is automatically activated. This may seem counterintuitive, but it's the actual behavior.

Additionally, in Android, when a View gains focus, the system assumes it needs to be fully visible on the screen.

This can lead to the issue described in the video, where upon long-pressing a TextView, the ScrollView immediately scrolls to the position of the TextView, potentially degrading the user experience (as multiple lines of text may be unintentionally selected during the long-press, leading to confusion).

In the traditional android.widget.ScrollView, one workaround for this issue is to set the setRevealOnFocusHint property of the TextView to true. However, when using NestedScrollView, this workaround does not work as NestedScrollView does not take this property into account during its implementation.

Therefore, an alternative approach is necessary. One such approach is to inherit from NestedScrollView and override the computeScrollDeltaToGetChildRectOnScreen method, returning 0. I have tested this approach in another project, and it resolves the issue.

Related links

https://blog.csdn.net/ZYJWR/article/details/108386309

@F0x1d F0x1d closed this as completed Feb 25, 2024
F0x1d added a commit that referenced this issue Feb 25, 2024
* [build]: updated dependencies

* [fix]: improved code around the whole project, fixed #106 and #107

* [feat]: session cache, closes #103

* [feat]: update zh_rCN translation

---------

Co-authored-by: ‭huajijam <strhuaji@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants