From 6c79317662c38cd1ee3bee3742b0601ea6269929 Mon Sep 17 00:00:00 2001 From: Stojan Anastasov Date: Thu, 3 Oct 2024 13:47:19 +0200 Subject: [PATCH] Revert "Use fragment-compose content" This reverts commit 42f4e3de37bc318afe0b586a296abe33001d9c10. --- app/build.gradle | 1 - .../superherodetails/SuperheroDetailsFragment.kt | 11 +++++++---- .../superheroes/superheroslist/SuperheroesFragment.kt | 11 +++++++---- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index f84844c4..4db0ea85 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -88,7 +88,6 @@ dependencies { implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle" implementation "androidx.lifecycle:lifecycle-runtime-compose:$lifecycle" implementation 'androidx.fragment:fragment-ktx:1.8.0' - implementation 'androidx.fragment:fragment-compose:1.8.0' def nav_version = "2.7.7" implementation "androidx.navigation:navigation-fragment-ktx:$nav_version" implementation "androidx.navigation:navigation-ui-ktx:$nav_version" diff --git a/app/src/main/java/io/github/lordraydenmk/superheroesapp/superheroes/superherodetails/SuperheroDetailsFragment.kt b/app/src/main/java/io/github/lordraydenmk/superheroesapp/superheroes/superherodetails/SuperheroDetailsFragment.kt index edb0116b..09c5708c 100644 --- a/app/src/main/java/io/github/lordraydenmk/superheroesapp/superheroes/superherodetails/SuperheroDetailsFragment.kt +++ b/app/src/main/java/io/github/lordraydenmk/superheroesapp/superheroes/superherodetails/SuperheroDetailsFragment.kt @@ -2,9 +2,10 @@ package io.github.lordraydenmk.superheroesapp.superheroes.superherodetails import android.os.Bundle import android.view.View +import androidx.compose.ui.platform.ComposeView +import androidx.compose.ui.platform.ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed import androidx.fragment.app.Fragment import androidx.fragment.app.viewModels -import androidx.fragment.compose.content import androidx.lifecycle.Lifecycle.State import androidx.lifecycle.lifecycleScope import androidx.lifecycle.repeatOnLifecycle @@ -32,6 +33,8 @@ class SuperheroDetailsFragment : Fragment(R.layout.fragment_compose) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) + val composeView = view as ComposeView + composeView.setViewCompositionStrategy(DisposeOnViewTreeLifecycleDestroyed) val module = object : SuperheroDetailsModule, AppModule by requireActivity().appModule(), @@ -39,10 +42,8 @@ class SuperheroDetailsFragment : Fragment(R.layout.fragment_compose) { val actions = Channel(Channel.UNLIMITED) - handleEffects() - with(module) { - content { + composeView.setContent { SuperheroDetailsScreen( stateFlow = viewState, initialState = Loading, @@ -57,6 +58,8 @@ class SuperheroDetailsFragment : Fragment(R.layout.fragment_compose) { } } } + + handleEffects() } private fun handleEffects() { diff --git a/app/src/main/java/io/github/lordraydenmk/superheroesapp/superheroes/superheroslist/SuperheroesFragment.kt b/app/src/main/java/io/github/lordraydenmk/superheroesapp/superheroes/superheroslist/SuperheroesFragment.kt index e00034c5..dcaee4b6 100644 --- a/app/src/main/java/io/github/lordraydenmk/superheroesapp/superheroes/superheroslist/SuperheroesFragment.kt +++ b/app/src/main/java/io/github/lordraydenmk/superheroesapp/superheroes/superheroslist/SuperheroesFragment.kt @@ -2,9 +2,10 @@ package io.github.lordraydenmk.superheroesapp.superheroes.superheroslist import android.os.Bundle import android.view.View +import androidx.compose.ui.platform.ComposeView +import androidx.compose.ui.platform.ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed import androidx.fragment.app.Fragment import androidx.fragment.app.viewModels -import androidx.fragment.compose.content import androidx.lifecycle.Lifecycle import androidx.lifecycle.lifecycleScope import androidx.lifecycle.repeatOnLifecycle @@ -26,6 +27,8 @@ class SuperheroesFragment : Fragment(R.layout.fragment_compose) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) + val composeView = view as ComposeView + composeView.setViewCompositionStrategy(DisposeOnViewTreeLifecycleDestroyed) val module: SuperheroesModule = object : SuperheroesModule, AppModule by requireActivity().appModule(), @@ -33,10 +36,8 @@ class SuperheroesFragment : Fragment(R.layout.fragment_compose) { val actions = Channel(Channel.UNLIMITED) - handleEffects() - with(module) { - content { + composeView.setContent { SuperheroesScreen( stateFlow = viewState, initialValue = Loading, @@ -50,6 +51,8 @@ class SuperheroesFragment : Fragment(R.layout.fragment_compose) { } } } + + handleEffects() } private fun handleEffects() {