Skip to content

Stuttering Animations with withDecay in Newer Versions of Skia #2999

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

Open
1 task done
petrikjan opened this issue Mar 4, 2025 · 6 comments
Open
1 task done

Stuttering Animations with withDecay in Newer Versions of Skia #2999

petrikjan opened this issue Mar 4, 2025 · 6 comments
Labels
bug Something isn't working

Comments

@petrikjan
Copy link

Description

I encountered an issue in newer versions of Skia. When using withDecay, the animation stutters. In Skia version 1.9.0, everything worked fine on both the New and Old React architecture. Touch-based scrolling without withDecay seems to work without issues. The versions of Reanimated and Gesture Handler have no impact on this.

I'm using Gesture.Pan() for scrolling, and withDecay is applied in onEnd. The movement is handled through Group transform using useDerivedValue. There is a fairly heavy computation and state changes happening in the component during scrolling, but as I said, it worked perfectly smoothly with the older Skia version.

React Native Skia Version

v2.0.0-next.1

React Native Version

0.78

Using New Architecture

  • Enabled

Steps to Reproduce

Create PAN gesture handler
Apply transform to Skia Group

Snack, Code Example, Screenshot, or Link to Repository

Simplified Code Selection:

const translateX = useSharedValue(0);
const translateY = useSharedValue(0);

  const panGesture = Gesture.Pan()
    .onUpdate((event) => {
      translateX.set(event.translationX);
      translateY.set(event.translationY);
    })
    .onEnd((event) => {
      translateX.set(withDecay({
        velocity: event.velocityX,
      }));
      translateY.set(withDecay({
        velocity: event.velocityY,
      }));
    });

const transform = useDerivedValue(() => [
    { translateX: translateX.value },
    { translateY: translateY.value },
  ]);

<Canvas>
 <Group transform={transform}>
  //content 
 </Group>
</Canvas>
SkiaStuttering.mov
@petrikjan petrikjan added the bug Something isn't working label Mar 4, 2025
@wcandillon
Copy link
Contributor

This looks very interesting, could provide the full standalone example? I will investigate it immediately.

@petrikjan
Copy link
Author

Hi, I’ll prepare a repository with the full code. The behavior is really strange. If you haven’t seen it yet, check out the discussion here: #3089
Thank you!!!

@petrikjan
Copy link
Author

Hi @wcandillon , I created two repositories with the same code but different versions of React Native and Skia. The legacy version uses Skia 1.9.0 and React Native 75 (old architecture). The other version uses the latest versions and the new architecture – however, the issue is the same even with the old architecture. Sorry for the lack of typing and the messy code, it was pulled from a complex project and I wanted to get it to you as quickly as possible. I'm also attaching videos that show what’s happening and that the legacy version runs great.

https://github.com/petrikjan/skia-grid
https://github.com/petrikjan/skia-grid-legacy

@wcandillon
Copy link
Contributor

@petrikjan I have to thank you for this example. I really actually quite small already. Is there any chance you could make it even smaller? for instance not using the paragraph API and showing squares instead shows the same issue. It would be good to try to make it as small as possible. I might spend some time to investigate it but anything you can do to this example to make it smaller (and you are not so far away from right now) would be tremendously helpful.

Now we do have examples where updates run both on the UI and JS thread simultaneous and and they run completely fine, not sure what is the different with your example yet but I will have a look.

@petrikjan
Copy link
Author

petrikjan commented Apr 15, 2025

Hi @wcandillon, Thank you! I removed most of the unnecessary stuff – last commit in skiaGrid. Is this okay like this? Anyway, the issue is still happening. You can try commenting out useAnimatedReaction. It won't actually fix it, but it will stop rendering new cells and rows, and then scrolling is mostly fine – probably because the content of memoized things isn't changing.

@petrikjan
Copy link
Author

Hi @wcandillon, please, did you manage to find out anything?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants