about summary refs log tree commit diff
path: root/src/lib/hooks/useInitialNumToRender.ts
diff options
context:
space:
mode:
authorHailey <me@haileyok.com>2024-08-29 09:09:24 -0700
committerGitHub <noreply@github.com>2024-08-29 09:09:24 -0700
commite33b88ed7df4eeb6356e50e7d8494b24b31973d0 (patch)
treea0a39f6ae537faef41497812b80b60a4d0277e4a /src/lib/hooks/useInitialNumToRender.ts
parentea5ab993993280b7c9fc03c25be658f11369df4d (diff)
downloadvoidsky-e33b88ed7df4eeb6356e50e7d8494b24b31973d0.tar.zst
Profile screen performance tweak - Adjust initial num to render based on header height (#5005)
Diffstat (limited to 'src/lib/hooks/useInitialNumToRender.ts')
-rw-r--r--src/lib/hooks/useInitialNumToRender.ts22
1 files changed, 15 insertions, 7 deletions
diff --git a/src/lib/hooks/useInitialNumToRender.ts b/src/lib/hooks/useInitialNumToRender.ts
index 942f0404a..82bc89c0f 100644
--- a/src/lib/hooks/useInitialNumToRender.ts
+++ b/src/lib/hooks/useInitialNumToRender.ts
@@ -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
 }