From 84ff8a110b1519e0fab213d2469ca9d060063a25 Mon Sep 17 00:00:00 2001 From: Brandon Presley Date: Sun, 12 Nov 2023 23:36:22 +1300 Subject: [PATCH] =?UTF-8?q?Improve=20responsiveness=20of=20timer=20page=20?= =?UTF-8?q?-=201.180=20=F0=9F=9A=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TimerPage.tsx | 4 +++- android/app/build.gradle | 4 ++-- package.json | 2 +- use-timer.ts | 28 ++++++++++++++++------------ 4 files changed, 22 insertions(+), 16 deletions(-) diff --git a/TimerPage.tsx b/TimerPage.tsx index c9c7634..1accf5b 100644 --- a/TimerPage.tsx +++ b/TimerPage.tsx @@ -17,7 +17,7 @@ export interface TickEvent { } export default function TimerPage() { - const { minutes, seconds } = useTimer(); + const { minutes, seconds, update } = useTimer(); const [settings, setSettings] = useState(); const { colors } = useTheme(); @@ -29,11 +29,13 @@ export default function TimerPage() { const stop = () => { NativeModules.AlarmModule.stop(); + update(); }; const add = async () => { console.log(`${TimerPage.name}.add:`, settings); NativeModules.AlarmModule.add(); + update(); }; const progress = useMemo(() => { diff --git a/android/app/build.gradle b/android/app/build.gradle index d90fecf..04211ea 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -85,8 +85,8 @@ android { applicationId "com.massive" minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion - versionCode 36205 - versionName "1.179" + versionCode 36206 + versionName "1.180" } signingConfigs { release { diff --git a/package.json b/package.json index f4d8b30..8d89f31 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "massive", - "version": "1.179", + "version": "1.180", "private": true, "license": "GPL-3.0-only", "scripts": { diff --git a/use-timer.ts b/use-timer.ts index 1394bde..5d3be71 100644 --- a/use-timer.ts +++ b/use-timer.ts @@ -8,19 +8,23 @@ export default function useTimer() { const [minutes, setMinutes] = useState("00"); const [seconds, setSeconds] = useState("00"); + const update = () => { + const current: number = NativeModules.AlarmModule.getCurrent(); + setMinutes( + Math.floor(current / 1000 / 60) + .toString() + .padStart(2, "0") + ); + setSeconds( + Math.floor((current / 1000) % 60) + .toString() + .padStart(2, "0") + ); + }; + useFocusEffect( useCallback(() => { - const current: number = NativeModules.AlarmModule.getCurrent(); - setMinutes( - Math.floor(current / 1000 / 60) - .toString() - .padStart(2, "0") - ); - setSeconds( - Math.floor((current / 1000) % 60) - .toString() - .padStart(2, "0") - ); + update(); const listener = emitter.addListener("tick", (event: TickEvent) => { console.log(`${useTimer.name}.tick:`, { event }); setMinutes(event.minutes); @@ -30,5 +34,5 @@ export default function useTimer() { }, []) ); - return { minutes, seconds }; + return { minutes, seconds, update }; }