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 {_} = useLingui()
const pal = usePalette('default')
const {isTablet, isDesktop} = useWebMediaQueries()
const {isTablet, isDesktop, isTabletOrMobile} = useWebMediaQueries()
const ref = useRef<ListMethods>(null)
const highlightedPostRef = useRef<View | null>(null)
const needsScrollAdjustment = useRef<boolean>(
@@ -198,9 +198,15 @@ function PostThreadLoaded({
// wait for loading to finish
if (thread.type === 'post' && !!thread.parent) {
function onMeasure(pageY) {
let spinnerHeight = 0
if (isDesktop) {
spinnerHeight = 40
} else if (isTabletOrMobile) {
spinnerHeight = 82
}
ref.current?.scrollToOffset({
animated: false,
offset: pageY - (isDesktop ? 0 : 50),
offset: pageY - spinnerHeight,
})
}
if (isNative) {
@@ -210,13 +216,12 @@ function PostThreadLoaded({
},
)
} else {
const pageY =
highlightedPostRef.current.getBoundingClientRect().top + scrollY
const pageY = highlightedPostRef.current.getBoundingClientRect().top
onMeasure(pageY)
}
needsScrollAdjustment.current = false
}
}, [thread, isDesktop])
}, [thread, isDesktop, isTabletOrMobile])
const onPTR = React.useCallback(async () => {
setIsPTRing(true)