From e3baa2f58ba331f635efc3c83d0b54ef251a90fb Mon Sep 17 00:00:00 2001 From: Fredrik Burmester Date: Thu, 10 Oct 2024 17:27:17 +0200 Subject: [PATCH] fix: rotation issues --- app/(auth)/(tabs)/(libraries)/[libraryId].tsx | 31 ++++++++++--------- app/(auth)/play-video.tsx | 14 +++++++-- 2 files changed, 29 insertions(+), 16 deletions(-) diff --git a/app/(auth)/(tabs)/(libraries)/[libraryId].tsx b/app/(auth)/(tabs)/(libraries)/[libraryId].tsx index f2439409..1f345a0a 100644 --- a/app/(auth)/(tabs)/(libraries)/[libraryId].tsx +++ b/app/(auth)/(tabs)/(libraries)/[libraryId].tsx @@ -32,7 +32,6 @@ import { tagsFilterAtom, yearFilterAtom, } from "@/utils/atoms/filters"; -import { orientationAtom } from "@/utils/atoms/orientation"; import { BaseItemDto, BaseItemDtoQueryResult, @@ -44,6 +43,7 @@ import { } from "@jellyfin/sdk/lib/utils/api"; import { FlashList } from "@shopify/flash-list"; import { useSafeAreaInsets } from "react-native-safe-area-context"; +import { useOrientation } from "@/hooks/useOrientation"; const MemoizedTouchableItemRouter = React.memo(TouchableItemRouter); @@ -60,12 +60,13 @@ const Page = () => { const [selectedTags, setSelectedTags] = useAtom(tagsFilterAtom); const [sortBy, _setSortBy] = useAtom(sortByAtom); const [sortOrder, _setSortOrder] = useAtom(sortOrderAtom); - const [orientation] = useAtom(orientationAtom); const [sortByPreference, setSortByPreference] = useAtom(sortByPreferenceAtom); const [sortOrderPreference, setOderByPreference] = useAtom( sortOrderPreferenceAtom ); + const { orientation } = useOrientation(); + useEffect(() => { const sop = getSortOrderPreference(libraryId, sortOrderPreference); if (sop) { @@ -106,11 +107,12 @@ const Page = () => { [libraryId, sortOrderPreference] ); - const getNumberOfColumns = useCallback(() => { - if (orientation === ScreenOrientation.Orientation.PORTRAIT_UP) return 3; - if (screenWidth < 600) return 5; - if (screenWidth < 960) return 6; - if (screenWidth < 1280) return 7; + const nrOfCols = useMemo(() => { + if (screenWidth < 300) return 2; + if (screenWidth < 500) return 3; + if (screenWidth < 800) return 5; + if (screenWidth < 1000) return 6; + if (screenWidth < 1500) return 7; return 6; }, [screenWidth, orientation]); @@ -219,7 +221,7 @@ const Page = () => { const renderItem = useCallback( ({ item, index }: { item: BaseItemDto; index: number }) => ( - { { - + ), [orientation] ); @@ -429,6 +431,7 @@ const Page = () => { return ( No results @@ -437,10 +440,10 @@ const Page = () => { contentInsetAdjustmentBehavior="automatic" data={flatData} renderItem={renderItem} - extraData={orientation} + extraData={[orientation, nrOfCols]} keyExtractor={keyExtractor} estimatedItemSize={244} - numColumns={getNumberOfColumns()} + numColumns={nrOfCols} onEndReached={() => { if (hasNextPage) { fetchNextPage(); diff --git a/app/(auth)/play-video.tsx b/app/(auth)/play-video.tsx index fc2378a2..59ef2733 100644 --- a/app/(auth)/play-video.tsx +++ b/app/(auth)/play-video.tsx @@ -214,18 +214,28 @@ export default function page() { return (