diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-15 03:34:42 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-15 03:34:42 +0000 |
commit | da4c7e7ed675c3bf405668739c3012d140856109 (patch) | |
tree | cdd868dba063fecba609a1d819de271f0d51b23e /mobile/android/android-components/components/compose/engine/src | |
parent | Adding upstream version 125.0.3. (diff) | |
download | firefox-da4c7e7ed675c3bf405668739c3012d140856109.tar.xz firefox-da4c7e7ed675c3bf405668739c3012d140856109.zip |
Adding upstream version 126.0.upstream/126.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'mobile/android/android-components/components/compose/engine/src')
4 files changed, 69 insertions, 0 deletions
diff --git a/mobile/android/android-components/components/compose/engine/src/main/AndroidManifest.xml b/mobile/android/android-components/components/compose/engine/src/main/AndroidManifest.xml new file mode 100644 index 0000000000..e16cda1d34 --- /dev/null +++ b/mobile/android/android-components/components/compose/engine/src/main/AndroidManifest.xml @@ -0,0 +1,4 @@ +<!-- This Source Code Form is subject to the terms of the Mozilla Public + - License, v. 2.0. If a copy of the MPL was not distributed with this + - file, You can obtain one at http://mozilla.org/MPL/2.0/. --> +<manifest /> diff --git a/mobile/android/android-components/components/compose/engine/src/main/java/mozilla/components/compose/engine/WebContent.kt b/mobile/android/android-components/components/compose/engine/src/main/java/mozilla/components/compose/engine/WebContent.kt new file mode 100644 index 0000000000..0d2bfb02f1 --- /dev/null +++ b/mobile/android/android-components/components/compose/engine/src/main/java/mozilla/components/compose/engine/WebContent.kt @@ -0,0 +1,62 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +package mozilla.components.compose.engine + +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.viewinterop.AndroidView +import mozilla.components.browser.state.action.EngineAction +import mozilla.components.browser.state.helper.Target +import mozilla.components.browser.state.store.BrowserStore +import mozilla.components.concept.engine.Engine +import mozilla.components.concept.engine.EngineView + +/** + * Composes an [EngineView] obtained from the given [Engine] and renders the web content of the + * [target] from the [store] on it. + */ +@Composable +fun WebContent( + engine: Engine, + store: BrowserStore, + target: Target, +) { + val selectedTab = target.observeAsComposableStateFrom( + store = store, + observe = { tab -> + // Render if the tab itself changed or when the state of the linked engine session changes + arrayOf( + tab?.id, + tab?.engineState?.engineSession, + tab?.engineState?.crashed, + tab?.content?.firstContentfulPaint, + ) + }, + ) + + AndroidView( + modifier = Modifier.fillMaxSize(), + factory = { context -> engine.createView(context).asView() }, + update = { view -> + val engineView = view as EngineView + + val tab = selectedTab.value + if (tab == null) { + engineView.release() + } else { + val session = tab.engineState.engineSession + if (session == null) { + // This tab does not have an EngineSession that we can render yet. Let's dispatch an + // action to request creating one. Once one was created and linked to this session, this + // method will get invoked again. + store.dispatch(EngineAction.CreateEngineSessionAction(tab.id)) + } else { + engineView.render(session) + } + } + }, + ) +} diff --git a/mobile/android/android-components/components/compose/engine/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/mobile/android/android-components/components/compose/engine/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker new file mode 100644 index 0000000000..cf1c399ea8 --- /dev/null +++ b/mobile/android/android-components/components/compose/engine/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker @@ -0,0 +1,2 @@ +mock-maker-inline +// This allows mocking final classes (classes are final by default in Kotlin) diff --git a/mobile/android/android-components/components/compose/engine/src/test/resources/robolectric.properties b/mobile/android/android-components/components/compose/engine/src/test/resources/robolectric.properties new file mode 100644 index 0000000000..932b01b9eb --- /dev/null +++ b/mobile/android/android-components/components/compose/engine/src/test/resources/robolectric.properties @@ -0,0 +1 @@ +sdk=28 |