Skip to content

Commit

Permalink
Set view composition strategy in DreamServiceCompat
Browse files Browse the repository at this point in the history
  • Loading branch information
nielsvanvelzen committed May 4, 2024
1 parent 5ef7bbc commit 723e838
Showing 1 changed file with 3 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.service.dreams.DreamService
import androidx.annotation.CallSuper
import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.platform.ViewCompositionStrategy
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleRegistry
import androidx.lifecycle.setViewTreeLifecycleOwner
Expand Down Expand Up @@ -46,6 +47,8 @@ abstract class DreamServiceCompat : DreamService(), SavedStateRegistryOwner {

fun setContent(content: @Composable () -> Unit) {
val view = ComposeView(this)
// Set composition strategy
view.setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed)

// Inject dependencies normally added by appcompat activities
view.setViewTreeLifecycleOwner(this)
Expand Down

0 comments on commit 723e838

Please sign in to comment.