-
-
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
19 changed files
with
176 additions
and
15 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
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
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'); |
54 changes: 54 additions & 0 deletions
54
packages/frontend/core/src/mobile/modules/navigation-gesture/services/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,54 @@ | ||
import { | ||
effect, | ||
exhaustMapWithTrailing, | ||
fromPromise, | ||
LiveData, | ||
Service, | ||
} from '@toeverything/infra'; | ||
import { catchError, distinctUntilChanged, EMPTY, mergeMap } from 'rxjs'; | ||
|
||
import type { NavigationGestureProvider } from '../providers/navigation-gesture'; | ||
|
||
export class NavigationGestureService extends Service { | ||
public enabled$ = new LiveData(false); | ||
|
||
constructor( | ||
private readonly navigationGestureProvider?: NavigationGestureProvider | ||
) { | ||
super(); | ||
this.disable().catch(console.error); | ||
} | ||
|
||
setEnabled = effect( | ||
distinctUntilChanged<boolean>(), | ||
exhaustMapWithTrailing((enable: boolean) => { | ||
return fromPromise(async () => { | ||
if (!this.navigationGestureProvider) { | ||
return; | ||
} | ||
if (enable) { | ||
await this.navigationGestureProvider.enable(); | ||
} else { | ||
await this.navigationGestureProvider.disable(); | ||
} | ||
return; | ||
}).pipe( | ||
mergeMap(() => EMPTY), | ||
catchError(err => { | ||
console.error('navigationGestureProvider error', err); | ||
return EMPTY; | ||
}) | ||
); | ||
}) | ||
); | ||
|
||
async enable() { | ||
this.enabled$.next(true); | ||
return this.navigationGestureProvider?.enable(); | ||
} | ||
|
||
async disable() { | ||
this.enabled$.next(false); | ||
return this.navigationGestureProvider?.disable(); | ||
} | ||
} |
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
2 changes: 1 addition & 1 deletion
2
packages/frontend/core/src/mobile/views/all-docs/collection/detail.tsx
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
2 changes: 1 addition & 1 deletion
2
packages/frontend/core/src/mobile/views/all-docs/tag/detail-header.tsx
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