Add soft reset on tap selected in tab bar

zio/stable
Paul Frazee 2023-03-17 15:17:28 -05:00
parent 201c21df6d
commit b711a49df9
2 changed files with 18 additions and 3 deletions

View File

@ -21,6 +21,7 @@ export function TabBar({
indicatorPosition = 'bottom',
indicatorColor,
onSelect,
onPressSelected,
}: {
selectedPage: number
items: string[]
@ -29,6 +30,7 @@ export function TabBar({
indicatorPosition?: 'top' | 'bottom'
indicatorColor?: string
onSelect?: (index: number) => void
onPressSelected?: () => void
}) {
const pal = usePalette('default')
const [itemLayouts, setItemLayouts] = useState<Layout[]>(
@ -80,6 +82,9 @@ export function TabBar({
const onPressItem = (index: number) => {
onSelect?.(index)
if (index === selectedPage) {
onPressSelected?.()
}
}
return (

View File

@ -59,8 +59,12 @@ export const HomeScreen = withAuthRequired((_opts: Props) => {
[store],
)
const onPressSelected = React.useCallback(() => {
store.emitScreenSoftReset()
}, [store])
const renderTabBar = React.useCallback((props: TabBarProps) => {
return <FloatingTabBar {...props} />
return <FloatingTabBar {...props} onPressSelected={onPressSelected} />
}, [])
return (
@ -156,9 +160,15 @@ const FeedPage = observer(
scrollElRef.current?.scrollToOffset({offset: 0})
}, [scrollElRef])
const onSoftReset = React.useCallback(() => {
if (isPageFocused) {
scrollToTop()
}
}, [isPageFocused, scrollToTop])
useFocusEffect(
React.useCallback(() => {
const softResetSub = store.onScreenSoftReset(scrollToTop)
const softResetSub = store.onScreenSoftReset(onSoftReset)
const feedCleanup = feed.registerListeners()
const pollInterval = setInterval(doPoll, 15e3)
@ -173,7 +183,7 @@ const FeedPage = observer(
softResetSub.remove()
feedCleanup()
}
}, [store, doPoll, scrollToTop, screen, feed]),
}, [store, doPoll, onSoftReset, screen, feed]),
)
const onPressCompose = React.useCallback(() => {