Skip to content
This repository has been archived by the owner on Nov 12, 2024. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbanes committed Feb 22, 2021
1 parent a04b909 commit c953d03
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions ui-account/src/main/java/app/tivi/account/AccountUiFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}
}
}
Expand Down

0 comments on commit c953d03

Please sign in to comment.