From d7a75a206281b99ad38fea576aa20a0557fd3d65 Mon Sep 17 00:00:00 2001 From: Paul Frazee Date: Tue, 11 Oct 2022 09:37:01 -0500 Subject: Home button scrolls to top when on home page --- src/view/shell/mobile/index.tsx | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'src/view/shell/mobile/index.tsx') diff --git a/src/view/shell/mobile/index.tsx b/src/view/shell/mobile/index.tsx index b8e83e873..732527963 100644 --- a/src/view/shell/mobile/index.tsx +++ b/src/view/shell/mobile/index.tsx @@ -1,9 +1,9 @@ -import React, {useState, useEffect} from 'react' +import React, {useState, useEffect, useRef} from 'react' import {observer} from 'mobx-react-lite' import { useWindowDimensions, + FlatList, GestureResponderEvent, - Image, SafeAreaView, StyleSheet, Text, @@ -97,6 +97,7 @@ export const MobileShell: React.FC = observer(() => { const [isLocationMenuActive, setLocationMenuActive] = useState(false) const [isMainMenuActive, setMainMenuActive] = useState(false) const [isTabsSelectorActive, setTabsSelectorActive] = useState(false) + const scrollElRef = useRef() const winDim = useWindowDimensions() const swipeGestureInterp = useSharedValue(0) const screenRenderDesc = constructScreenRenderDesc(store.nav) @@ -109,7 +110,13 @@ export const MobileShell: React.FC = observer(() => { const onPressBack = () => store.nav.tab.goBack() const onPressForward = () => store.nav.tab.goForward() - const onPressHome = () => store.nav.navigate('/') + const onPressHome = () => { + if (store.nav.tab.current.url === '/') { + scrollElRef.current?.scrollToOffset({offset: 0}) + } else { + store.nav.navigate('/') + } + } const onPressMenu = () => setMainMenuActive(true) const onPressTabs = () => setTabsSelectorActive(true) @@ -184,7 +191,11 @@ export const MobileShell: React.FC = observer(() => { styles.screen, current ? swipeTransform : undefined, ]}> - + ) -- cgit 1.4.1