From d5ac30b6d87c0d9848ab40dd36127432a15561a4 Mon Sep 17 00:00:00 2001 From: Fredrik Burmester Date: Sat, 22 Feb 2025 13:20:52 +0100 Subject: [PATCH] feat: scroll to top on tab home press --- components/settings/HomeIndex.tsx | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/components/settings/HomeIndex.tsx b/components/settings/HomeIndex.tsx index 44eebc27..565d1d58 100644 --- a/components/settings/HomeIndex.tsx +++ b/components/settings/HomeIndex.tsx @@ -9,6 +9,7 @@ import { useInvalidatePlaybackProgressCache } from "@/hooks/useRevalidatePlaybac import { useDownload } from "@/providers/DownloadProvider"; import { apiAtom, userAtom } from "@/providers/JellyfinProvider"; import { useSettings } from "@/utils/atoms/settings"; +import { eventBus } from "@/utils/eventBus"; import { Feather, Ionicons } from "@expo/vector-icons"; import { Api } from "@jellyfin/sdk"; import { @@ -26,7 +27,7 @@ import NetInfo from "@react-native-community/netinfo"; import { QueryFunction, useQuery } from "@tanstack/react-query"; import { useNavigation, useRouter } from "expo-router"; import { useAtomValue } from "jotai"; -import { useCallback, useEffect, useMemo, useState } from "react"; +import { useCallback, useEffect, useMemo, useRef, useState } from "react"; import { useTranslation } from "react-i18next"; import { ActivityIndicator, @@ -77,6 +78,8 @@ export const HomeIndex = () => { const insets = useSafeAreaInsets(); + const scrollViewRef = useRef(null); + const { downloadedFiles, cleanCacheDirectory } = useDownload(); useEffect(() => { const hasDownloads = downloadedFiles && downloadedFiles.length > 0; @@ -104,6 +107,16 @@ export const HomeIndex = () => { ); }, []); + useEffect(() => { + const unsubscribe = eventBus.on("scrollToTop", () => { + scrollViewRef.current?.scrollTo({ y: -152, animated: true }); + }); + + return () => { + unsubscribe(); + }; + }, []); + const checkConnection = useCallback(async () => { setLoadingRetry(true); const state = await NetInfo.fetch(); @@ -415,6 +428,8 @@ export const HomeIndex = () => { return (