Skip to content

Cherry pick #7292 #7319

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

Merged

Conversation

bartlomiejbloniarz
Copy link
Contributor

@bartlomiejbloniarz bartlomiejbloniarz commented Mar 28, 2025

Summary

Cherry pick #7292

Test plan

## Summary

In RN 0.77 a [batching mechanism for commands was
introduced](facebook/react-native@6f1c2a5)
behind a feature flag. It was enabled in RN 0.77, but mistakenly
disabled in RN 0.78. Now, in RN 0.79 it is back.

The mechanism makes it so that our `scrollTo` calls are only applied
from `RuntimeSecheduler_Modern::updateRendering` on event loop tick. So
when there was nothing happening on the JS thread, our updates wouldn't
be propagated to the platform (That's why adding a console.log to each
frame would fix scrolling in the repro). To fix that we bypass batching,
by calling `schedulerDidDispatchCommand` directly on the
`SchedulerDelegate`.

This issue is a different thing that the one reported in #6999 by
@MatiPl01. It is most probably what @hirbod reported under the same
issue.

## Test plan
<details>
<summary>
Code snippet
</summary>

```jsx

import { StyleSheet, Text } from 'react-native';
import Animated, {
  scrollTo,
  useAnimatedRef,
  useAnimatedStyle,
  useFrameCallback,
  useSharedValue,
  withRepeat,
  withSequence,
  withTiming,
} from 'react-native-reanimated';

const COUNT = 200;

export default function PlaygroundExample() {
  const animatedRef = useAnimatedRef<Animated.ScrollView>();
  const sv = useSharedValue(0);

  useFrameCallback(() => {
    sv.value++;
    scrollTo(animatedRef, 0, sv.value, false);
  });

  return (
    <Animated.ScrollView ref={animatedRef}>
      {Array.from({ length: COUNT }, (_, index) => (
        <Item
          color={`hsl(210, 80%, ${COUNT - index}%)`}
          name={`Item ${index + 1}`}
          key={index}
        />
      ))}
    </Animated.ScrollView>
  );
}

function Item({ color, name }: { name: string; color: string }) {
  const animatedStyle = useAnimatedStyle(() => {
    return {
      transform: [
        {
          translateX: withRepeat(
            withSequence(withTiming(100), withTiming(0)),
            -1,
            true
          ),
        },
      ],
    };
  });

  return (
    <Animated.View
      style={[styles.item, animatedStyle, { backgroundColor: color }]}>
      <Text style={styles.text}>{name}</Text>
    </Animated.View>
  );
}

const styles = StyleSheet.create({
  item: {
    alignItems: 'center',
    justifyContent: 'center',
    backgroundColor: 'red',
    height: 100,
  },
  text: {
    fontWeight: 'bold',
  },
});
```
Copy link
Contributor

@patrycjakalinska patrycjakalinska left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🪨

@patrycjakalinska patrycjakalinska merged commit 39d2c7d into 3.17-stable Mar 31, 2025
34 of 48 checks passed
@patrycjakalinska patrycjakalinska deleted the @bartlomiejbloniarz/cherry-pick-scrollTo branch March 31, 2025 12:51
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

Successfully merging this pull request may close these issues.

2 participants