Skip to content

Commit

Permalink
Show tabs when swiping feeds (#1856)
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon authored Nov 9, 2023
1 parent 7a55ca6 commit c627a76
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/view/com/pager/Pager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ interface Props {
renderTabBar: RenderTabBarFn
onPageSelected?: (index: number) => void
onPageSelecting?: (index: number) => void
onPageScrollStateChanged?: (
scrollState: 'idle' | 'dragging' | 'settling',
) => void
testID?: string
}
export const Pager = forwardRef<PagerRef, React.PropsWithChildren<Props>>(
Expand All @@ -35,6 +38,7 @@ export const Pager = forwardRef<PagerRef, React.PropsWithChildren<Props>>(
tabBarPosition = 'top',
initialPage = 0,
renderTabBar,
onPageScrollStateChanged,
onPageSelected,
onPageSelecting,
testID,
Expand Down Expand Up @@ -97,11 +101,12 @@ export const Pager = forwardRef<PagerRef, React.PropsWithChildren<Props>>(
[lastOffset, lastDirection, onPageSelecting],
)

const onPageScrollStateChanged = React.useCallback(
const handlePageScrollStateChanged = React.useCallback(
(e: PageScrollStateChangedNativeEvent) => {
scrollState.current = e.nativeEvent.pageScrollState
onPageScrollStateChanged?.(e.nativeEvent.pageScrollState)
},
[scrollState],
[scrollState, onPageScrollStateChanged],
)

const onTabBarSelect = React.useCallback(
Expand All @@ -123,7 +128,7 @@ export const Pager = forwardRef<PagerRef, React.PropsWithChildren<Props>>(
ref={pagerView}
style={s.flex1}
initialPage={initialPage}
onPageScrollStateChanged={onPageScrollStateChanged}
onPageScrollStateChanged={handlePageScrollStateChanged}
onPageSelected={onPageSelectedInner}
onPageScroll={onPageScroll}>
{children}
Expand Down
10 changes: 10 additions & 0 deletions src/view/screens/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,15 @@ export const HomeScreen = withAuthRequired(
store.emitScreenSoftReset()
}, [store])

const onPageScrollStateChanged = React.useCallback(
(state: 'idle' | 'dragging' | 'settling') => {
if (state === 'dragging') {
setMinimalShellMode(false)
}
},
[setMinimalShellMode],
)

const renderTabBar = React.useCallback(
(props: RenderTabBarFnProps) => {
return (
Expand Down Expand Up @@ -113,6 +122,7 @@ export const HomeScreen = withAuthRequired(
ref={pagerRef}
testID="homeScreen"
onPageSelected={onPageSelected}
onPageScrollStateChanged={onPageScrollStateChanged}
renderTabBar={renderTabBar}
tabBarPosition="top">
<FeedPage
Expand Down

0 comments on commit c627a76

Please sign in to comment.