From fe184ba904c6d9ab93d2125a42171cba97332b1f Mon Sep 17 00:00:00 2001 From: xinhao Date: Tue, 1 Sep 2020 15:05:40 +0800 Subject: [PATCH] feat(ios): set AllowBackNavigationGestures dynamically from JavaScript --- src/ios/CDVWKWebViewEngine.h | 1 + src/ios/CDVWKWebViewEngine.m | 11 +++++++++++ src/www/util.js | 3 +++ 3 files changed, 15 insertions(+) diff --git a/src/ios/CDVWKWebViewEngine.h b/src/ios/CDVWKWebViewEngine.h index 9dd7b24c..7272d2ee 100644 --- a/src/ios/CDVWKWebViewEngine.h +++ b/src/ios/CDVWKWebViewEngine.h @@ -27,5 +27,6 @@ -(void)setServerBasePath:(CDVInvokedUrlCommand*)command; -(void)getServerBasePath:(CDVInvokedUrlCommand*)command; +-(void)setAllowBackNavigationGestures:(CDVInvokedUrlCommand*)command; @end diff --git a/src/ios/CDVWKWebViewEngine.m b/src/ios/CDVWKWebViewEngine.m index d6b24084..39e184bb 100644 --- a/src/ios/CDVWKWebViewEngine.m +++ b/src/ios/CDVWKWebViewEngine.m @@ -802,6 +802,17 @@ -(void)persistServerBasePath:(CDVInvokedUrlCommand*)command [userDefaults synchronize]; } +-(void)setAllowBackNavigationGestures:(CDVInvokedUrlCommand*)command +{ + id value = [command argumentAtIndex:0]; + if (!([value isKindOfClass:[NSNumber class]])) { + value = [NSNumber numberWithBool:NO]; + } + + WKWebView* wkWebView = (WKWebView*)_engineWebView; + wkWebView.allowsBackForwardNavigationGestures = [value boolValue]; +} + @end #pragma mark - CDVWKWeakScriptMessageHandler diff --git a/src/www/util.js b/src/www/util.js index ba52a8e9..b3c624d3 100644 --- a/src/www/util.js +++ b/src/www/util.js @@ -24,6 +24,9 @@ var WebView = { }, persistServerBasePath: function() { exec(null, null, 'IonicWebView', 'persistServerBasePath', []); + }, + setAllowBackNavigationGestures: function(allow) { + exec(null, null, 'IonicWebView', 'setAllowBackNavigationGestures', [allow]); } }