diff --git a/squarenotsquare/src/components/Fade.js b/squarenotsquare/src/components/Fade.js new file mode 100644 index 0000000..250a78f --- /dev/null +++ b/squarenotsquare/src/components/Fade.js @@ -0,0 +1,39 @@ +import React from "react"; +import { Animated} from "react-native"; +import { useEffect, useRef } from "react"; + +function Fade(props){ + const faded = useRef(new Animated.Value(0.25)); + const opaque = useRef(new Animated.Value(1)); + + useEffect(() => { + if (props.faded) { + Animated.timing( + opaque.current, + { + toValue: 0.25, + duration: props.duration, + useNativeDriver: true + } + ).start(); + } else { + Animated.timing( + faded.current, + { + toValue: 1, + duration: props.duration, + useNativeDriver: true + } + ).start(); + } + }, [props.faded]) + + + return ( + + {props.children} + + ) +} + +export default Fade; \ No newline at end of file