Skip to content

There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.

fix(mobile): reset active-tab to home on ios/android when launched (#9245)

CatsJuice209c0889f8a0
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 (
<li
className={tabItem}