From 070429627bda53b4318aa56697d219d483c7f30e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zo=C3=AB?= Date: Tue, 11 Aug 2026 16:48:01 +0200 Subject: [PATCH] fix(workout-builder): defer TextInput updates to onBlur using local state --- .../workout-builder/screens/BuilderScreen.tsx | 46 ++++++++++++++++--- 1 file changed, 40 insertions(+), 6 deletions(-) diff --git a/src/features/workout-builder/screens/BuilderScreen.tsx b/src/features/workout-builder/screens/BuilderScreen.tsx index c4db5fc..d719e32 100644 --- a/src/features/workout-builder/screens/BuilderScreen.tsx +++ b/src/features/workout-builder/screens/BuilderScreen.tsx @@ -16,6 +16,7 @@ export function BuilderScreen() { const navigation = useNavigation>(); const { poolLength: defaultPoolLength } = useSettings(); const [poolLength, setPoolLength] = useState(defaultPoolLength); + const [fieldValues, setFieldValues] = useState>({}); const { sets, workoutName, @@ -124,8 +125,19 @@ export function BuilderScreen() { {t("distanceM")} updateSet(index, { distancePerRep: Number(val) || 0 })} + value={fieldValues[`${index}-distance`] ?? String(set.distancePerRep)} + onChangeText={(val) => setFieldValues((prev) => ({ ...prev, [`${index}-distance`]: val }))} + onBlur={() => { + const num = Number(fieldValues[`${index}-distance`] ?? set.distancePerRep); + updateSet(index, { distancePerRep: isNaN(num) || num < poolLength ? poolLength : num }); + setFieldValues((prev) => { + const next = { ...prev }; + delete next[`${index}-distance`]; + return next; + }); + }} + placeholder={String(poolLength)} + placeholderTextColor="#94a3b8" className="bg-white border border-slate-300 rounded-lg px-3 py-2 text-slate-900" /> @@ -133,8 +145,19 @@ export function BuilderScreen() { {t("reps")} updateSet(index, { repCount: Number(val) || 1 })} + value={fieldValues[`${index}-rep`] ?? String(set.repCount)} + onChangeText={(val) => setFieldValues((prev) => ({ ...prev, [`${index}-rep`]: val }))} + onBlur={() => { + const num = Number(fieldValues[`${index}-rep`] ?? set.repCount); + updateSet(index, { repCount: isNaN(num) || num < 1 ? 1 : num }); + setFieldValues((prev) => { + const next = { ...prev }; + delete next[`${index}-rep`]; + return next; + }); + }} + placeholder="1" + placeholderTextColor="#94a3b8" className="bg-white border border-slate-300 rounded-lg px-3 py-2 text-slate-900" /> @@ -142,8 +165,19 @@ export function BuilderScreen() { {t("restS")} updateSet(index, { restDuration: Number(val) || 0 })} + value={fieldValues[`${index}-rest`] ?? String(set.restDuration)} + onChangeText={(val) => setFieldValues((prev) => ({ ...prev, [`${index}-rest`]: val }))} + onBlur={() => { + const num = Number(fieldValues[`${index}-rest`] ?? set.restDuration); + updateSet(index, { restDuration: isNaN(num) || num < 0 ? 0 : num }); + setFieldValues((prev) => { + const next = { ...prev }; + delete next[`${index}-rest`]; + return next; + }); + }} + placeholder="0" + placeholderTextColor="#94a3b8" className="bg-white border border-slate-300 rounded-lg px-3 py-2 text-slate-900" />