Profile screen performance tweak - Adjust initial num to render based on header height (#5005)
parent
ea5ab99399
commit
e33b88ed7d
|
@ -1,11 +1,19 @@
|
||||||
import React from 'react'
|
import {useWindowDimensions} from 'react-native'
|
||||||
import {Dimensions} from 'react-native'
|
import {useSafeAreaInsets} from 'react-native-safe-area-context'
|
||||||
|
|
||||||
|
import {useBottomBarOffset} from 'lib/hooks/useBottomBarOffset'
|
||||||
|
|
||||||
const MIN_POST_HEIGHT = 100
|
const MIN_POST_HEIGHT = 100
|
||||||
|
|
||||||
export function useInitialNumToRender(minItemHeight: number = MIN_POST_HEIGHT) {
|
export function useInitialNumToRender({
|
||||||
return React.useMemo(() => {
|
minItemHeight = MIN_POST_HEIGHT,
|
||||||
const screenHeight = Dimensions.get('window').height
|
screenHeightOffset = 0,
|
||||||
return Math.ceil(screenHeight / minItemHeight) + 1
|
}: {minItemHeight?: number; screenHeightOffset?: number} = {}) {
|
||||||
}, [minItemHeight])
|
const {height: screenHeight} = useWindowDimensions()
|
||||||
|
const {top: topInset} = useSafeAreaInsets()
|
||||||
|
const bottomBarHeight = useBottomBarOffset()
|
||||||
|
|
||||||
|
const finalHeight =
|
||||||
|
screenHeight - screenHeightOffset - topInset - bottomBarHeight
|
||||||
|
return Math.floor(finalHeight / minItemHeight) + 1
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,7 +96,7 @@ export function MessagesScreen({navigation, route}: Props) {
|
||||||
)
|
)
|
||||||
}, [_, t])
|
}, [_, t])
|
||||||
|
|
||||||
const initialNumToRender = useInitialNumToRender(80)
|
const initialNumToRender = useInitialNumToRender({minItemHeight: 80})
|
||||||
const [isPTRing, setIsPTRing] = useState(false)
|
const [isPTRing, setIsPTRing] = useState(false)
|
||||||
|
|
||||||
const {
|
const {
|
||||||
|
|
|
@ -8,6 +8,7 @@ import {isNative} from '#/platform/detection'
|
||||||
import {FeedDescriptor} from '#/state/queries/post-feed'
|
import {FeedDescriptor} from '#/state/queries/post-feed'
|
||||||
import {RQKEY as FEED_RQKEY} from '#/state/queries/post-feed'
|
import {RQKEY as FEED_RQKEY} from '#/state/queries/post-feed'
|
||||||
import {truncateAndInvalidate} from '#/state/queries/util'
|
import {truncateAndInvalidate} from '#/state/queries/util'
|
||||||
|
import {useInitialNumToRender} from 'lib/hooks/useInitialNumToRender'
|
||||||
import {usePalette} from 'lib/hooks/usePalette'
|
import {usePalette} from 'lib/hooks/usePalette'
|
||||||
import {Text} from '#/view/com/util/text/Text'
|
import {Text} from '#/view/com/util/text/Text'
|
||||||
import {Feed} from 'view/com/posts/Feed'
|
import {Feed} from 'view/com/posts/Feed'
|
||||||
|
@ -42,6 +43,10 @@ export const ProfileFeedSection = React.forwardRef<
|
||||||
const queryClient = useQueryClient()
|
const queryClient = useQueryClient()
|
||||||
const [hasNew, setHasNew] = React.useState(false)
|
const [hasNew, setHasNew] = React.useState(false)
|
||||||
const [isScrolledDown, setIsScrolledDown] = React.useState(false)
|
const [isScrolledDown, setIsScrolledDown] = React.useState(false)
|
||||||
|
const shouldUseAdjustedNumToRender = feed.endsWith('posts_and_author_threads')
|
||||||
|
const adjustedInitialNumToRender = useInitialNumToRender({
|
||||||
|
screenHeightOffset: headerHeight,
|
||||||
|
})
|
||||||
|
|
||||||
const onScrollToTop = React.useCallback(() => {
|
const onScrollToTop = React.useCallback(() => {
|
||||||
scrollElRef.current?.scrollToOffset({
|
scrollElRef.current?.scrollToOffset({
|
||||||
|
@ -79,7 +84,9 @@ export const ProfileFeedSection = React.forwardRef<
|
||||||
headerOffset={headerHeight}
|
headerOffset={headerHeight}
|
||||||
renderEndOfFeed={ProfileEndOfFeed}
|
renderEndOfFeed={ProfileEndOfFeed}
|
||||||
ignoreFilterFor={ignoreFilterFor}
|
ignoreFilterFor={ignoreFilterFor}
|
||||||
outsideHeaderOffset={headerHeight}
|
initialNumToRender={
|
||||||
|
shouldUseAdjustedNumToRender ? adjustedInitialNumToRender : undefined
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
{(isScrolledDown || hasNew) && (
|
{(isScrolledDown || hasNew) && (
|
||||||
<LoadLatestBtn
|
<LoadLatestBtn
|
||||||
|
|
|
@ -161,6 +161,7 @@ let Feed = ({
|
||||||
ListHeaderComponent,
|
ListHeaderComponent,
|
||||||
extraData,
|
extraData,
|
||||||
savedFeedConfig,
|
savedFeedConfig,
|
||||||
|
initialNumToRender: initialNumToRenderOverride,
|
||||||
}: {
|
}: {
|
||||||
feed: FeedDescriptor
|
feed: FeedDescriptor
|
||||||
feedParams?: FeedParams
|
feedParams?: FeedParams
|
||||||
|
@ -180,7 +181,7 @@ let Feed = ({
|
||||||
ListHeaderComponent?: () => JSX.Element
|
ListHeaderComponent?: () => JSX.Element
|
||||||
extraData?: any
|
extraData?: any
|
||||||
savedFeedConfig?: AppBskyActorDefs.SavedFeed
|
savedFeedConfig?: AppBskyActorDefs.SavedFeed
|
||||||
outsideHeaderOffset?: number
|
initialNumToRender?: number
|
||||||
}): React.ReactNode => {
|
}): React.ReactNode => {
|
||||||
const theme = useTheme()
|
const theme = useTheme()
|
||||||
const {track} = useAnalytics()
|
const {track} = useAnalytics()
|
||||||
|
@ -545,7 +546,7 @@ let Feed = ({
|
||||||
desktopFixedHeight={
|
desktopFixedHeight={
|
||||||
desktopFixedHeightOffset ? desktopFixedHeightOffset : true
|
desktopFixedHeightOffset ? desktopFixedHeightOffset : true
|
||||||
}
|
}
|
||||||
initialNumToRender={initialNumToRender}
|
initialNumToRender={initialNumToRenderOverride ?? initialNumToRender}
|
||||||
windowSize={11}
|
windowSize={11}
|
||||||
onItemSeen={feedFeedback.onItemSeen}
|
onItemSeen={feedFeedback.onItemSeen}
|
||||||
/>
|
/>
|
||||||
|
|
Loading…
Reference in New Issue