From 139d617a6e757b993526c25e87255f0d42984dbd Mon Sep 17 00:00:00 2001 From: ashiagr Date: Fri, 17 Feb 2023 19:16:18 +0530 Subject: [PATCH] Set compose view composition strategy --- .../pocketcasts/search/SearchFragment.kt | 34 +++++++++++-------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/modules/features/search/src/main/java/au/com/shiftyjelly/pocketcasts/search/SearchFragment.kt b/modules/features/search/src/main/java/au/com/shiftyjelly/pocketcasts/search/SearchFragment.kt index e1be6dc671e..48988d480a8 100644 --- a/modules/features/search/src/main/java/au/com/shiftyjelly/pocketcasts/search/SearchFragment.kt +++ b/modules/features/search/src/main/java/au/com/shiftyjelly/pocketcasts/search/SearchFragment.kt @@ -10,6 +10,7 @@ import android.view.View import android.view.ViewGroup import android.view.inputmethod.EditorInfo import androidx.appcompat.widget.SearchView +import androidx.compose.ui.platform.ViewCompositionStrategy import androidx.fragment.app.viewModels import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView @@ -243,21 +244,24 @@ class SearchFragment : BaseFragment() { recyclerView.itemAnimator = null recyclerView.addOnScrollListener(onScrollListener) - binding.searchHistoryPanel.setContent { - AppTheme(theme.activeTheme) { - SearchHistoryPage( - viewModel = searchHistoryViewModel, - onClick = ::navigateFromSearchHistoryEntry, - onShowClearAllConfirmation = { - SearchHistoryClearAllConfirmationDialog( - context = this@SearchFragment.requireContext(), - onConfirm = { searchHistoryViewModel.clearAll() } - ).show(parentFragmentManager, SEARCH_HISTORY_CLEAR_ALL_CONFIRMATION_DIALOG_TAG) - }, - onScroll = { UiUtil.hideKeyboard(recyclerView) } - ) - if (viewModel.isFragmentChangingConfigurations && viewModel.showSearchHistory) { - binding.searchHistoryPanel.show() + binding.searchHistoryPanel.apply { + ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed + setContent { + AppTheme(theme.activeTheme) { + SearchHistoryPage( + viewModel = searchHistoryViewModel, + onClick = ::navigateFromSearchHistoryEntry, + onShowClearAllConfirmation = { + SearchHistoryClearAllConfirmationDialog( + context = this@SearchFragment.requireContext(), + onConfirm = { searchHistoryViewModel.clearAll() } + ).show(parentFragmentManager, SEARCH_HISTORY_CLEAR_ALL_CONFIRMATION_DIALOG_TAG) + }, + onScroll = { UiUtil.hideKeyboard(recyclerView) } + ) + if (viewModel.isFragmentChangingConfigurations && viewModel.showSearchHistory) { + binding.searchHistoryPanel.show() + } } } }