mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-02 18:09:58 +08:00
feat(core): disable the back gesture when the menu is open (#9263)
close: BS-2174
This commit is contained in:
@@ -44,6 +44,7 @@ import { useTheme } from 'next-themes';
|
|||||||
import { Suspense, useEffect } from 'react';
|
import { Suspense, useEffect } from 'react';
|
||||||
import { RouterProvider } from 'react-router-dom';
|
import { RouterProvider } from 'react-router-dom';
|
||||||
|
|
||||||
|
import { BlocksuiteMenuConfigProvider } from './bs-menu-config';
|
||||||
import { configureFetchProvider } from './fetch';
|
import { configureFetchProvider } from './fetch';
|
||||||
import { ModalConfigProvider } from './modal-config';
|
import { ModalConfigProvider } from './modal-config';
|
||||||
import { Cookie } from './plugins/cookie';
|
import { Cookie } from './plugins/cookie';
|
||||||
@@ -259,11 +260,13 @@ export function App() {
|
|||||||
<AffineContext store={getCurrentStore()}>
|
<AffineContext store={getCurrentStore()}>
|
||||||
<KeyboardThemeProvider />
|
<KeyboardThemeProvider />
|
||||||
<ModalConfigProvider>
|
<ModalConfigProvider>
|
||||||
<RouterProvider
|
<BlocksuiteMenuConfigProvider>
|
||||||
fallbackElement={<AppFallback />}
|
<RouterProvider
|
||||||
router={router}
|
fallbackElement={<AppFallback />}
|
||||||
future={future}
|
router={router}
|
||||||
/>
|
future={future}
|
||||||
|
/>
|
||||||
|
</BlocksuiteMenuConfigProvider>
|
||||||
</ModalConfigProvider>
|
</ModalConfigProvider>
|
||||||
</AffineContext>
|
</AffineContext>
|
||||||
</I18nProvider>
|
</I18nProvider>
|
||||||
|
|||||||
@@ -0,0 +1,41 @@
|
|||||||
|
import { NavigationGestureService } from '@affine/core/mobile/modules/navigation-gesture';
|
||||||
|
import { onMenuOpen } from '@blocksuite/affine-components/context-menu';
|
||||||
|
import { useService } from '@toeverything/infra';
|
||||||
|
import { type PropsWithChildren, useCallback, useEffect, useRef } from 'react';
|
||||||
|
|
||||||
|
export const BlocksuiteMenuConfigProvider = ({
|
||||||
|
children,
|
||||||
|
}: PropsWithChildren) => {
|
||||||
|
const navigationGesture = useService(NavigationGestureService);
|
||||||
|
const menuCountRef = useRef(0);
|
||||||
|
const prevEnabledRef = useRef(false);
|
||||||
|
|
||||||
|
const handleMenuState = useCallback(() => {
|
||||||
|
const currentCount = menuCountRef.current + 1;
|
||||||
|
menuCountRef.current = currentCount;
|
||||||
|
|
||||||
|
if (currentCount === 1) {
|
||||||
|
prevEnabledRef.current = navigationGesture.enabled$.value;
|
||||||
|
if (prevEnabledRef.current) {
|
||||||
|
navigationGesture.setEnabled(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
const currentCount = menuCountRef.current - 1;
|
||||||
|
menuCountRef.current = currentCount;
|
||||||
|
|
||||||
|
if (currentCount === 0 && prevEnabledRef.current) {
|
||||||
|
navigationGesture.setEnabled(true);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}, [navigationGesture]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
return onMenuOpen(() => {
|
||||||
|
return handleMenuState();
|
||||||
|
});
|
||||||
|
}, [handleMenuState]);
|
||||||
|
|
||||||
|
return children;
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user