From 6993e88265c3a759916e5e9677cdf28351ca85d2 Mon Sep 17 00:00:00 2001 From: arkon Date: Sat, 7 May 2022 23:50:14 -0400 Subject: [PATCH] Adjust inset consumption in Compose controllers (fixes #7085) Co-authored-by: jobobby04 --- .../ui/base/controller/ComposeController.kt | 66 ++++++++++++------- 1 file changed, 42 insertions(+), 24 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/ComposeController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/ComposeController.kt index cc3926e67c..44f32c2446 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/ComposeController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/ComposeController.kt @@ -3,8 +3,10 @@ package eu.kanade.tachiyomi.ui.base.controller import android.os.Bundle import android.view.LayoutInflater import android.view.View +import androidx.compose.foundation.layout.consumeWindowInsets import androidx.compose.runtime.Composable import androidx.compose.ui.input.nestedscroll.NestedScrollConnection +import androidx.compose.ui.platform.ViewCompositionStrategy import androidx.compose.ui.platform.rememberNestedScrollInteropConnection import eu.kanade.presentation.theme.TachiyomiTheme import eu.kanade.tachiyomi.databinding.ComposeControllerBinding @@ -14,62 +16,78 @@ import nucleus.presenter.Presenter /** * Compose controller with a Nucleus presenter. */ -abstract class ComposeController

>(bundle: Bundle? = null) : NucleusController(bundle) { +abstract class ComposeController

>(bundle: Bundle? = null) : + NucleusController(bundle), + ComposeContentController { - override fun createBinding(inflater: LayoutInflater): ComposeControllerBinding = + override fun createBinding(inflater: LayoutInflater) = ComposeControllerBinding.inflate(inflater) override fun onViewCreated(view: View) { super.onViewCreated(view) - binding.root.setContent { - val nestedScrollInterop = rememberNestedScrollInteropConnection(binding.root) - TachiyomiTheme { - ComposeContent(nestedScrollInterop) + binding.root.apply { + consumeWindowInsets = false + setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed) + setContent { + val nestedScrollInterop = rememberNestedScrollInteropConnection(binding.root) + TachiyomiTheme { + ComposeContent(nestedScrollInterop) + } } } } - - @Composable abstract fun ComposeContent(nestedScrollInterop: NestedScrollConnection) } /** * Basic Compose controller without a presenter. */ -abstract class BasicComposeController : BaseController() { +abstract class BasicComposeController : + BaseController(), + ComposeContentController { - override fun createBinding(inflater: LayoutInflater): ComposeControllerBinding = + override fun createBinding(inflater: LayoutInflater) = ComposeControllerBinding.inflate(inflater) override fun onViewCreated(view: View) { super.onViewCreated(view) - binding.root.setContent { - val nestedScrollInterop = rememberNestedScrollInteropConnection(binding.root) - TachiyomiTheme { - ComposeContent(nestedScrollInterop) + binding.root.apply { + consumeWindowInsets = false + setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed) + setContent { + val nestedScrollInterop = rememberNestedScrollInteropConnection(binding.root) + TachiyomiTheme { + ComposeContent(nestedScrollInterop) + } } } } - - @Composable abstract fun ComposeContent(nestedScrollInterop: NestedScrollConnection) } -abstract class SearchableComposeController

>(bundle: Bundle? = null) : SearchableNucleusController(bundle) { +abstract class SearchableComposeController

>(bundle: Bundle? = null) : + SearchableNucleusController(bundle), + ComposeContentController { - override fun createBinding(inflater: LayoutInflater): ComposeControllerBinding = + override fun createBinding(inflater: LayoutInflater) = ComposeControllerBinding.inflate(inflater) override fun onViewCreated(view: View) { super.onViewCreated(view) - binding.root.setContent { - val nestedScrollInterop = rememberNestedScrollInteropConnection(binding.root) - TachiyomiTheme { - ComposeContent(nestedScrollInterop) + binding.root.apply { + consumeWindowInsets = false + setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed) + setContent { + val nestedScrollInterop = rememberNestedScrollInteropConnection(binding.root) + TachiyomiTheme { + ComposeContent(nestedScrollInterop) + } } } } - - @Composable abstract fun ComposeContent(nestedScrollInterop: NestedScrollConnection) +} + +interface ComposeContentController { + @Composable fun ComposeContent(nestedScrollInterop: NestedScrollConnection) }