mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 12:55:00 +00:00
close AF-1663, AF-1756 - new global `ModalConfigContext` - new logic to judge whether inside modal - render `✕` for PageHeader back if inside modal - only enable `NavigationGesture` when there is `<` in PageHeader
29 lines
855 B
TypeScript
29 lines
855 B
TypeScript
import { ModalConfigContext } from '@affine/component';
|
|
import { NavigationGestureService } from '@affine/core/mobile/modules/navigation-gesture';
|
|
import { useService } from '@toeverything/infra';
|
|
import { type PropsWithChildren, useCallback } from 'react';
|
|
|
|
export const ModalConfigProvider = ({ children }: PropsWithChildren) => {
|
|
const navigationGesture = useService(NavigationGestureService);
|
|
|
|
const onOpenChange = useCallback(
|
|
(open: boolean) => {
|
|
const prev = navigationGesture.enabled$.value;
|
|
if (open && !prev) {
|
|
navigationGesture.setEnabled(false);
|
|
return () => {
|
|
navigationGesture.setEnabled(prev);
|
|
};
|
|
}
|
|
return;
|
|
},
|
|
[navigationGesture]
|
|
);
|
|
|
|
return (
|
|
<ModalConfigContext.Provider value={{ onOpenChange }}>
|
|
{children}
|
|
</ModalConfigContext.Provider>
|
|
);
|
|
};
|