diff --git a/app/(tabs)/index.tsx b/app/(tabs)/index.tsx index c18ef58..03ef8f2 100644 --- a/app/(tabs)/index.tsx +++ b/app/(tabs)/index.tsx @@ -24,6 +24,7 @@ import { useTranslation } from "react-i18next"; import { ActivityIndicator, FlatList, + RefreshControl, StyleSheet, TouchableOpacity, View, @@ -44,6 +45,7 @@ export default function HomeScreen() { const [leagues, setLeagues] = useState([]); const [matches, setMatches] = useState([]); const [loading, setLoading] = useState(true); + const [refreshing, setRefreshing] = useState(false); const [loadingLeagues, setLoadingLeagues] = useState(false); const [now, setNow] = useState(() => new Date()); const [liveLeagueIdByMatchId, setLiveLeagueIdByMatchId] = useState< @@ -321,8 +323,8 @@ export default function HomeScreen() { } }; - const loadMatches = async (sportId: number) => { - setLoading(true); + const loadMatches = async (sportId: number, isRefresh = false) => { + if (!isRefresh) setLoading(true); try { const res = await fetchTodayMatches({ sportId, @@ -441,10 +443,17 @@ export default function HomeScreen() { } catch (e) { console.error(e); } finally { - setLoading(false); + if (!isRefresh) setLoading(false); } }; + const onRefresh = async () => { + if (!selectedSportId) return; + setRefreshing(true); + await loadMatches(selectedSportId, true); + setRefreshing(false); + }; + const loadMoreMatches = async () => { if (loadingMore || loading) return; if (!selectedSportId) return; @@ -604,6 +613,9 @@ export default function HomeScreen() { renderItem={({ item }) => ( )} + refreshControl={ + + } onEndReached={loadMoreMatches} onEndReachedThreshold={0.4} ListFooterComponent={