feat(mobile): disable swipe back gesture when there is no back in header (#8876)

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
This commit is contained in:
CatsJuice
2024-11-25 03:12:21 +00:00
parent 922db5ced4
commit b369ee0cca
23 changed files with 260 additions and 26 deletions
@@ -5,11 +5,13 @@ class AFFiNEViewController: CAPBridgeViewController {
override func viewDidLoad() {
super.viewDidLoad()
webView?.allowsBackForwardNavigationGestures = true
// disable by default, enable manually when there is a "back" button in page-header
webView?.allowsBackForwardNavigationGestures = false
}
override func capacitorDidLoad() {
bridge?.registerPluginInstance(CookiePlugin())
bridge?.registerPluginInstance(HashcashPlugin())
bridge?.registerPluginInstance(NavigationGesturePlugin())
}
}
@@ -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([:])
}
}
}