From 52f82410541f9fe49bf14f641783ee0ac66fc3a6 Mon Sep 17 00:00:00 2001 From: Brandon Presley Date: Thu, 13 Oct 2022 16:30:02 +1300 Subject: [PATCH] Prevent flickering of empty lists on slow devices --- BestList.tsx | 25 +++++++++++++------------ PlanList.tsx | 27 ++++++++++++++------------- SetList.tsx | 27 ++++++++++++++------------- WorkoutList.tsx | 27 ++++++++++++++------------- 4 files changed, 55 insertions(+), 51 deletions(-) diff --git a/BestList.tsx b/BestList.tsx index 1133ad0..eef96b8 100644 --- a/BestList.tsx +++ b/BestList.tsx @@ -13,7 +13,7 @@ import Set from './set'; import {useSettings} from './use-settings'; export default function BestList() { - const [bests, setBests] = useState([]); + const [bests, setBests] = useState(); const [search, setSearch] = useState(''); const navigation = useNavigation>(); const {settings} = useSettings(); @@ -59,17 +59,18 @@ export default function BestList() { return ( - - } - renderItem={renderItem} - data={bests} - /> + {bests?.length === 0 ? ( + + ) : ( + + )} ); } diff --git a/PlanList.tsx b/PlanList.tsx index ccf3c1b..06d1561 100644 --- a/PlanList.tsx +++ b/PlanList.tsx @@ -15,7 +15,7 @@ import PlanItem from './PlanItem'; export default function PlanList() { const [search, setSearch] = useState(''); - const [plans, setPlans] = useState([]); + const [plans, setPlans] = useState(); const navigation = useNavigation>(); const refresh = useCallback(async () => { @@ -47,18 +47,19 @@ export default function PlanList() { return ( - set.id?.toString() || ''} - ListEmptyComponent={ - - } - /> + {plans?.length === 0 ? ( + + ) : ( + set.id?.toString() || ''} + /> + )} ); } diff --git a/SetList.tsx b/SetList.tsx index d6fadf0..55423c3 100644 --- a/SetList.tsx +++ b/SetList.tsx @@ -87,19 +87,20 @@ export default function SetList() { return ( - - } - renderItem={renderItem} - keyExtractor={s => s.id!.toString()} - onEndReached={next} - /> + {sets?.length === 0 ? ( + + ) : ( + s.id!.toString()} + onEndReached={next} + /> + )} ); } diff --git a/WorkoutList.tsx b/WorkoutList.tsx index 85bfadb..41dca82 100644 --- a/WorkoutList.tsx +++ b/WorkoutList.tsx @@ -80,19 +80,20 @@ export default function WorkoutList() { return ( - - } - renderItem={renderItem} - keyExtractor={w => w.name} - onEndReached={next} - /> + {workouts?.length === 0 ? ( + + ) : ( + w.name} + onEndReached={next} + /> + )} ); }