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
This commit is contained in:
topjohnwu
2026-08-20 21:36:49 +00:00
committed by John Wu
parent 5262ecdf82
commit c578a9632b
@@ -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)
}