-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(mobile): disable swipe back gesture when there is no back in header
- Loading branch information
Showing
23 changed files
with
260 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
packages/frontend/apps/ios/App/App/plugins/NavigationGesture/NavigationGesturePlugin.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import Foundation | ||
import Capacitor | ||
|
||
@objc(NavigationGesturePlugin) | ||
public class NavigationGesturePlugin: CAPPlugin, CAPBridgedPlugin { | ||
public let identifier = "NavigationGesturePlugin" | ||
public let jsName = "NavigationGesture" | ||
public let pluginMethods: [CAPPluginMethod] = [ | ||
CAPPluginMethod(name: "isEnabled", returnType: CAPPluginReturnPromise), | ||
CAPPluginMethod(name: "enable", returnType: CAPPluginReturnPromise), | ||
CAPPluginMethod(name: "disable", returnType: CAPPluginReturnPromise) | ||
] | ||
|
||
@objc func isEnabled(_ call: CAPPluginCall) { | ||
let enabled = self.bridge?.webView?.allowsBackForwardNavigationGestures ?? true | ||
call.resolve(["value": enabled]) | ||
} | ||
|
||
@objc func enable(_ call: CAPPluginCall) { | ||
DispatchQueue.main.sync { | ||
self.bridge?.webView?.allowsBackForwardNavigationGestures = true | ||
call.resolve([:]) | ||
} | ||
} | ||
|
||
@objc func disable(_ call: CAPPluginCall) { | ||
DispatchQueue.main.sync { | ||
self.bridge?.webView?.allowsBackForwardNavigationGestures = false | ||
call.resolve([:]) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
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> | ||
); | ||
}; |
5 changes: 5 additions & 0 deletions
5
packages/frontend/apps/ios/src/plugins/navigation-gesture/definitions.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export interface NavigationGesturePlugin { | ||
isEnabled: () => Promise<boolean>; | ||
enable: () => Promise<void>; | ||
disable: () => Promise<void>; | ||
} |
9 changes: 9 additions & 0 deletions
9
packages/frontend/apps/ios/src/plugins/navigation-gesture/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { registerPlugin } from '@capacitor/core'; | ||
|
||
import type { NavigationGesturePlugin } from './definitions'; | ||
|
||
const NavigationGesture = | ||
registerPlugin<NavigationGesturePlugin>('NavigationGesture'); | ||
|
||
export * from './definitions'; | ||
export { NavigationGesture }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { createContext } from 'react'; | ||
|
||
export interface ModalConfig { | ||
/** | ||
* add global callback for modal open/close | ||
*/ | ||
onOpenChange?: (open: boolean) => void; | ||
} | ||
export const ModalConfigContext = createContext<ModalConfig>({}); | ||
|
||
export const InsideModalContext = createContext<number>(0); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export * from './confirm-modal'; | ||
export * from './context'; | ||
export * from './modal'; | ||
export * from './overlay-modal'; | ||
export * from './prompt-modal'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
export * from './config-modal'; | ||
export * from './page-header'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
import type { Framework } from '@toeverything/infra'; | ||
|
||
import { configureMobileNavigationGestureModule } from './navigation-gesture'; | ||
import { configureMobileSearchModule } from './search'; | ||
import { configureMobileVirtualKeyboardModule } from './virtual-keyboard'; | ||
|
||
export function configureMobileModules(framework: Framework) { | ||
configureMobileSearchModule(framework); | ||
configureMobileVirtualKeyboardModule(framework); | ||
configureMobileNavigationGestureModule(framework); | ||
} |
13 changes: 13 additions & 0 deletions
13
packages/frontend/core/src/mobile/modules/navigation-gesture/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import type { Framework } from '@toeverything/infra'; | ||
|
||
import { NavigationGestureProvider } from './providers/navigation-gesture'; | ||
import { NavigationGestureService } from './services/navigation-gesture'; | ||
|
||
export { NavigationGestureProvider, NavigationGestureService }; | ||
|
||
export function configureMobileNavigationGestureModule(framework: Framework) { | ||
framework.service( | ||
NavigationGestureService, | ||
f => new NavigationGestureService(f.getOptional(NavigationGestureProvider)) | ||
); | ||
} |
10 changes: 10 additions & 0 deletions
10
packages/frontend/core/src/mobile/modules/navigation-gesture/providers/navigation-gesture.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { createIdentifier } from '@toeverything/infra'; | ||
|
||
export interface NavigationGestureProvider { | ||
isEnabled: () => Promise<boolean>; | ||
enable: () => Promise<void>; | ||
disable: () => Promise<void>; | ||
} | ||
|
||
export const NavigationGestureProvider = | ||
createIdentifier<NavigationGestureProvider>('NavigationGestureProvider'); |
Oops, something went wrong.