From 1cb94710533eb6ccb85637e174ddbb629013b438 Mon Sep 17 00:00:00 2001 From: Martin Mazein Date: Fri, 2 Aug 2024 15:55:08 +0200 Subject: [PATCH] fix(ios): allow enabling gesture navigation via config (#3808) Signed-off-by: Martin Mazein --- ios/Capacitor/Capacitor/CAPBridgeViewController.swift | 1 + ios/Capacitor/Capacitor/CAPInstanceConfiguration.h | 1 + ios/Capacitor/Capacitor/CAPInstanceConfiguration.m | 2 ++ ios/Capacitor/Capacitor/CAPInstanceDescriptor.h | 5 +++++ ios/Capacitor/Capacitor/CAPInstanceDescriptor.m | 1 + ios/Capacitor/Capacitor/CAPInstanceDescriptor.swift | 3 +++ 6 files changed, 13 insertions(+) diff --git a/ios/Capacitor/Capacitor/CAPBridgeViewController.swift b/ios/Capacitor/Capacitor/CAPBridgeViewController.swift index 37ef75c4d..a9c63890e 100644 --- a/ios/Capacitor/Capacitor/CAPBridgeViewController.swift +++ b/ios/Capacitor/Capacitor/CAPBridgeViewController.swift @@ -288,6 +288,7 @@ extension CAPBridgeViewController { aWebView.scrollView.bounces = false aWebView.scrollView.contentInsetAdjustmentBehavior = configuration.contentInsetAdjustmentBehavior aWebView.allowsLinkPreview = configuration.allowLinkPreviews + aWebView.allowsBackForwardNavigationGestures = configuration.allowsBackForwardNavigationGestures aWebView.scrollView.isScrollEnabled = configuration.scrollingEnabled if let overrideUserAgent = configuration.overridenUserAgentString { aWebView.customUserAgent = overrideUserAgent diff --git a/ios/Capacitor/Capacitor/CAPInstanceConfiguration.h b/ios/Capacitor/Capacitor/CAPInstanceConfiguration.h index 81ebe3d1b..2122c91a9 100644 --- a/ios/Capacitor/Capacitor/CAPInstanceConfiguration.h +++ b/ios/Capacitor/Capacitor/CAPInstanceConfiguration.h @@ -19,6 +19,7 @@ NS_SWIFT_NAME(InstanceConfiguration) @property (nonatomic, readonly) BOOL scrollingEnabled; @property (nonatomic, readonly) BOOL zoomingEnabled; @property (nonatomic, readonly) BOOL allowLinkPreviews; +@property (nonatomic, readonly) BOOL allowsBackForwardNavigationGestures; @property (nonatomic, readonly) BOOL handleApplicationNotifications; @property (nonatomic, readonly) BOOL isWebDebuggable; @property (nonatomic, readonly) BOOL cordovaDeployDisabled; diff --git a/ios/Capacitor/Capacitor/CAPInstanceConfiguration.m b/ios/Capacitor/Capacitor/CAPInstanceConfiguration.m index 0bb8ecd8f..52289b13f 100644 --- a/ios/Capacitor/Capacitor/CAPInstanceConfiguration.m +++ b/ios/Capacitor/Capacitor/CAPInstanceConfiguration.m @@ -31,6 +31,7 @@ - (instancetype)initWithDescriptor:(CAPInstanceDescriptor *)descriptor isDebug:( _scrollingEnabled = descriptor.scrollingEnabled; _zoomingEnabled = descriptor.zoomingEnabled; _allowLinkPreviews = descriptor.allowLinkPreviews; + _allowsBackForwardNavigationGestures = descriptor.allowsBackForwardNavigationGestures; _handleApplicationNotifications = descriptor.handleApplicationNotifications; _contentInsetAdjustmentBehavior = descriptor.contentInsetAdjustmentBehavior; _appLocation = descriptor.appLocation; @@ -69,6 +70,7 @@ - (instancetype)initWithConfiguration:(CAPInstanceConfiguration*)configuration a _scrollingEnabled = configuration.scrollingEnabled; _zoomingEnabled = configuration.zoomingEnabled; _allowLinkPreviews = configuration.allowLinkPreviews; + _allowsBackForwardNavigationGestures = configuration.allowsBackForwardNavigationGestures; _handleApplicationNotifications = configuration.handleApplicationNotifications; _isWebDebuggable = configuration.isWebDebuggable; _cordovaDeployDisabled = configuration.cordovaDeployDisabled; diff --git a/ios/Capacitor/Capacitor/CAPInstanceDescriptor.h b/ios/Capacitor/Capacitor/CAPInstanceDescriptor.h index 228b3a41d..3537d37ce 100644 --- a/ios/Capacitor/Capacitor/CAPInstanceDescriptor.h +++ b/ios/Capacitor/Capacitor/CAPInstanceDescriptor.h @@ -93,6 +93,11 @@ NS_SWIFT_NAME(InstanceDescriptor) @discussion Set by @c ios.allowsLinkPreview in the configuration file. Corresponds to @c allowsLinkPreview on WKWebView. */ @property (nonatomic, assign) BOOL allowLinkPreviews; +/** + @brief Whether or not the web view will allow gesture navigation . + @discussion Set by @c ios.allowsBackForwardNavigationGestures in the configuration file. Corresponds to @c allowsBackForwardNavigationGestures on WKWebView. + */ +@property (nonatomic, assign) BOOL allowsBackForwardNavigationGestures; /** @brief Whether or not the Capacitor runtime will set itself as the @c UNUserNotificationCenter delegate. @discussion Defaults to @c true. Required to be @c true for notification plugins to work correctly. Set to @c false if your application will handle notifications independently. diff --git a/ios/Capacitor/Capacitor/CAPInstanceDescriptor.m b/ios/Capacitor/Capacitor/CAPInstanceDescriptor.m index 6d3566776..910458322 100644 --- a/ios/Capacitor/Capacitor/CAPInstanceDescriptor.m +++ b/ios/Capacitor/Capacitor/CAPInstanceDescriptor.m @@ -39,6 +39,7 @@ - (void)_setDefaultsWithAppLocation:(NSURL*)location { _scrollingEnabled = YES; _zoomingEnabled = NO; _allowLinkPreviews = YES; + _allowsBackForwardNavigationGestures = NO; _handleApplicationNotifications = YES; _isWebDebuggable = NO; _contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever; diff --git a/ios/Capacitor/Capacitor/CAPInstanceDescriptor.swift b/ios/Capacitor/Capacitor/CAPInstanceDescriptor.swift index 9645d005e..d354af3fe 100644 --- a/ios/Capacitor/Capacitor/CAPInstanceDescriptor.swift +++ b/ios/Capacitor/Capacitor/CAPInstanceDescriptor.swift @@ -111,6 +111,9 @@ internal extension InstanceDescriptor { if let allowPreviews = config[keyPath: "ios.allowsLinkPreview"] as? Bool { allowLinkPreviews = allowPreviews } + if let allowsNavigationGestures = config[keyPath: "ios.allowsBackForwardNavigationGestures"] as? Bool { + allowsBackForwardNavigationGestures = allowsNavigationGestures + } if let scrollEnabled = config[keyPath: "ios.scrollEnabled"] as? Bool { scrollingEnabled = scrollEnabled }