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

Android: onMomentumEnd called many times #6896

Closed
icedcrow opened this issue Jan 14, 2025 · 1 comment · Fixed by #6907
Closed

Android: onMomentumEnd called many times #6896

icedcrow opened this issue Jan 14, 2025 · 1 comment · Fixed by #6907
Labels
Platform: Android This issue is specific to Android Repro provided A reproduction with a snippet of code, snack or repo is provided

Comments

@icedcrow
Copy link

Description

I am experiencing an issue where the onMomentumEnd event is always called multiple times on Android.

image

This behavior is particularly noticeable when the ScrollView has the snapToInterval property set.

image

This issue does not seem to occur on iOS. It is specific to the Android environment.

I found the same issue here: #2735 (comment)

Steps to reproduce

function MyTest() {
  const [w, sW] = useState(0);

  const scrollHandler = useAnimatedScrollHandler({
    onBeginDrag() {
      console.log('start');
    },
    onMomentumEnd() {
      console.log('end');
    },
  });

  return (
    <View
      style={{ flex: 1 }}
      onLayout={(evt) => sW(evt.nativeEvent.layout.width)}>
      <Animated.ScrollView
        onScroll={scrollHandler}
        horizontal
        snapToInterval={w}
        decelerationRate="fast">
        {Array.from({ length: 20 })
          .fill(0)
          .map((_, i) => {
            return (
              <View key={i} style={{ width: w }}>
                <Text>{i}</Text>
              </View>
            );
          })}
      </Animated.ScrollView>
    </View>
  );
}

Snack or a link to a repository

https://www.npmjs.com/package/react-native-reanimated

Reanimated version

3.14.0

React Native version

0.71.19

Platforms

Android

JavaScript runtime

None

Workflow

None

Architecture

None

Build type

None

Device

None

Device model

No response

Acknowledgements

Yes

@github-actions github-actions bot added Platform: Android This issue is specific to Android Missing repro This issue need minimum repro scenario labels Jan 14, 2025
Copy link

Hey! 👋

The issue doesn't seem to contain a minimal reproduction.

Could you provide a snack or a link to a GitHub repository under your username that reproduces the problem?

@szydlovsky szydlovsky added Repro provided A reproduction with a snippet of code, snack or repo is provided and removed Missing repro This issue need minimum repro scenario labels Jan 16, 2025
github-merge-queue bot pushed a commit that referenced this issue Feb 4, 2025
## Summary

Fixes
#6896

When adding support for fabric, we have inadvertently kept previous
listeners still active for fabric. This way, we registered twice with
the same `NodesManager` for React Native's `FabricEventDispatcher`,
resulting in pretty much all the events doubling in number on android. I
added a simple check that takes care of it.

## Test plan

Paste the following into `EmptyExample` and run `FabricExample`. Check
logs making sure that both `start` and `end` are logged only once per
gesture.

```TSX
import React, { useState } from 'react';
import { View, Text } from 'react-native';
import Animated, { useAnimatedScrollHandler } from 'react-native-reanimated';

function EmptyExample() {
  const [w, sW] = useState(0);

  const scrollHandler = useAnimatedScrollHandler({
    onBeginDrag() {
      console.log('start');
    },
    onMomentumEnd() {
      console.log('end');
    },
  });

  return (
    <View
      style={{ flex: 1 }}
      onLayout={(evt) => sW(evt.nativeEvent.layout.width)}>
      <Animated.ScrollView
        onScroll={scrollHandler}
        horizontal
        snapToInterval={w}
        decelerationRate="fast">
        {Array.from({ length: 20 })
          .fill(0)
          .map((_, i) => {
            return (
              <View key={i} style={{ width: w }}>
                <Text>{i}</Text>
              </View>
            );
          })}
      </Animated.ScrollView>
    </View>
  );
}

export default EmptyExample;

```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Platform: Android This issue is specific to Android Repro provided A reproduction with a snippet of code, snack or repo is provided
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants