diff --git a/.eslintrc.js b/.eslintrc.js index fefad92ce29d..98b4f4ff0fa2 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -3,7 +3,18 @@ const path = require('path'); const restrictedImportPaths = [ { name: 'react-native', - importNames: ['useWindowDimensions', 'StatusBar', 'TouchableOpacity', 'TouchableWithoutFeedback', 'TouchableNativeFeedback', 'TouchableHighlight', 'Pressable', 'Text', 'ScrollView'], + importNames: [ + 'useWindowDimensions', + 'StatusBar', + 'TouchableOpacity', + 'TouchableWithoutFeedback', + 'TouchableNativeFeedback', + 'TouchableHighlight', + 'Pressable', + 'Text', + 'ScrollView', + 'Animated', + ], message: [ '', "For 'useWindowDimensions', please use '@src/hooks/useWindowDimensions' instead.", @@ -11,6 +22,7 @@ const restrictedImportPaths = [ "For 'StatusBar', please use '@libs/StatusBar' instead.", "For 'Text', please use '@components/Text' instead.", "For 'ScrollView', please use '@components/ScrollView' instead.", + "For 'Animated', please use 'Animated' from 'react-native-reanimated' instead.", ].join('\n'), }, { diff --git a/contributingGuides/TS_CHEATSHEET.md b/contributingGuides/TS_CHEATSHEET.md index 77d316bb861d..e8c899a0aafb 100644 --- a/contributingGuides/TS_CHEATSHEET.md +++ b/contributingGuides/TS_CHEATSHEET.md @@ -101,22 +101,46 @@ - [1.4](#animated-style) **Animated styles** - ```ts - import {useRef} from 'react'; - import {Animated, StyleProp, ViewStyle} from 'react-native'; +The recommended approach to creating animations is by using the `react-native-reanimated` library, +as it offers greater efficiency and convenience compared to using the `Animated` API directly from +React Native. + ```ts + import React from 'react'; + import { View, StyleSheet, StyleProp, ViewStyle } from 'react-native'; + import Animated, { useAnimatedStyle, useSharedValue, withTiming, SharedValue, WithTimingConfig } from 'react-native-reanimated'; + type MyComponentProps = { - style?: Animated.WithAnimatedValue>; + opacity: Animated.SharedValue; + }; + + const MyComponent = ({ opacity }: MyComponentProps) => { + const animatedStyle = useAnimatedStyle(() => ({ + opacity: opacity.value, + })); + + return ( + + ); + }; + + const App = () => { + const opacity = useSharedValue(0); + + const startAnimation = () => { + opacity.value = withTiming(1, { + duration: 1000, + easing: Easing.inOut(Easing.quad), + }); + }; + + return ( + + +