diff --git a/app/App.tsx b/app/App.tsx index 027096d..41b7155 100644 --- a/app/App.tsx +++ b/app/App.tsx @@ -1,10 +1,11 @@ -import React, { useState, useEffect } from "react"; +import React, { useState, useEffect, useRef } from "react"; import { Text, View, Image, TouchableWithoutFeedback, StyleSheet, + Animated, } from "react-native"; import * as ImageManipulator from "expo-image-manipulator"; import { Camera } from "expo-camera"; @@ -48,6 +49,7 @@ export default function App() { const [pressed, setPressed] = useState(false); const [pasting, setPasting] = useState(false); + const fadeAnim = useRef(new Animated.Value(1)).current; let camera: any = null; @@ -62,6 +64,16 @@ export default function App() { })(); }, []); + const fadeOut = () => { + Animated.timing(fadeAnim, { + toValue: 0, + duration: 1000, + }).start(({ finished }) => { + setState({ ...state, currImgSrc: "" }); + fadeAnim.setValue(1); + }); + }; + async function cut(): Promise { const start = Date.now(); console.log(""); @@ -146,10 +158,10 @@ export default function App() { async function onPressOut() { setPressed(false); setPasting(true); + fadeOut(); if (state.currImgSrc !== "") { await paste(); - setState({ ...state, currImgSrc: "" }); setPasting(false); } } @@ -190,19 +202,24 @@ export default function App() { - {pressed && state.currImgSrc !== "" ? ( + {state.currImgSrc !== "" ? ( <> - + - + ) : null} - {(pressed && state.currImgSrc === "") || pasting ? : null} + {(pressed && state.currImgSrc === "") || pasting ? ( + + ) : null} ); }