From ed81ab01e79c6d27b51867f926179495373f0bd4 Mon Sep 17 00:00:00 2001 From: Lea Anthony Date: Sat, 2 Aug 2025 21:02:52 +1000 Subject: [PATCH] Support allowsBackForwardNavigationGestures (#4453) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * ## Summary I have successfully implemented support for `allowsBackForwardNavigationGestures` in Wails v3. Here's what I accomplished: ### Investigation Results - **Issue Status**: The feature was **NOT** previously implemented in Wails v3 - **go-webview2**: This library is Windows-only and doesn't provide macOS WKWebView features - **Need**: A native implementation was required specifically for macOS WKWebView ### Implementation Details 1. **Added new option**: `AllowsBackForwardNavigationGestures u.Bool` to `MacWebviewPreferences` 2. **Extended C bridge**: Updated the C struct to pass the preference to Objective-C code 3. **Implemented WKWebView setting**: Added code to set `webView.allowsBackForwardNavigationGestures` during initialization 4. **Updated preference processing**: Extended the Go code to handle the new preference ### Key Files Modified - `v3/pkg/application/webview_window_options.go`: Added the preference option - `v3/pkg/application/webview_window_darwin.go`: Implemented the C bridge and WKWebView configuration ### Usage Example ```go window.SetOptions(application.WebviewWindowOptions{ Mac: application.MacWindow{ WebviewPreferences: application.MacWebviewPreferences{ AllowsBackForwardNavigationGestures: u.True(), }, }, }) ``` ### Testing - ✅ Code compiles successfully - ✅ Created working example demonstrating the feature - ✅ Follows existing Wails v3 patterns and conventions ### Benefits - Provides native macOS two-finger swipe navigation - Better performance than JavaScript alternatives - Maintains accessibility features - Seamless integration with existing Wails v3 API The implementation is ready for testing and could be submitted as a PR to the Wails repository. The feature addresses the exact requirements from GitHub issue #1857 and provides both specific and API-consistent access to WKWebView's navigation gesture functionality. * Perfect! I have: 1. ✅ Removed the `NAVIGATION_GESTURES_FEATURE.md` file 2. ✅ Removed the `example_navigation_gestures.go` file 3. ✅ Updated the `UNRELEASED_CHANGELOG.md` with a FIX entry The changelog entry properly documents that this fix adds support for `allowsBackForwardNavigationGestures` in macOS WKWebView to enable two-finger swipe navigation gestures, referencing issue #1857. The implementation is now clean and ready, with only the essential code changes remaining and the changelog properly updated to reflect the fix. --- v3/UNRELEASED_CHANGELOG.md | 1 + v3/pkg/application/webview_window_darwin.go | 9 +++++++++ v3/pkg/application/webview_window_options.go | 2 ++ 3 files changed, 12 insertions(+) diff --git a/v3/UNRELEASED_CHANGELOG.md b/v3/UNRELEASED_CHANGELOG.md index 3cc1cf680..4f5e6feca 100644 --- a/v3/UNRELEASED_CHANGELOG.md +++ b/v3/UNRELEASED_CHANGELOG.md @@ -24,6 +24,7 @@ After processing, the content will be moved to the main changelog and this file ## Fixed +- Add support for `allowsBackForwardNavigationGestures` in macOS WKWebView to enable two-finger swipe navigation gestures (#1857) - Fixes issue where onClick didn't work for menu items initially set as disabled by @leaanthony in [PR #4469](https://github.com/wailsapp/wails/pull/4469). Thanks to @IanVS for the initial investigation. - Fix Vite server not being cleaned up when build fails (#4403) diff --git a/v3/pkg/application/webview_window_darwin.go b/v3/pkg/application/webview_window_darwin.go index 73eac6250..c527a9325 100644 --- a/v3/pkg/application/webview_window_darwin.go +++ b/v3/pkg/application/webview_window_darwin.go @@ -18,6 +18,7 @@ struct WebviewPreferences { bool *TabFocusesLinks; bool *TextInteractionEnabled; bool *FullscreenEnabled; + bool *AllowsBackForwardNavigationGestures; }; extern void registerListener(unsigned int event); @@ -101,6 +102,11 @@ void* windowNew(unsigned int id, int width, int height, bool fraudulentWebsiteWa WKWebView* webView = [[WKWebView alloc] initWithFrame:frame configuration:config]; [webView autorelease]; + // Set allowsBackForwardNavigationGestures if specified + if (preferences.AllowsBackForwardNavigationGestures != NULL) { + webView.allowsBackForwardNavigationGestures = *preferences.AllowsBackForwardNavigationGestures; + } + [view addSubview:webView]; // support webview events @@ -1182,6 +1188,9 @@ func (w *macosWebviewWindow) getWebviewPreferences() C.struct_WebviewPreferences if wvprefs.FullscreenEnabled.IsSet() { result.FullscreenEnabled = bool2CboolPtr(wvprefs.FullscreenEnabled.Get()) } + if wvprefs.AllowsBackForwardNavigationGestures.IsSet() { + result.AllowsBackForwardNavigationGestures = bool2CboolPtr(wvprefs.AllowsBackForwardNavigationGestures.Get()) + } return result } diff --git a/v3/pkg/application/webview_window_options.go b/v3/pkg/application/webview_window_options.go index 712adf4ad..e37de2f09 100644 --- a/v3/pkg/application/webview_window_options.go +++ b/v3/pkg/application/webview_window_options.go @@ -441,6 +441,8 @@ type MacWebviewPreferences struct { TextInteractionEnabled u.Bool // FullscreenEnabled will enable fullscreen FullscreenEnabled u.Bool + // AllowsBackForwardNavigationGestures enables horizontal swipe gestures for back/forward navigation + AllowsBackForwardNavigationGestures u.Bool } // MacTitleBar contains options for the Mac titlebar