Better positioning

This commit is contained in:
Dan Abramov
2023-12-22 21:57:05 +00:00
parent f3972c44f7
commit a76746d3c7
+10 -5
View File
@@ -139,7 +139,7 @@ function PostThreadLoaded({
const {hasSession} = useSession() const {hasSession} = useSession()
const {_} = useLingui() const {_} = useLingui()
const pal = usePalette('default') const pal = usePalette('default')
const {isTablet, isDesktop} = useWebMediaQueries() const {isTablet, isDesktop, isTabletOrMobile} = useWebMediaQueries()
const ref = useRef<ListMethods>(null) const ref = useRef<ListMethods>(null)
const highlightedPostRef = useRef<View | null>(null) const highlightedPostRef = useRef<View | null>(null)
const needsScrollAdjustment = useRef<boolean>( const needsScrollAdjustment = useRef<boolean>(
@@ -198,9 +198,15 @@ function PostThreadLoaded({
// wait for loading to finish // wait for loading to finish
if (thread.type === 'post' && !!thread.parent) { if (thread.type === 'post' && !!thread.parent) {
function onMeasure(pageY) { function onMeasure(pageY) {
let spinnerHeight = 0
if (isDesktop) {
spinnerHeight = 40
} else if (isTabletOrMobile) {
spinnerHeight = 82
}
ref.current?.scrollToOffset({ ref.current?.scrollToOffset({
animated: false, animated: false,
offset: pageY - (isDesktop ? 0 : 50), offset: pageY - spinnerHeight,
}) })
} }
if (isNative) { if (isNative) {
@@ -210,13 +216,12 @@ function PostThreadLoaded({
}, },
) )
} else { } else {
const pageY = const pageY = highlightedPostRef.current.getBoundingClientRect().top
highlightedPostRef.current.getBoundingClientRect().top + scrollY
onMeasure(pageY) onMeasure(pageY)
} }
needsScrollAdjustment.current = false needsScrollAdjustment.current = false
} }
}, [thread, isDesktop]) }, [thread, isDesktop, isTabletOrMobile])
const onPTR = React.useCallback(async () => { const onPTR = React.useCallback(async () => {
setIsPTRing(true) setIsPTRing(true)