Skip to content

Commit

Permalink
fix: useffect didnt trigger for the last one
Browse files Browse the repository at this point in the history
  • Loading branch information
YoanRos committed Aug 5, 2024
1 parent b103a31 commit 410d6d5
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions expo/src/components/CustomBootsplash.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useRef } from "react";
import React, { useEffect, useRef, useState } from "react";
import { Image, Dimensions, Animated, StyleSheet } from "react-native";
import { atom, useRecoilValue } from "recoil";

Expand All @@ -11,16 +11,21 @@ export const showBootSplashState = atom({
const CustomBootsplash = () => {
const showBootSplash = useRecoilValue(showBootSplashState);
const fadeAnim = useRef(new Animated.Value(0)).current;
const [animationComplete, setAnimationComplete] = useState(false);

useEffect(() => {
Animated.timing(fadeAnim, {
toValue: showBootSplash ? 1 : 0,
duration: 200,
useNativeDriver: true,
}).start();
}, [fadeAnim, showBootSplash]);
}).start(({ finished }) => {
if (finished) {
setAnimationComplete(!showBootSplash);
}
});
}, [showBootSplash]);

if (!showBootSplash && fadeAnim._value === 0) return null;
if (!showBootSplash && animationComplete) return null;

return (
<Animated.View style={[styles.fullScreen, { opacity: fadeAnim }]}>
Expand Down

0 comments on commit 410d6d5

Please sign in to comment.