Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix(android): delay WebView#loadUrl call #683

Merged
merged 1 commit into from
Sep 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/webview/android/kotlin/RustWebView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,20 @@ package {{app-domain-reversed}}.{{app-name-snake-case}}

import android.webkit.*
import android.content.Context
import android.os.Handler
import android.os.Looper

class RustWebView(context: Context): WebView(context) {
init {
this.settings.javaScriptEnabled = true
{{class-init}}
}

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

{{class-extension}}
}
7 changes: 6 additions & 1 deletion src/webview/android/main_pipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,12 @@ impl MainPipe<'_> {

// Load URL
if let Ok(url) = env.new_string(url) {
env.call_method(webview, "loadUrl", "(Ljava/lang/String;)V", &[url.into()])?;
env.call_method(
webview,
"loadUrlMainThread",
"(Ljava/lang/String;)V",
&[url.into()],
)?;
}

// Enable devtools
Expand Down