From c953d0356f97149b04037f8afa7d05c4f036ba17 Mon Sep 17 00:00:00 2001 From: Chris Banes Date: Mon, 22 Feb 2021 17:24:52 +0000 Subject: [PATCH] Add workaround for https://issuetracker.google.com/180691023 --- .../app/tivi/account/AccountUiFragment.kt | 36 +++++++++++-------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/ui-account/src/main/java/app/tivi/account/AccountUiFragment.kt b/ui-account/src/main/java/app/tivi/account/AccountUiFragment.kt index c239fa885f..89380cd013 100644 --- a/ui-account/src/main/java/app/tivi/account/AccountUiFragment.kt +++ b/ui-account/src/main/java/app/tivi/account/AccountUiFragment.kt @@ -29,6 +29,7 @@ import androidx.compose.runtime.livedata.observeAsState import androidx.compose.ui.platform.ComposeView import androidx.fragment.app.DialogFragment import androidx.fragment.app.viewModels +import androidx.lifecycle.ViewTreeLifecycleOwner import androidx.navigation.fragment.findNavController import app.tivi.common.compose.LocalTiviDateFormatter import app.tivi.common.compose.shouldUseDarkColors @@ -70,22 +71,29 @@ class AccountUiFragment : DialogFragment() { inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? - ): View = ComposeView(requireContext()).apply { - layoutParams = ViewGroup.LayoutParams(MATCH_PARENT, WRAP_CONTENT) + ): View { + // Workaround for https://issuetracker.google.com/180691023 + dialog?.window?.decorView?.let { decorView -> + ViewTreeLifecycleOwner.set(decorView, viewLifecycleOwner) + } + + return ComposeView(requireContext()).apply { + layoutParams = ViewGroup.LayoutParams(MATCH_PARENT, WRAP_CONTENT) - // We use ViewWindowInsetObserver rather than ProvideWindowInsets - // See: https://github.com/chrisbanes/accompanist/issues/155 - val windowInsets = ViewWindowInsetObserver(this).start(consumeWindowInsets = false) + // We use ViewWindowInsetObserver rather than ProvideWindowInsets + // See: https://github.com/chrisbanes/accompanist/issues/155 + val windowInsets = ViewWindowInsetObserver(this).start(consumeWindowInsets = false) - setContent { - CompositionLocalProvider( - LocalTiviDateFormatter provides tiviDateFormatter, - LocalWindowInsets provides windowInsets, - ) { - TiviTheme(useDarkColors = preferences.shouldUseDarkColors()) { - val viewState by viewModel.liveData.observeAsState() - if (viewState != null) { - AccountUi(viewState!!, ::onAccountUiAction) + setContent { + CompositionLocalProvider( + LocalTiviDateFormatter provides tiviDateFormatter, + LocalWindowInsets provides windowInsets, + ) { + TiviTheme(useDarkColors = preferences.shouldUseDarkColors()) { + val viewState by viewModel.liveData.observeAsState() + if (viewState != null) { + AccountUi(viewState!!, ::onAccountUiAction) + } } } }