-
-
Notifications
You must be signed in to change notification settings - Fork 771
Migrate WebViews activities to Jetpack Compose #5419
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 10 commits
857cb8d
650c7bf
0de35c7
6c5cd2e
1b6597d
eba7f4b
30c5706
5e6b373
88c0475
19bf320
3bb0a83
d9e6f3e
f53f785
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package io.homeassistant.companion.android.util.compose.webview | ||
|
||
import android.webkit.WebView | ||
import android.widget.FrameLayout | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.viewinterop.AndroidView | ||
|
||
/** | ||
* A composable that displays a WebView. | ||
* | ||
* This function provides a convenient way to embed a WebView in a Jetpack Compose UI. | ||
* It allows for customization of the WebView through the `configure` lambda, | ||
* and provides a callback for when the WebView is released via the `onRelease` lambda. | ||
* | ||
* @param modifier The modifier to be applied to the WebView. | ||
* @param configure A lambda that allows for configuration of the WebView instance. | ||
* This is called when the WebView is created. | ||
* @param factory A lambda that creates the WebView instance. If this returns null, a new | ||
* WebView will be created with the current context. | ||
*/ | ||
@Composable | ||
fun HAWebView( | ||
modifier: Modifier = Modifier, | ||
configure: WebView.() -> Unit = {}, | ||
factory: () -> WebView? = { null }, | ||
) { | ||
AndroidView( | ||
factory = { context -> | ||
(factory() ?: WebView(context)).apply { | ||
// We want the modifier to determine the size so the WebView should match the parent | ||
this.layoutParams = FrameLayout.LayoutParams( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Today, I discovered that this |
||
FrameLayout.LayoutParams.MATCH_PARENT, | ||
FrameLayout.LayoutParams.MATCH_PARENT | ||
) | ||
|
||
configure(this) | ||
} | ||
}, | ||
modifier = modifier, | ||
) | ||
} |
Uh oh!
There was an error while loading. Please reload this page.