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

Props are not updated on custom animated component #6911

Open
jakex7 opened this issue Jan 20, 2025 · 1 comment
Open

Props are not updated on custom animated component #6911

jakex7 opened this issue Jan 20, 2025 · 1 comment
Labels
Platform: iOS This issue is specific to iOS Repro provided A reproduction with a snippet of code, snack or repo is provided

Comments

@jakex7
Copy link
Member

jakex7 commented Jan 20, 2025

Description

I built an animated view using Animated.createAnimatedComponent and passed an angle prop animation via useAnimatedProps. However, the view wasn't updating the prop through the shadow tree. To make it work, I needed to include zIndex: 1. Here's a sample code snippet:

import { ConicGradientView } from "expo-conic-gradient";
import { useEffect } from "react";
import { View } from "react-native";
import Animated, {
  Easing,
  useAnimatedProps,
  useSharedValue,
  withRepeat,
  withTiming,
} from "react-native-reanimated";

const AnimatedConicGradient =
  Animated.createAnimatedComponent(ConicGradientView);
export default () => {
  const value = useSharedValue(0);

  useEffect(() => {
    value.value = withRepeat(
      withTiming(360, { duration: 5000, easing: Easing.linear }),
      -1,
      false
    );
  }, [value]);

  const conic = useAnimatedProps(() => {
    return {
      angle: value.value,
      // working workaround with zIndex
      // zIndex: 1,
    };
  });

  return (
    <View style={{ flex: 1, justifyContent: "center", alignItems: "center" }}>
      <AnimatedConicGradient
        colors={["red", "orange", "yellow", "green", "blue", "purple", "red"]}
        animatedProps={conic}
        style={{ width: 200, height: 200 }}
      />
    </View>
  );
};

Steps to reproduce

  1. Clone expo-conic-gradient and checkout to branch reanimated-bug-repro
  2. Run npm install in the root folder and run example app on iOS
  3. Conic gradient angle is not updated
  4. Uncomment zIndex: 1 in example/App.tsx to see workaround

Snack or a link to a repository

https://github.com/jakex7/expo-conic-gradient/tree/reanimated-bug-repro

Reanimated version

3.16.7

React Native version

0.76.6

Platforms

iOS

JavaScript runtime

Hermes

Workflow

Expo Dev Client

Architecture

Fabric (New Architecture)

Build type

Debug app & dev bundle

Device

iOS simulator

Device model

No response

Acknowledgements

Yes

@github-actions github-actions bot added Repro provided A reproduction with a snippet of code, snack or repo is provided Platform: iOS This issue is specific to iOS labels Jan 20, 2025
@ariva85
Copy link

ariva85 commented Jan 22, 2025

I have a similar issue but on android, the issue appears on v 3.16.0, works fine in 3.15.5 and below

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

No branches or pull requests

2 participants