From 209c0889f8a0cbeded5b62bdcf27e06a2d9cd916 Mon Sep 17 00:00:00 2001 From: CatsJuice Date: Tue, 24 Dec 2024 03:39:56 +0000 Subject: [PATCH] fix(mobile): reset active-tab to home on ios/android when launched (#9245) --- .../core/src/mobile/components/app-tabs/tab-item.tsx | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/frontend/core/src/mobile/components/app-tabs/tab-item.tsx b/packages/frontend/core/src/mobile/components/app-tabs/tab-item.tsx index c4297062bc..abc6f8e8f9 100644 --- a/packages/frontend/core/src/mobile/components/app-tabs/tab-item.tsx +++ b/packages/frontend/core/src/mobile/components/app-tabs/tab-item.tsx @@ -1,6 +1,6 @@ import { GlobalCacheService } from '@affine/core/modules/storage'; import { LiveData, useLiveData, useService } from '@toeverything/infra'; -import { type PropsWithChildren, useCallback, useMemo } from 'react'; +import { type PropsWithChildren, useCallback, useEffect, useMemo } from 'react'; import { tabItem } from './styles.css'; @@ -11,6 +11,7 @@ export interface TabItemProps extends PropsWithChildren { } const cacheKey = 'activeAppTabId'; +let isInitialized = false; export const TabItem = ({ id, label, children, onClick }: TabItemProps) => { const globalCache = useService(GlobalCacheService).globalCache; const activeTabId$ = useMemo( @@ -26,6 +27,14 @@ export const TabItem = ({ id, label, children, onClick }: TabItemProps) => { onClick?.(isActive); }, [globalCache, id, isActive, onClick]); + useEffect(() => { + if (isInitialized) return; + isInitialized = true; + if (BUILD_CONFIG.isIOS || BUILD_CONFIG.isAndroid) { + globalCache.set(cacheKey, 'home'); + } + }, [globalCache]); + return (