Skip to content

Commit

Permalink
fix(android): convert color to argb in rust (#1237)
Browse files Browse the repository at this point in the history
  • Loading branch information
amrbashir committed Apr 30, 2024
1 parent 203604c commit 8bbc2bf
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
5 changes: 5 additions & 0 deletions .changes/android-transparent.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wry": "patch"
---

Fix `WebviewBuilder::with_transparent`, `WebviewBuilder::with_background_color`, and `Webview::set_background_color` always failing and causing the webview to fail to load.
17 changes: 3 additions & 14 deletions src/android/main_pipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,21 +348,10 @@ fn load_html<'a>(env: &mut JNIEnv<'a>, webview: &JObject<'a>, html: &JString<'a>
fn set_background_color<'a>(
env: &mut JNIEnv<'a>,
webview: &JObject<'a>,
background_color: RGBA,
(r, g, b, a): RGBA,
) -> JniResult<()> {
let color_class = env.find_class("android/graphics/Color")?;
let color = env.call_static_method(
color_class,
"argb",
"(IIII)I",
&[
background_color.3.into(),
background_color.0.into(),
background_color.1.into(),
background_color.2.into(),
],
)?;
env.call_method(webview, "setBackgroundColor", "(I)V", &[color.borrow()])?;
let color = (a as i32) << 24 | (r as i32) << 16 | (g as i32) << 8 | (b as i32);
env.call_method(webview, "setBackgroundColor", "(I)V", &[color.into()])?;
Ok(())
}

Expand Down

0 comments on commit 8bbc2bf

Please sign in to comment.