mirror of
https://github.com/wailsapp/wails.git
synced 2026-03-14 14:45:49 +01:00
Support allowsBackForwardNavigationGestures (#4453)
* ## 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.
This commit is contained in:
parent
a9222b538d
commit
ed81ab01e7
3 changed files with 12 additions and 0 deletions
|
|
@ -24,6 +24,7 @@ After processing, the content will be moved to the main changelog and this file
|
|||
|
||||
## Fixed
|
||||
<!-- Bug fixes -->
|
||||
- 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)
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue