Skip to content

Commit

Permalink
feat(android): apply navigation handler to loadUrl calls (#974)
Browse files Browse the repository at this point in the history
  • Loading branch information
jhutchins authored Jun 19, 2023
1 parent 5d08eb7 commit 4ab2a45
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .cargo/android-navigation-handler-improvements.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wry": "patch"
---

Make `WebViewBuilder::with_navigation_handler` apply to Android `loadUrl` calls.
18 changes: 16 additions & 2 deletions src/webview/android/kotlin/RustWebView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,25 @@ class RustWebView(context: Context): WebView(context) {

fun loadUrlMainThread(url: String) {
post {
super.loadUrl(url)
loadUrl(url)
}
}

fun loadUrlMainThread(url: String, additionalHttpHeaders: Map<String, String>) {
post {
super.loadUrl(url, additionalHttpHeaders)
loadUrl(url, additionalHttpHeaders)
}
}

override fun loadUrl(url: String) {
if (!shouldOverride(url)) {
super.loadUrl(url);
}
}

override fun loadUrl(url: String, additionalHttpHeaders: Map<String, String>) {
if (!shouldOverride(url)) {
super.loadUrl(url, additionalHttpHeaders);
}
}

Expand Down Expand Up @@ -61,5 +73,7 @@ class RustWebView(context: Context): WebView(context) {
settings.userAgentString = ua
}

private external fun shouldOverride(url: String): Boolean

{{class-extension}}
}
8 changes: 8 additions & 0 deletions src/webview/android/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@ macro_rules! android_binding {
[JString],
jboolean
);
android_fn!(
$domain,
$package,
RustWebView,
shouldOverride,
[JString],
jboolean
);
android_fn!($domain, $package, Ipc, ipc, [JString]);
android_fn!(
$domain,
Expand Down

0 comments on commit 4ab2a45

Please sign in to comment.