mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
1import {useWindowDimensions} from 'react-native'
2import {useSafeAreaInsets} from 'react-native-safe-area-context'
3
4import {useBottomBarOffset} from '#/lib/hooks/useBottomBarOffset'
5
6const MIN_POST_HEIGHT = 100
7
8export function useInitialNumToRender({
9 minItemHeight = MIN_POST_HEIGHT,
10 screenHeightOffset = 0,
11}: {minItemHeight?: number; screenHeightOffset?: number} = {}) {
12 const {height: screenHeight} = useWindowDimensions()
13 const {top: topInset} = useSafeAreaInsets()
14 const bottomBarHeight = useBottomBarOffset()
15
16 const finalHeight =
17 screenHeight - screenHeightOffset - topInset - bottomBarHeight
18
19 const minItems = Math.floor(finalHeight / minItemHeight)
20 if (minItems < 1) {
21 return 1
22 }
23 return minItems
24}