Add soft reset on tap selected in tab bar
parent
201c21df6d
commit
b711a49df9
|
@ -21,6 +21,7 @@ export function TabBar({
|
||||||
indicatorPosition = 'bottom',
|
indicatorPosition = 'bottom',
|
||||||
indicatorColor,
|
indicatorColor,
|
||||||
onSelect,
|
onSelect,
|
||||||
|
onPressSelected,
|
||||||
}: {
|
}: {
|
||||||
selectedPage: number
|
selectedPage: number
|
||||||
items: string[]
|
items: string[]
|
||||||
|
@ -29,6 +30,7 @@ export function TabBar({
|
||||||
indicatorPosition?: 'top' | 'bottom'
|
indicatorPosition?: 'top' | 'bottom'
|
||||||
indicatorColor?: string
|
indicatorColor?: string
|
||||||
onSelect?: (index: number) => void
|
onSelect?: (index: number) => void
|
||||||
|
onPressSelected?: () => void
|
||||||
}) {
|
}) {
|
||||||
const pal = usePalette('default')
|
const pal = usePalette('default')
|
||||||
const [itemLayouts, setItemLayouts] = useState<Layout[]>(
|
const [itemLayouts, setItemLayouts] = useState<Layout[]>(
|
||||||
|
@ -80,6 +82,9 @@ export function TabBar({
|
||||||
|
|
||||||
const onPressItem = (index: number) => {
|
const onPressItem = (index: number) => {
|
||||||
onSelect?.(index)
|
onSelect?.(index)
|
||||||
|
if (index === selectedPage) {
|
||||||
|
onPressSelected?.()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -59,8 +59,12 @@ export const HomeScreen = withAuthRequired((_opts: Props) => {
|
||||||
[store],
|
[store],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const onPressSelected = React.useCallback(() => {
|
||||||
|
store.emitScreenSoftReset()
|
||||||
|
}, [store])
|
||||||
|
|
||||||
const renderTabBar = React.useCallback((props: TabBarProps) => {
|
const renderTabBar = React.useCallback((props: TabBarProps) => {
|
||||||
return <FloatingTabBar {...props} />
|
return <FloatingTabBar {...props} onPressSelected={onPressSelected} />
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -156,9 +160,15 @@ const FeedPage = observer(
|
||||||
scrollElRef.current?.scrollToOffset({offset: 0})
|
scrollElRef.current?.scrollToOffset({offset: 0})
|
||||||
}, [scrollElRef])
|
}, [scrollElRef])
|
||||||
|
|
||||||
|
const onSoftReset = React.useCallback(() => {
|
||||||
|
if (isPageFocused) {
|
||||||
|
scrollToTop()
|
||||||
|
}
|
||||||
|
}, [isPageFocused, scrollToTop])
|
||||||
|
|
||||||
useFocusEffect(
|
useFocusEffect(
|
||||||
React.useCallback(() => {
|
React.useCallback(() => {
|
||||||
const softResetSub = store.onScreenSoftReset(scrollToTop)
|
const softResetSub = store.onScreenSoftReset(onSoftReset)
|
||||||
const feedCleanup = feed.registerListeners()
|
const feedCleanup = feed.registerListeners()
|
||||||
const pollInterval = setInterval(doPoll, 15e3)
|
const pollInterval = setInterval(doPoll, 15e3)
|
||||||
|
|
||||||
|
@ -173,7 +183,7 @@ const FeedPage = observer(
|
||||||
softResetSub.remove()
|
softResetSub.remove()
|
||||||
feedCleanup()
|
feedCleanup()
|
||||||
}
|
}
|
||||||
}, [store, doPoll, scrollToTop, screen, feed]),
|
}, [store, doPoll, onSoftReset, screen, feed]),
|
||||||
)
|
)
|
||||||
|
|
||||||
const onPressCompose = React.useCallback(() => {
|
const onPressCompose = React.useCallback(() => {
|
||||||
|
|
Loading…
Reference in New Issue