Skip to content

Commit

Permalink
Add the ability to navigate with swipe gesture (#757)
Browse files Browse the repository at this point in the history
* Add the ability to navigate with swipe gesture

On macOS, add an API to enable or disable
backward and forward navigation gestures.

For details, see <https://developer.apple.com/documentation/webkit/wkwebview/1414995-allowsbackforwardnavigationgestu>

Signed-off-by: pan93412 <[email protected]>

* Update .changes/allow-back-forward-gesture.md

Signed-off-by: pan93412 <[email protected]>
  • Loading branch information
pan93412 authored Nov 16, 2022
1 parent cf32c71 commit 487dff0
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changes/allow-back-forward-gesture.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wry": minor
---

On macOS, add an API to enable or disable backward and forward navigation gestures.
20 changes: 20 additions & 0 deletions src/webview/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,14 @@ pub struct WebViewAttributes {
///
/// This configuration only impacts macOS.
pub accept_first_mouse: bool,

/// Indicates whether horizontal swipe gestures trigger backward and forward page navigation.
///
/// ## Platform-specific
///
/// This configuration only impacts macOS.
/// [Documentation](https://developer.apple.com/documentation/webkit/wkwebview/1414995-allowsbackforwardnavigationgestu).
pub back_forward_navigation_gestures: bool,
}

impl Default for WebViewAttributes {
Expand All @@ -241,6 +249,7 @@ impl Default for WebViewAttributes {
devtools: false,
zoom_hotkeys_enabled: false,
accept_first_mouse: false,
back_forward_navigation_gestures: false,
}
}
}
Expand Down Expand Up @@ -295,6 +304,17 @@ impl<'a> WebViewBuilder<'a> {
})
}

/// Indicates whether horizontal swipe gestures trigger backward and forward page navigation.
///
/// ## Platform-specific
///
/// This configuration only impacts macOS.
/// [Documentation](https://developer.apple.com/documentation/webkit/wkwebview/1414995-allowsbackforwardnavigationgestu).
pub fn with_back_forward_navigation_gestures(mut self, gesture: bool) -> Self {
self.webview.back_forward_navigation_gestures = gesture;
self
}

/// Sets whether the WebView should be transparent.
///
/// ## Platform-specific:
Expand Down
7 changes: 7 additions & 0 deletions src/webview/wkwebview/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,13 @@ impl InnerWebView {
let _: () = msg_send![webview, initWithFrame:frame configuration:config];
}

// allowsBackForwardNavigation
#[cfg(target_os = "macos")]
{
let value = attributes.back_forward_navigation_gestures;
let _: () = msg_send![webview, setAllowsBackForwardNavigationGestures: value];
}

// Message handler
let ipc_handler_ptr = if let Some(ipc_handler) = attributes.ipc_handler {
let cls = ClassDecl::new("WebViewDelegate", class!(NSObject));
Expand Down

0 comments on commit 487dff0

Please sign in to comment.