Skip to content

[Android] scrollTo not working when it is called inside onScrollEndDrag #32119

@kyo504

Description

@kyo504

Description

Since 0.64.x, scrollTo method does not work when it is called inside onScrollEndDrag which means user lifts finger but view is being scrolled on Android. It seems that scrollTo is ignored while view is being scrolled. It works fine on iOS which means I guess it's a platform specific bug.

React Native version:

System:
    OS: macOS 11.3.1
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 34.03 MB / 32.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 14.16.0 - ~/.nvm/versions/node/v14.16.0/bin/node
    Yarn: 1.22.11 - ~/.nvm/versions/node/v14.16.0/bin/yarn
    npm: 6.14.11 - ~/.nvm/versions/node/v14.16.0/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  Managers:
    CocoaPods: 1.10.2 - /Users/danieljung/.rbenv/shims/pod
  SDKs:
    iOS SDK:
      Platforms: iOS 14.5, DriverKit 20.4, macOS 11.3, tvOS 14.5, watchOS 7.4
    Android SDK:
      API Levels: 29, 30
      Build Tools: 29.0.2, 30.0.2, 30.0.3
      System Images: android-29 | Google Play Intel x86 Atom, android-30 | Google APIs Intel x86 Atom
      Android NDK: Not Found
  IDEs:
    Android Studio: 4.2 AI-202.7660.26.42.7351085
    Xcode: 12.5.1/12E507 - /usr/bin/xcodebuild
  Languages:
    Java: 1.8.0_282 - /usr/bin/javac
  npmPackages:
    @react-native-community/cli: 5.0.1 => 4.14.0
    react: 17.0.2 => 17.0.2
    react-native: 0.65.1 => 0.65.1
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

Steps To Reproduce

  1. Just run the code example with latest RN version(0.65.x or 0.64.x)
  2. Scroll down

Expected Results

When user scrolls down and finishes drag, view should scroll back to top.

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

import React, { useState, useEffect, useRef } from 'react';
import { ScrollView, View, Text, Button } from 'react-native';

export default function App() {
  const scrollViewRef = useRef();

  return (
    <ScrollView
      ref={scrollViewRef}
      onScrollEndDrag={() => {
        scrollViewRef.current.scrollTo({ y: 0, animated: true });
      }}
      >
      <View style={{backgroundColor: 'yellow', height: 250}}/>
      <View style={{backgroundColor: 'teal', height: 250}}/>
      <View style={{backgroundColor: 'green', height: 250}}/>
      <View style={{backgroundColor: 'blue', height: 250}}/>
      <View style={{backgroundColor: 'red', height: 250}}/>
      <View style={{backgroundColor: 'teal', height: 250}}/>
      <View style={{backgroundColor: 'green', height: 250}}/>
      <View style={{backgroundColor: 'blue', height: 250}}/>
      <View />
    </ScrollView>
  )
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs: Triage 🔍StaleThere has been a lack of activity on this issue and it may be closed soon.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions