Skip to content

Commit

Permalink
Fix iOS jump in the new pager
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon committed Nov 6, 2023
1 parent 4c00fc5 commit 061227c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
16 changes: 12 additions & 4 deletions src/view/com/pager/PagerWithHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react'
import {LayoutChangeEvent, StyleSheet} from 'react-native'
import {LayoutChangeEvent, StyleSheet, View} from 'react-native'
import Animated, {
Easing,
useAnimatedReaction,
Expand Down Expand Up @@ -131,7 +131,7 @@ export const PagerWithHeader = React.forwardRef<PagerRef, PagerWithHeaderProps>(
// props to pass into children render functions
const onScroll = useAnimatedScrollHandler({
onScroll(e) {
scrollY.value = e.contentOffset.y
scrollY.value = e.contentOffset.y + (e.contentInset?.top ?? 0)
},
})
const childProps = React.useMemo<PagerWithHeaderChildParams>(() => {
Expand Down Expand Up @@ -175,9 +175,17 @@ export const PagerWithHeader = React.forwardRef<PagerRef, PagerWithHeaderProps>(
tabBarPosition="top">
{toArray(children)
.filter(Boolean)
.map(child => {
.map((child, i) => {
if (child) {
return child(childProps)
return (
<View
key={i}
style={{
opacity: headerHeight > 0 ? 1 : 0,
}}>
{child(childProps)}
</View>
)
}
return null
})}
Expand Down
4 changes: 3 additions & 1 deletion src/view/com/posts/Feed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, {MutableRefObject} from 'react'
import {observer} from 'mobx-react-lite'
import {
ActivityIndicator,
Platform,
RefreshControl,
StyleProp,
StyleSheet,
Expand Down Expand Up @@ -177,13 +178,14 @@ export const Feed = observer(function Feed({
/>
}
contentContainerStyle={s.contentContainer}
style={{paddingTop: headerOffset}}
onScroll={onScroll}
scrollEventThrottle={scrollEventThrottle}
indicatorStyle={theme.colorScheme === 'dark' ? 'white' : 'black'}
onEndReached={onEndReached}
onEndReachedThreshold={2}
removeClippedSubviews={true}
style={{paddingTop: Platform.OS === 'ios' ? 0 : headerOffset}}
contentInset={{top: headerOffset}}
contentOffset={{x: 0, y: headerOffset * -1}}
extraData={extraData}
// @ts-ignore our .web version only -prf
Expand Down

0 comments on commit 061227c

Please sign in to comment.