From c578a9632b85704c99645c5e2d1f66fcc4c874e3 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Wed, 19 Aug 2026 11:25:56 -0700 Subject: [PATCH] app: reload tabs when selected in apk-ng Because HorizontalPager pre-renders all tab composables, LaunchedEffect with a Unit key was only executing once on initial creation. As a result, changes to configuration (e.g. update channel) calling resetUpdate() did not trigger a reload when returning to the Home tab, causing the install/reinstall dialog to display an empty changelog. Trigger startLoading() whenever a tab becomes active (isCurrentPage). Assisted-by: Gemini 3.7 Flash --- .../java/com/topjohnwu/magisk/ui/MainScreen.kt | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/app/apk-ng/src/main/java/com/topjohnwu/magisk/ui/MainScreen.kt b/app/apk-ng/src/main/java/com/topjohnwu/magisk/ui/MainScreen.kt index 282f35869..1337a639b 100644 --- a/app/apk-ng/src/main/java/com/topjohnwu/magisk/ui/MainScreen.kt +++ b/app/apk-ng/src/main/java/com/topjohnwu/magisk/ui/MainScreen.kt @@ -99,11 +99,14 @@ fun MainScreen(initialTab: Int = Tab.HOME.ordinal) { beyondViewportPageCount = visibleTabs.size - 1, userScrollEnabled = true, ) { page -> + val isCurrentPage = pagerState.currentPage == page when (visibleTabs[page]) { Tab.HOME -> { val vm: HomeViewModel = viewModel(factory = VMFactory) val installVm: InstallViewModel = viewModel(factory = VMFactory) - LaunchedEffect(Unit) { vm.startLoading() } + LaunchedEffect(isCurrentPage) { + if (isCurrentPage) vm.startLoading() + } CollectNavEvents(vm, navigator) CollectNavEvents(installVm, navigator) HomeScreen(vm, installVm) @@ -115,18 +118,24 @@ fun MainScreen(initialTab: Int = Tab.HOME.ordinal) { vm.authenticate = { onSuccess -> activity.extension.withAuthentication { if (it) onSuccess() } } - vm.startLoading() + } + LaunchedEffect(isCurrentPage) { + if (isCurrentPage) vm.startLoading() } SuperuserScreen(vm) } Tab.LOG -> { val vm: LogViewModel = viewModel(factory = VMFactory) - LaunchedEffect(Unit) { vm.startLoading() } + LaunchedEffect(isCurrentPage) { + if (isCurrentPage) vm.startLoading() + } LogScreen(vm) } Tab.MODULES -> { val vm: ModuleViewModel = viewModel(factory = VMFactory) - LaunchedEffect(Unit) { vm.startLoading() } + LaunchedEffect(isCurrentPage) { + if (isCurrentPage) vm.startLoading() + } CollectNavEvents(vm, navigator) ModuleScreen(vm) }