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

useAnimatedStyle does not support hsl(x y% z%) syntax for colors #5746

Open
tomekzaw opened this issue Feb 28, 2024 · 2 comments · May be fixed by #5825
Open

useAnimatedStyle does not support hsl(x y% z%) syntax for colors #5746

tomekzaw opened this issue Feb 28, 2024 · 2 comments · May be fixed by #5825
Labels
Maintainer issue Issue created by a maintainer

Comments

@tomekzaw
Copy link
Member

Description

When using hsl(x y% z%) syntax for background color in animated style, the color is not updated.

Steps to reproduce

import { StyleSheet, View } from 'react-native';

import Animated, {
  useAnimatedStyle,
  useSharedValue,
  withRepeat,
  withTiming,
} from 'react-native-reanimated';
import React, { useEffect } from 'react';

export default function EmptyExample() {
  const sv = useSharedValue(0);

  useEffect(() => {
    sv.value = withRepeat(withTiming(1, { duration: 1000 }), -1, true);
    return () => {
      sv.value = 0;
    };
  }, [sv]);

  const animatedStyle = useAnimatedStyle(() => {
    return {
      backgroundColor: `hsl(${sv.value * 180} 100% 50%)`,
    };
  });

  return (
    <View style={styles.container}>
      <Animated.View style={[styles.box, animatedStyle]} />
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    alignItems: 'center',
    justifyContent: 'center',
  },
  box: {
    width: 100,
    height: 100,
  },
});

Snack or a link to a repository

nope

Reanimated version

3.7.1

React Native version

0.73.4

Platforms

Android, iOS

JavaScript runtime

Hermes

Workflow

React Native

Architecture

Paper (Old Architecture)

Build type

Debug app & dev bundle

Device

iOS simulator

Device model

iPhone 15 Pro

Acknowledgements

Yes

@github-actions github-actions bot added Platform: Android This issue is specific to Android Platform: iOS This issue is specific to iOS Missing repro This issue need minimum repro scenario labels Feb 28, 2024
Copy link

Hey! 👋

The issue doesn't seem to contain a minimal reproduction.

Could you provide a snack or a link to a GitHub repository under your username that reproduces the problem?

@tomekzaw
Copy link
Member Author

Workaround

Add commas (,) between HSL components.

   const animatedStyle = useAnimatedStyle(() => {
     return {
-      backgroundColor: `hsl(${sv.value * 180} 100% 50%)`,
+      backgroundColor: `hsl(${sv.value * 180}, 100%, 50%)`,
     };
   });
``

@tomekzaw tomekzaw added Maintainer issue Issue created by a maintainer and removed Missing repro This issue need minimum repro scenario Platform: Android This issue is specific to Android Platform: iOS This issue is specific to iOS labels Feb 28, 2024
@maciekstosio maciekstosio linked a pull request Mar 22, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Maintainer issue Issue created by a maintainer
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant