Add hacks to fix web

This commit is contained in:
Dan Abramov
2023-11-10 06:00:15 +00:00
parent 0a67e83b05
commit 2b1cbf376a
2 changed files with 21 additions and 4 deletions
+12 -1
View File
@@ -49,7 +49,18 @@ export const Pager = React.forwardRef(function PagerImpl(
onSelect: onTabBarSelect,
})}
{React.Children.map(children, (child, i) => (
<View style={selectedPage === i ? s.flex1 : s.hidden} key={`page-${i}`}>
<View
style={
selectedPage === i
? s.flex1
: {
position: 'absolute',
pointerEvents: 'none',
// @ts-ignore web-only
visibility: 'hidden',
}
}
key={`page-${i}`}>
{child}
</View>
))}
+9 -3
View File
@@ -60,8 +60,8 @@ export const PagerWithHeader = React.forwardRef<PagerRef, PagerWithHeaderProps>(
const [tabBarHeight, setTabBarHeight] = React.useState(0)
const [headerOnlyHeight, setHeaderOnlyHeight] = React.useState(0)
const [isScrolledDown, setIsScrolledDown] = React.useState(false)
const headerHeight = headerOnlyHeight + tabBarHeight
const headerOnlyHeightShared = useSharedValue(0)
// capture the header bar sizing
const onTabBarLayout = React.useCallback(
@@ -73,8 +73,9 @@ export const PagerWithHeader = React.forwardRef<PagerRef, PagerWithHeaderProps>(
const onHeaderOnlyLayout = React.useCallback(
(evt: LayoutChangeEvent) => {
setHeaderOnlyHeight(evt.nativeEvent.layout.height)
headerOnlyHeightShared.value = evt.nativeEvent.layout.height
},
[setHeaderOnlyHeight],
[setHeaderOnlyHeight, headerOnlyHeightShared],
)
// render the the header and tab bar
@@ -131,7 +132,12 @@ export const PagerWithHeader = React.forwardRef<PagerRef, PagerWithHeaderProps>(
// props to pass into children render functions
const onScroll = useAnimatedScrollHandler({
onScroll(e) {
clampedScrollY.value = Math.min(e.contentOffset.y, headerOnlyHeight)
// TODO: We should be able to use headerOnlyHeight directly here, but on the web
// there seems is a bug in Reanimated causing state inside this function to be stale.
clampedScrollY.value = Math.min(
e.contentOffset.y,
headerOnlyHeightShared.value,
)
},
})
useAnimatedReaction(