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