-
-
Notifications
You must be signed in to change notification settings - Fork 844
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
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
857cb8d
Introduce HAWebView small wrapper around WebView and AndroidView
TimoPtr 650c7bf
Add callback onFullscreenClicked in HAMediaPlayer
TimoPtr 0de35c7
Migrate MyActivity to Jetpack Compose
TimoPtr 6c5cd2e
Make AuthenticationFragment uses HAWebView
TimoPtr 1b6597d
Add Haze dependency for bluring
TimoPtr eba7f4b
Migrate WebViewActivity to Jetpack Compose
TimoPtr 30c5706
Update lint baseline and disable UsingMaterialAndMaterial3Libraries rule
TimoPtr 5e6b373
Fix KTLint
TimoPtr 88c0475
Move disabled rule to each module since wear doesn't have the rule
TimoPtr 19bf320
Merge branch 'main' into feature/compose-webview
TimoPtr 3bb0a83
Merge branch 'main' into feature/compose-webview
TimoPtr d9e6f3e
Apply comments
TimoPtr f53f785
Replace usage of GlobalScope with lifecycleScope in WebViewActivity
TimoPtr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Binary file added
BIN
+15.2 KB
...ndroid/webview/WebViewContentScreenScreenshotTest/WebView with app locked_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+18.5 KB
...roid/webview/WebViewContentScreenScreenshotTest/WebView with app unlocked_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+22.5 KB
...on/android/webview/WebViewContentScreenScreenshotTest/WebView with player_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
app/src/main/kotlin/io/homeassistant/companion/android/util/compose/webview/HAWebView.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| 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. | ||
| * | ||
| * The WebView will be sized to match the [modifier]. | ||
| * | ||
| * @param factory A lambda that creates the WebView instance. If this returns null, a new | ||
| * WebView will be created with the current context. This is useful for providing | ||
| * a pre-configured WebView instance. | ||
| */ | ||
| @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( | ||
| FrameLayout.LayoutParams.MATCH_PARENT, | ||
| FrameLayout.LayoutParams.MATCH_PARENT, | ||
| ) | ||
|
|
||
| configure(this) | ||
| } | ||
| }, | ||
| modifier = modifier, | ||
| ) | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Today, I discovered that this
this.layoutParams = [...]with match parent causes Webview to set correct CSSenv(safe-area-insets-*)values. I tested it on webview 137, on 119 it is not working.But I am not sure if it really matters because it's not very stable or/and documented.