From 4eb2b4c368c963324ad4344d946c6341de47c1ee Mon Sep 17 00:00:00 2001 From: Melad Raouf Date: Mon, 13 Oct 2025 10:49:53 +0100 Subject: [PATCH] [MS-1200] Refactor RecyclerView height adjustment to use lifecycle-aware coroutine --- .../settings/syncinfo/SyncInfoFragment.kt | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/feature/dashboard/src/main/java/com/simprints/feature/dashboard/settings/syncinfo/SyncInfoFragment.kt b/feature/dashboard/src/main/java/com/simprints/feature/dashboard/settings/syncinfo/SyncInfoFragment.kt index bb5c777d72..f156178d1c 100644 --- a/feature/dashboard/src/main/java/com/simprints/feature/dashboard/settings/syncinfo/SyncInfoFragment.kt +++ b/feature/dashboard/src/main/java/com/simprints/feature/dashboard/settings/syncinfo/SyncInfoFragment.kt @@ -352,12 +352,14 @@ internal class SyncInfoFragment : Fragment(R.layout.fragment_sync_info) { moduleCountAdapter.submitList(moduleCountsForAdapter) // RecyclerView height fix (wrong height may be caused by ConstraintLayout in parent views) - binding.selectedModulesView.post { - val itemHeight = resources.getDimensionPixelSize(R.dimen.module_item_height) - val itemCount = moduleCountsForAdapter.size.coerceAtMost(MAX_MODULE_LIST_HEIGHT_ITEMS) - binding.selectedModulesView.apply { - layoutParams = layoutParams.apply { - height = itemHeight * itemCount + viewLifecycleOwner.lifecycleScope.launch { + viewLifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) { + val itemHeight = resources.getDimensionPixelSize(R.dimen.module_item_height) + val itemCount = moduleCountsForAdapter.size.coerceAtMost(MAX_MODULE_LIST_HEIGHT_ITEMS) + binding.selectedModulesView.apply { + layoutParams = layoutParams.apply { + height = itemHeight * itemCount + } } } }