Skip to content

Handle component internal animated ref #7054

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
merged 2 commits into from
Feb 20, 2025

Conversation

piaskowyk
Copy link
Member

@piaskowyk piaskowyk commented Feb 19, 2025

Summary

A reference provided by the component via getAnimatableRef() should always take precedence over a reference received through _setLocalRef()

Fixes expo/expo#32781

before after
before.mov
after.mov

Test plan

Based on repro: https://github.com/jakex7/expo-32781

code
import { BlurView } from "expo-blur";
import React, { useEffect } from "react";
import { Image, StyleSheet, Text, View } from "react-native";
import Animated, {
  useAnimatedProps,
  useSharedValue,
  withRepeat,
  withTiming,
} from "react-native-reanimated";

Animated.addWhitelistedNativeProps({ intensity: true });
const AnimatedBlurView = Animated.createAnimatedComponent(BlurView);

export default function Test() {
  const animatedIntensity = useSharedValue<number | undefined>(0);

  useEffect(() => {
    animatedIntensity.value = withRepeat(
      withTiming(100, { duration: 2000 }),
      -1,
      true
      );
  }, []);

  return (
    <View style={styles.container}>
      <View style={styles.innerContainer}>
        <Image
          style={styles.image}
          source={{ uri: "https://source.unsplash.com/300x300" }}
        />
        <Text style={styles.blurredText}>This text is blurred</Text>

        <AnimatedBlurView
          style={styles.blurView}
          tint={"dark"}
          intensity={animatedIntensity}
        >
          <Text style={styles.nonBlurredText}>text</Text>
        </AnimatedBlurView>
      </View>
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    alignItems: "center",
    justifyContent: "center",
    padding: 6,
  },
  innerContainer: {
    alignItems: "center",
    justifyContent: "center",
  },
  image: {
    width: 250,
    height: 250,
  },
  blurredText: {
    position: "absolute",
    padding: 10,
    backgroundColor: "rgb(120,20,20)",
    color: "white",
    fontWeight: "bold",
    fontSize: 20,
    borderRadius: 5,
  },
  blurView: {
    ...StyleSheet.absoluteFillObject,
    alignItems: "center",
    paddingTop: 20,
  },
  nonBlurredText: {
    paddingHorizontal: 10,
    paddingVertical: 4,
    backgroundColor: "rgb(120,20,20)",
    color: "white",
    fontWeight: "bold",
    fontSize: 18,
  },
});

@piaskowyk piaskowyk marked this pull request as ready for review February 19, 2025 15:08
@piaskowyk piaskowyk requested a review from tjzel February 19, 2025 15:08
@piaskowyk piaskowyk added this pull request to the merge queue Feb 20, 2025
Merged via the queue into main with commit 23fadf2 Feb 20, 2025
9 checks passed
@piaskowyk piaskowyk deleted the @piaskowyk/internal-ref-handling branch February 20, 2025 09:42
tjzel pushed a commit that referenced this pull request Feb 20, 2025
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.

Expo52: Can not animate BlurView intensity with reanimated
2 participants