Skip to content

Commit

Permalink
[fix]: small Compose performance improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
F0x1d committed Jul 12, 2024
1 parent 034cf37 commit 7ef7939
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.compose.foundation.layout.consumeWindowInsets
import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.ViewCompositionStrategy
import com.f0x1d.logfox.arch.databinding.FragmentComposeBinding
import com.f0x1d.logfox.arch.ui.fragment.BaseFragment

Expand All @@ -18,8 +20,13 @@ abstract class BaseComposeFragment : BaseFragment<FragmentComposeBinding>() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

binding.composeView.setContent {
Content()
binding.composeView.apply {
consumeWindowInsets = false
setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed)

setContent {
this@BaseComposeFragment.Content()
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.view.View
import android.view.ViewGroup
import androidx.compose.foundation.layout.consumeWindowInsets
import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.ViewCompositionStrategy
import com.f0x1d.logfox.arch.databinding.FragmentComposeBinding
import com.f0x1d.logfox.arch.ui.fragment.BaseViewModelFragment
import com.f0x1d.logfox.arch.ui.snackbar
Expand All @@ -25,6 +26,7 @@ abstract class BaseComposeViewModelFragment<T : BaseViewModel> : BaseViewModelFr

binding.composeView.apply {
consumeWindowInsets = false
setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed)

setContent {
this@BaseComposeViewModelFragment.Content()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package com.f0x1d.logfox.feature.setup.ui.fragment.setup.compose

import androidx.compose.runtime.Immutable

data class SetupScreenState(
val showAdbDialog: Boolean = false,
val adbCommand: String = "",
)

@Immutable
data class SetupScreenListener(
val onRootClick: () -> Unit,
val onAdbClick: () -> Unit,
Expand Down

0 comments on commit 7ef7939

Please sign in to comment.