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

React style not correctly applied when removing reanimated style #6681

Open
freeboub opened this issue Nov 9, 2024 · 1 comment
Open

React style not correctly applied when removing reanimated style #6681

freeboub opened this issue Nov 9, 2024 · 1 comment
Labels
Platform: Android This issue is specific to Android Repro provided A reproduction with a snippet of code, snack or repo is provided

Comments

@freeboub
Copy link

freeboub commented Nov 9, 2024

Description

When you have an Animated.View which use a react style and reanimated style, If you remove the reanimated style, the react style is not correctly reapplied.

Steps to reproduce

make an animation on view. and remove the reanimated style.
Once the reanimated style is removed, we expect that the regular style is applied:

        style={[
          { width: 1, height: 80, backgroundColor: "black", margin: 30 },
          visible ? style : undefined,
        ]}

Here I animated width, once visible goes to false I expect the width to be 1. But correctly the behavior inconsistent.
I made a sample with width, but we also see this issue on opacity or color for a text.
Of course there are easy workaround which can be implemented, but it is painful to identify and correct...

Adtionnal informations:

  • Seen with or without newArchitecture
  • Seen on ios and android (tested only on emulators)

even if ios have the same issue, I think on android with an uggly glitch when we remove the style, I don't see that on ios ...

Full code to reproduce the issue:

  const width = useSharedValue(10);

  const config = {
    duration: 1000,
    easing: Easing.linear,
  };
  useEffect(() => {
    width.value = withRepeat(withTiming(350, config), 10000)
  }, [])

  const style = useAnimatedStyle(() => {
    return {
      width: width.value,
    };
  });

  const [visible, setStyleVisible] = useState(false)

  console.log('is visible', visible)
  return (
    <View
      style={{
        flex: 1,
        alignItems: "center",
        justifyContent: "center",
        flexDirection: "column",
      }}
    >
      <Animated.View
        style={[
          { width: 1, height: 80, backgroundColor: "black", margin: 30 },
          visible ? style : undefined,
        ]}
      />
      <Button
        title="toggle"
        onPress={() => {
          console.log('toggle')
          setStyleVisible(v => !v)
        }}
      />
    </View>
  );

Snack or a link to a repository

https://github.com/freeboub/bug-reanimated-style

Reanimated version

3.16.1

React Native version

expo 51.0.38 (react-native 0.74.5) also reproduced on 0.76.1

Platforms

Android

JavaScript runtime

Hermes

Workflow

React Native

Architecture

Fabric (New Architecture)

Build type

Debug app & dev bundle

Device

Android emulator

Device model

No response

Acknowledgements

Yes

@github-actions github-actions bot added Platform: Android This issue is specific to Android Repro provided A reproduction with a snippet of code, snack or repo is provided labels Nov 9, 2024
@freeboub
Copy link
Author

freeboub commented Nov 9, 2024

I didn't test on ios when I open the issue, can you please add the "Plaform: ios" tag ?

@freeboub freeboub changed the title react style not correctly applied when removing reanimated style React style not correctly applied when removing reanimated style Nov 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Platform: Android This issue is specific to Android Repro provided A reproduction with a snippet of code, snack or repo is provided
Projects
None yet
Development

No branches or pull requests

1 participant