From 1879c7c1f7a6578022499a15ed1ed718ff4c84bd Mon Sep 17 00:00:00 2001 From: Chris Sanden Date: Wed, 22 Apr 2026 20:41:19 +0200 Subject: [PATCH] Added placeholder task info and made some UI/UX improvements --- app/(tabs)/timer.tsx | 110 +++++++++++++++++++++++++++++++------------ 1 file changed, 79 insertions(+), 31 deletions(-) diff --git a/app/(tabs)/timer.tsx b/app/(tabs)/timer.tsx index 20d94f1..fceb963 100644 --- a/app/(tabs)/timer.tsx +++ b/app/(tabs)/timer.tsx @@ -19,32 +19,55 @@ const colors = { const timers = [...Array(13).keys()].map((i) => (i === 0 ? 1 : i * 5)); const ITEM_SIZE = width * 0.38; const ITEM_SPACING = (width - ITEM_SIZE) / 2; +const TIMER_UNIT_IN_SECONDS = 1; // Set to 60 for timer value to represent minutes const placeholderTask = { name: 'Read chapter 4', description: 'Focus on the summary questions and write down anything unclear.', }; -/* -Har bare skrevet timeren som en egen tab til å begynne med. -Planen er at når bruker starter en task så vil de få opp denne timeren -som viser TaskName og Description der tallene står nå -Kanskje en animert figur hvis vi får tid -*/ +function formatTime(totalSeconds: number) { + const minutes = Math.floor(totalSeconds / 60); + const seconds = totalSeconds % 60; + + return `${minutes.toString().padStart(2, '0')}:${ + seconds.toString().padStart(2, '0')}`; +} + export default function App() { const [containerHeight, setContainerHeight] = React.useState(0) - const scrollX = React.useRef(new Animated.Value(0)).current; const [duration, setDuration] = React.useState(timers[0]) const [isRunning, setIsRunning] = React.useState(false) + const [timeRemaining, setTimeRemaining] = React.useState(0) + const [selectedIndex, setSelectedIndex] = React.useState(0) + const [showCountdownText, setShowCountdownText] = React.useState(false) + const scrollX = React.useRef(new Animated.Value(0)).current; const timerAnimation = React.useRef(new Animated.Value(0)).current const buttonAnimation = React.useRef(new Animated.Value(0)).current const taskDetailsAnimation = React.useRef(new Animated.Value(0)).current + const countdownAnimation = React.useRef(new Animated.Value(0)).current + const animation = React.useCallback(() => { - if (isRunning) { + if (isRunning || containerHeight === 0) { return; } setIsRunning(true); + setShowCountdownText(true); taskDetailsAnimation.setValue(0); + countdownAnimation.setValue(0); + + const totalSeconds = duration * TIMER_UNIT_IN_SECONDS; + setTimeRemaining(totalSeconds); + + const countdown = setInterval(() => { + setTimeRemaining((currentTime) => { + if (currentTime <= 1) { + clearInterval(countdown) + return 0; + } + return currentTime -1; + }); + }, 1000); Animated.sequence([ Animated.parallel([ @@ -58,6 +81,11 @@ export default function App() { duration: 500, useNativeDriver: true }), + Animated.timing(countdownAnimation, { + toValue: 1, + duration: 300, + useNativeDriver: true + }), ]), Animated.timing(timerAnimation, { toValue: 0, @@ -66,37 +94,45 @@ export default function App() { }), Animated.timing(timerAnimation, { toValue: containerHeight, - duration: duration * 1000, + duration: totalSeconds * 1000, useNativeDriver: true - }), - ]) .start(({ finished }) => { + }) + ]).start(({ finished }) => { if (!finished) { setIsRunning(false); return; } + Animated.timing(countdownAnimation, { + toValue: 0, + duration: 200, + useNativeDriver: true + }).start(() => { + setShowCountdownText(false); + Animated.parallel([ - Animated.timing(buttonAnimation, { - toValue: 0, - duration: 300, - useNativeDriver: true - }), - Animated.timing(taskDetailsAnimation, { - toValue: 0, - duration: 300, - useNativeDriver: true - }), - ]).start(() => { - setIsRunning(false); - }) + Animated.timing(buttonAnimation, { + toValue: 0, + duration: 300, + useNativeDriver: true + }), + Animated.timing(taskDetailsAnimation, { + toValue: 0, + duration: 300, + useNativeDriver: true + }), + ]).start(() => { + setIsRunning(false); + }) }) - }, [buttonAnimation, duration, isRunning, taskDetailsAnimation, timerAnimation]) + }) +}, [countdownAnimation, buttonAnimation, containerHeight, duration, isRunning, taskDetailsAnimation, timerAnimation]) React.useEffect(() => { - if (containerHeight > 0) { + if (containerHeight > 0 && !isRunning) { timerAnimation.setValue(containerHeight); } - }) + }, [containerHeight, isRunning, timerAnimation]) const opacity = buttonAnimation.interpolate({ inputRange: [0, 1], @@ -127,7 +163,7 @@ return (