I am trying to have some components fade in and out on mount and unmount using react-native-reanimated. I think the code is pretty simple:
import { View } from "react-native";
import Animated, { FadeIn, FadeOut } from "react-native-reanimated";
export const Dialog = () => (
<Animated.View
style={styles.loadingWrapper}
entering={FadeIn}
exiting={FadeOut}
>
<Progress.CircleSnail />
</Animated.View>
);
const App = () => {
const [isVisible, setIsVisible] = useState(false);
return (
<View>
{isVisible && <Dialog />}
<Button
title="Open Dialog"
onPress={() => setIsVisible(true)}
/>
</View>
);
}
My expectation here is that as the isVisible
prop changes, the Dialog
would fade in and out of existinence. What is happening is that it is popping in and out of existence, as if I were using a simple View
, not an Animated.View
.
I am unable to reproduce this issue in a snack. In the snack it seems to work fine. In my actual codebase, which is just a slightly more layered version of this, there is no animation. How might I be able to even begin debugging this?
This is the case for all instances of Animated.View
in my app. I had it working at some point, and then somewhere along the way, it stopped working. I'm not sure what changed. I am using an expo managed project. Here's the relevant parts of my package.json and versions:
{
"scripts": {
"start": "expo start",
"android": "expo start --android",
"ios": "expo start --ios",
"web": "expo start --web",
"eject": "expo eject"
},
"dependencies": {
"@expo/webpack-config": "~0.16.2",
"@gorhom/bottom-sheet": "^4.3.1",
"@react-native-async-storage/async-storage": "~1.17.6",
"@react-navigation/bottom-tabs": "^6.3.1",
"@react-navigation/drawer": "^6.4.1",
"@react-navigation/native": "^6.0.10",
"@react-navigation/native-stack": "^6.6.2",
"expo": "^45.0.4",
"expo-web-browser": "^10.2.1",
"react": "17.0.2",
"react-dom": "17.0.2",
"react-native": "0.68.2",
"react-native-dropdown-picker": "^5.4.2",
"react-native-gesture-handler": "~2.2.1",
"react-native-get-random-values": "~1.8.0",
"react-native-maps": "0.30.2",
"react-native-progress": "^5.0.0",
"react-native-reanimated": "~2.8.0",
"react-native-safe-area-context": "4.2.4",
"react-native-screens": "~3.11.1",
"react-native-svg": "12.3.0",
"react-native-web": "0.17.7",
"webpack-dev-server": "~3.11.0"
},
"devDependencies": {
"@babel/core": "^7.12.9",
"@types/react": "~17.0.21",
"@types/react-native": "~0.67.7",
"babel-plugin-inline-import": "^3.0.0",
"react-devtools": "^4.24.7",
"typescript": "~4.3.5"
},
}
And my babel config, as recommended by the install docs for react-native-reanimated:
module.exports = function (api) {
api.cache(true);
return {
presets: ["babel-preset-expo"],
plugins: [
[
"babel-plugin-inline-import",
{
extensions: [".svg"],
},
],
"react-native-reanimated/plugin",
],
};
};
Other libraries which rely on react-native-reanimated, like react-native-navigation, or react-native-bottomsheet, seem to be animating just fine. Am I doing something wrong? Did my packages get mismatched somewhere along the way and my animations stopped working all of a sudden?