Skip to content

(cherry-pick) [Web LA] Adjust animation cleanup to slower devices - #8008

Merged
MatiPl01 merged 1 commit into
3.19-stablefrom
@matipl01/cherry-pick/web-la-fix
Aug 5, 2025
Merged

MatiPl01 merged 1 commit into
3.19-stablefrom
@matipl01/cherry-pick/web-la-fix

Conversation

@MatiPl01

@MatiPl01 MatiPl01 commented Aug 5, 2025

Copy link
Copy Markdown
Contributor

Cherry-pick of the #7933

## Summary

Turns out that on slower devices when animation lags, it can be removed
from DOM before it finishes. This results in callbacks not being called
and `dummy` being left instead of removed.

This PR:

1. Adjusts timeout value for slower devices,
2. Removes dummy elements when their animation is removed from DOM

## Test plan

<details>
<summary>Tested on the following code, with 20x throttling enabled in
chrome dev tools:</summary>

```jsx
import { useState } from 'react';
import { Button, View } from 'react-native';
import Animated, { Keyframe, Easing } from 'react-native-reanimated';

function Square() {
  const [visible, setVisible] = useState(false);

  const easing = Easing.bezier(0.76, 0.0, 0.24, 1.0).factory();
  const animation = new Keyframe({
    from: { transform: [{ translateX: '0%' }] },
    to: {
      transform: [{ translateX: '100%' }],
      easing,
    },
  });

  return (
    <View
      style={{
        padding: 20,
        flex: 1,
        flexDirection: 'row',
        alignItems: 'center',
      }}>
      <Button
        title="Toggle"
        onPress={() => setVisible((visible) => !visible)}
      />
      {visible && (
        <Animated.View
          style={{
            backgroundColor: 'red',
            width: 200,
            height: 200,
            flexDirection: 'row',
            flexWrap: 'wrap',
          }}
          exiting={animation
            .duration(300)
            .withCallback(() => console.log('callback!'))}>
          {Array(10000)
            .fill(0)
            .map((_, i) => (
              <View
                key={i}
                style={{ backgroundColor: 'yellow', width: 2, height: 2 }}
              />
            ))}
        </Animated.View>
      )}
    </View>
  );
}

export default function App() {
  return (
    <View style={{ flex: 1 }}>
      <Square />
    </View>
  );
}
```

</details>
@MatiPl01 MatiPl01 self-assigned this Aug 5, 2025
@MatiPl01 MatiPl01 mentioned this pull request Aug 5, 2025
10 tasks done
@MatiPl01
MatiPl01 requested a review from m-bert August 5, 2025 10:49
@MatiPl01
MatiPl01 merged commit 26dd3e9 into 3.19-stable Aug 5, 2025
@MatiPl01
MatiPl01 deleted the @matipl01/cherry-pick/web-la-fix branch August 5, 2025 12:30
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