From 75be749830cf429b59147558ac734addceca7bbe Mon Sep 17 00:00:00 2001 From: Laimonas Turauskas Date: Thu, 5 Dec 2024 14:41:23 -0500 Subject: [PATCH] [Compose] Set the correct view composition strategy. --- .../instacart/formula/android/compose/ComposeViewFactory.kt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/formula-android-compose/src/main/java/com/instacart/formula/android/compose/ComposeViewFactory.kt b/formula-android-compose/src/main/java/com/instacart/formula/android/compose/ComposeViewFactory.kt index 2f6cf898..7174d8e1 100644 --- a/formula-android-compose/src/main/java/com/instacart/formula/android/compose/ComposeViewFactory.kt +++ b/formula-android-compose/src/main/java/com/instacart/formula/android/compose/ComposeViewFactory.kt @@ -5,6 +5,7 @@ import android.view.ViewGroup import androidx.compose.runtime.Composable import androidx.compose.runtime.rxjava3.subscribeAsState import androidx.compose.ui.platform.ComposeView +import androidx.compose.ui.platform.ViewCompositionStrategy import com.instacart.formula.android.FeatureView import com.instacart.formula.android.ViewFactory import com.jakewharton.rxrelay3.BehaviorRelay @@ -14,6 +15,9 @@ abstract class ComposeViewFactory : ViewFactory override fun create(inflater: LayoutInflater, container: ViewGroup?): FeatureView { val view = ComposeView(inflater.context) + // Based-on: https://developer.android.com/develop/ui/compose/migrate/interoperability-apis/compose-in-views#compose-in-fragments + view.setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed) + val outputRelay = BehaviorRelay.create() view.setContent { val model = outputRelay.subscribeAsState(null).value