Skip to content

[Android] Tapping selectable text inside a ScrollView can cause the ScrollView to jump to the top under some circumstances #33419

Open

Description

@artemiswkearney

Description

After selectable text inside a ScrollView has been touched in a way that neither creates a selection nor scrolls the ScrollView, certain interactions cause the ScrollView to scroll to the top.
(I'm not sure exactly what set of events are necessary to trigger the jump, but I have a text unloading algorithm that consistently causes it. The issue may be specific to large or nested Texts, and may have to do with content changing as the result of a scroll event? Changing the content of the text in a setInterval didn't seem to be enough to cause it, so I just copied the unloading algorithm out of my codebase.)

As a workaround, updating the key prop on the selectable text component seems to clear the glitched state.

Version

0.67.3 (originally observed on 0.64.1)

Output of npx react-native info

info Fetching system and libraries information...
System:
    OS: Windows 10 10.0.22000
    CPU: (12) x64 Intel(R) Core(TM) i7-10750H CPU @ 2.60GHz
    Memory: 3.72 GB / 15.76 GB
  Binaries:
    Node: 17.7.1 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.5 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
    npm: 8.5.2 - C:\Program Files\nodejs\npm.CMD
    Watchman: Not Found
  SDKs:
    Android SDK: Not Found
    Windows SDK: Not Found
  IDEs:
    Android Studio: Not Found
    Visual Studio: 16.10.31402.337 (Visual Studio Community 2019), 15.9.28307.1033 (Visual Studio Community 2017)
  Languages:
    Java: 1.8.0_282 - C:\Program Files\OpenJDK\openjdk-8u282-b08\bin\javac.EXE
  npmPackages:
    @react-native-community/cli: Not Found
    react: 17.0.2 => 17.0.2
    react-native: 0.67.3 => 0.67.3
    react-native-windows: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

Steps to reproduce

  1. Run the Snack below on an Android device (Snack's provided one or your own).
  2. Scroll up and down; observe that scrolling works as expected.
  3. Tap on the text without starting a selection or scrolling. (Tapping to cancel a selection works.)
  4. Try scrolling again; observe that the scroll jumps to the top now.

Snack, code example, screenshot, or link to a repository

https://snack.expo.dev/b2Vgmc_4L
Set USE_WORKAROUND to true to see the workaround in action (this breaks the ability to actually select text, but if you need to use this in production, you can use https://github.com/artemiswkearney/react-native-selectable-text to add an onSelectionStart handler where you cancel running the workaround)

Activity

  1. suwu150 commented on Apr 12, 2022

    @suwu150

    i hava this problem too. is there a solutltion ?

  2. github-actions commented on Oct 14, 2022

    @github-actions

    This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.

  3. added
    StaleThere has been a lack of activity on this issue and it may be closed soon.
    on Oct 14, 2022
  4. artemiswkearney commented on Oct 14, 2022

    @artemiswkearney
    Author
  5. removed
    StaleThere has been a lack of activity on this issue and it may be closed soon.
    on Oct 15, 2022
  6. react3-moon commented on Jan 24, 2023

    @react3-moon

    @artemiswkearney any solution for this ?

  7. artemiswkearney commented on Jan 24, 2023

    @artemiswkearney
    Author
  8. github-actions commented on Mar 13, 2024

    @github-actions

    This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.

  9. added
    StaleThere has been a lack of activity on this issue and it may be closed soon.
    on Mar 13, 2024
  10. artemiswkearney commented on Mar 20, 2024

    @artemiswkearney
    Author
  11. added
    Never gets stalePrevent those issues and PRs from getting stale
    and removed
    StaleThere has been a lack of activity on this issue and it may be closed soon.
    on Mar 20, 2024
  12. mikenoriega commented on Feb 14, 2025

    @mikenoriega

    I have the same issue with a TextInput

  13. leaftail1880 commented on Mar 18, 2025

    @leaftail1880

    Happens to me too

  14. FrederickEngelhardt commented on Apr 17, 2025

    @FrederickEngelhardt

    Make sure to add removeClippedSubViews={false} this will prevent optimization preventing text selection even for views on screen...it should be a bug though since these views are on screen and it breaks even in small lists.

    This does not happen with scroll view but using scrollview . Do it only for Android though and consider pagination. This will break list performance efficiencies.

    Maybe Shopify Flashlist works. 🤔

    I'm able to reproduce this issue on a react native 0.74.5 (expo go) project.

    <FlatList removeClippedSubViews={Platform.OS !== 'android'} />
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions