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

added warning when animated component is rendered directly inside SafeAreaView #6052

Closed
wants to merge 3 commits into from

Conversation

exploIF
Copy link
Contributor

@exploIF exploIF commented May 27, 2024

Summary

Added warning log when animated component is rendered directly inside SafeAreaView from react-native or from react-native-safe-area-context. This should address maintainer issue here

Test plan

  1. Inside EmptyExample.tsx paste the code
import { StyleSheet, View, SafeAreaView as RNSafeAreaView } from 'react-native';
import React from 'react';
import Animated, { FadeIn } from 'react-native-reanimated';

const animation = FadeIn.delay(1000).duration(2000);

export default function EmptyExample() {
  return (
    <RNSafeAreaView>
      <View style={styles.greyBox} />
      <Animated.View entering={animation}>
        <View style={styles.redAnimatedBox} />
      </Animated.View>
    </RNSafeAreaView>
  );
}
const styles = StyleSheet.create({
  greyBox: {
    backgroundColor: 'grey',
    height: 100,
    width: '100%',
  },
  redAnimatedBox: {
    backgroundColor: 'red',
    height: 100,
    width: '100%',
  },
});
  1. This should throw a warning in your console:
Animated components shouldn't be rendered directly inside <SafeAreaView />, consider wrapping your content with additional <View />
  1. Apply changes below
import { StyleSheet, View, SafeAreaView as RNSafeAreaView } from 'react-native';
import React from 'react';
import Animated, { FadeIn } from 'react-native-reanimated';

const animation = FadeIn.delay(1000).duration(2000);

export default function EmptyExample() {
  return (
    <RNSafeAreaView>
+      <View>
        <View style={styles.greyBox} />
        <Animated.View entering={animation}>
          <View style={styles.redAnimatedBox} />
        </Animated.View>
+      </View>
    </RNSafeAreaView>
  );
}
const styles = StyleSheet.create({
  greyBox: {
    backgroundColor: 'grey',
    height: 100,
    width: '100%',
  },
  redAnimatedBox: {
    backgroundColor: 'red',
    height: 100,
    width: '100%',
  },
});
  1. Reload the app, there shouldn't be a warning message in the console.

@exploIF exploIF requested a review from piaskowyk May 27, 2024 15:13
@exploIF exploIF force-pushed the @exploIF/safe-area-view-error-log branch from aaa4ed6 to 1fc8c30 Compare May 27, 2024 15:15
Copy link
Contributor

@szydlovsky szydlovsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works well, nice 😄

@szydlovsky szydlovsky self-requested a review May 28, 2024 11:26
@piaskowyk
Copy link
Member

As we discussed offline, this issue is more generic than just the SafeAreaContext. We need to modify the implementation to cancel the animation and jump directly to the final position. A similar approach is already in place for Layout Animation for Fabric.
Solutions:

@piaskowyk piaskowyk closed this Jun 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants