Files
bsky-social-app/src/lib/hooks/useInitialNumToRender.ts
T
dan a22685c345 Sort imports (#6009)
* Mark import sort/order/style rules as error

* npm run lint -- --fix
2024-10-29 23:02:48 +00:00

25 lines
734 B
TypeScript

import {useWindowDimensions} from 'react-native'
import {useSafeAreaInsets} from 'react-native-safe-area-context'
import {useBottomBarOffset} from '#/lib/hooks/useBottomBarOffset'
const MIN_POST_HEIGHT = 100
export function useInitialNumToRender({
minItemHeight = MIN_POST_HEIGHT,
screenHeightOffset = 0,
}: {minItemHeight?: number; screenHeightOffset?: number} = {}) {
const {height: screenHeight} = useWindowDimensions()
const {top: topInset} = useSafeAreaInsets()
const bottomBarHeight = useBottomBarOffset()
const finalHeight =
screenHeight - screenHeightOffset - topInset - bottomBarHeight
const minItems = Math.floor(finalHeight / minItemHeight)
if (minItems < 1) {
return 1
}
return minItems
}