about summary refs log tree commit diff
path: root/src/lib/hooks/useInitialNumToRender.ts
blob: 82bc89c0f88986e4685736bbadbb570c679a730e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
  return Math.floor(finalHeight / minItemHeight) + 1
}