Add main menu button

zio/stable
Paul Frazee 2022-12-09 11:22:19 -06:00
parent 356297cace
commit fbf8e5fa14
4 changed files with 28 additions and 26 deletions

View File

@ -67,7 +67,7 @@ export interface ComposerOpts {
} }
export class ShellUiModel { export class ShellUiModel {
isViewControllingSwipes = false isMainMenuOpen = false
isModalActive = false isModalActive = false
activeModal: activeModal:
| ConfirmModel | ConfirmModel
@ -82,8 +82,8 @@ export class ShellUiModel {
makeAutoObservable(this) makeAutoObservable(this)
} }
setViewControllingSwipes(v: boolean) { setMainMenuOpen(v: boolean) {
this.isViewControllingSwipes = v this.isMainMenuOpen = v
} }
openModal( openModal(

View File

@ -28,6 +28,9 @@ export const ViewHeader = observer(function ViewHeader({
const onPressBack = () => { const onPressBack = () => {
store.nav.tab.goBack() store.nav.tab.goBack()
} }
const onPressMenu = () => {
store.shell.setMainMenuOpen(true)
}
const onPressCompose = () => { const onPressCompose = () => {
store.shell.openComposer({onPost}) store.shell.openComposer({onPost})
} }
@ -40,21 +43,20 @@ export const ViewHeader = observer(function ViewHeader({
console.log(e) console.log(e)
}) })
} }
const canGoBack = store.nav.tab.canGoBack
return ( return (
<> <>
<View style={styles.header}> <View style={styles.header}>
{store.nav.tab.canGoBack ? (
<TouchableOpacity <TouchableOpacity
onPress={onPressBack} onPress={canGoBack ? onPressBack : onPressMenu}
hitSlop={BACK_HITSLOP} hitSlop={BACK_HITSLOP}
style={styles.backIcon}> style={styles.backIcon}>
<FontAwesomeIcon <FontAwesomeIcon
size={18} size={18}
icon="angle-left" icon={canGoBack ? 'angle-left' : 'bars'}
style={{marginTop: 6}} style={{marginTop: 6}}
/> />
</TouchableOpacity> </TouchableOpacity>
) : undefined}
<View style={styles.titleContainer} pointerEvents="none"> <View style={styles.titleContainer} pointerEvents="none">
<Text style={styles.title}>{title}</Text> <Text style={styles.title}>{title}</Text>
{subtitle ? ( {subtitle ? (

View File

@ -44,9 +44,6 @@ export function ViewSelector({
} }
const onPressSelection = (index: number) => setSelectedIndex(index) const onPressSelection = (index: number) => setSelectedIndex(index)
useEffect(() => { useEffect(() => {
store.shell.setViewControllingSwipes(
Boolean(swipeEnabled) && selectedIndex > 0,
)
onSelectView?.(selectedIndex) onSelectView?.(selectedIndex)
}, [selectedIndex]) }, [selectedIndex])

View File

@ -110,7 +110,6 @@ const Btn = ({
export const MobileShell: React.FC = observer(() => { export const MobileShell: React.FC = observer(() => {
const store = useStores() const store = useStores()
const [isMenuActive, setMenuActive] = useState(false)
const [isTabsSelectorActive, setTabsSelectorActive] = useState(false) const [isTabsSelectorActive, setTabsSelectorActive] = useState(false)
const scrollElRef = useRef<FlatList | undefined>() const scrollElRef = useRef<FlatList | undefined>()
const winDim = useWindowDimensions() const winDim = useWindowDimensions()
@ -123,8 +122,8 @@ export const MobileShell: React.FC = observer(() => {
const screenRenderDesc = constructScreenRenderDesc(store.nav) const screenRenderDesc = constructScreenRenderDesc(store.nav)
const onPressHome = () => { const onPressHome = () => {
if (isMenuActive) { if (store.shell.isMainMenuOpen) {
setMenuActive(false) store.shell.setMainMenuOpen(false)
} }
if (store.nav.tab.fixedTabPurpose === 0) { if (store.nav.tab.fixedTabPurpose === 0) {
if (store.nav.tab.current.url === '/') { if (store.nav.tab.current.url === '/') {
@ -140,8 +139,8 @@ export const MobileShell: React.FC = observer(() => {
} }
} }
const onPressNotifications = () => { const onPressNotifications = () => {
if (isMenuActive) { if (store.shell.isMainMenuOpen) {
setMenuActive(false) store.shell.setMainMenuOpen(false)
} }
if (store.nav.tab.fixedTabPurpose === 1) { if (store.nav.tab.fixedTabPurpose === 1) {
store.nav.tab.fixedTabReset() store.nav.tab.fixedTabReset()
@ -211,6 +210,7 @@ export const MobileShell: React.FC = observer(() => {
// navigation swipes // navigation swipes
// = // =
const isMenuActive = store.shell.isMainMenuOpen
const canSwipeLeft = store.nav.tab.canGoBack || !isMenuActive const canSwipeLeft = store.nav.tab.canGoBack || !isMenuActive
const canSwipeRight = isMenuActive const canSwipeRight = isMenuActive
const onNavSwipeEnd = (dx: number) => { const onNavSwipeEnd = (dx: number) => {
@ -218,11 +218,11 @@ export const MobileShell: React.FC = observer(() => {
if (store.nav.tab.canGoBack) { if (store.nav.tab.canGoBack) {
store.nav.tab.goBack() store.nav.tab.goBack()
} else { } else {
setMenuActive(true) store.shell.setMainMenuOpen(true)
} }
} else if (dx > 0) { } else if (dx > 0) {
if (isMenuActive) { if (isMenuActive) {
setMenuActive(false) store.shell.setMainMenuOpen(false)
} }
} }
} }
@ -349,7 +349,10 @@ export const MobileShell: React.FC = observer(() => {
)} )}
</ScreenContainer> </ScreenContainer>
<Animated.View style={[styles.menuDrawer, menuSwipeTransform]}> <Animated.View style={[styles.menuDrawer, menuSwipeTransform]}>
<Menu visible={isMenuActive} onClose={() => setMenuActive(false)} /> <Menu
visible={isMenuActive}
onClose={() => store.shell.setMainMenuOpen(false)}
/>
</Animated.View> </Animated.View>
</HorzSwipe> </HorzSwipe>
</SafeAreaView> </SafeAreaView>