Profile screen performance tweak - Adjust initial num to render based on header height (#5005)

This commit is contained in:
Hailey 2024-08-29 09:09:24 -07:00 committed by GitHub
parent ea5ab99399
commit e33b88ed7d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 27 additions and 11 deletions

View file

@ -1,11 +1,19 @@
import React from 'react'
import {Dimensions} from 'react-native'
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: number = MIN_POST_HEIGHT) {
return React.useMemo(() => {
const screenHeight = Dimensions.get('window').height
return Math.ceil(screenHeight / minItemHeight) + 1
}, [minItemHeight])
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
}