Skip to content

Commit 1fc98b6

Browse files
committed
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
1 parent c7e3ae5 commit 1fc98b6

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

app/apk-ng/src/main/java/com/topjohnwu/magisk/ui/MainScreen.kt

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,14 @@ fun MainScreen(initialTab: Int = Tab.HOME.ordinal) {
9999
beyondViewportPageCount = visibleTabs.size - 1,
100100
userScrollEnabled = true,
101101
) { page ->
102+
val isCurrentPage = pagerState.currentPage == page
102103
when (visibleTabs[page]) {
103104
Tab.HOME -> {
104105
val vm: HomeViewModel = viewModel(factory = VMFactory)
105106
val installVm: InstallViewModel = viewModel(factory = VMFactory)
106-
LaunchedEffect(Unit) { vm.startLoading() }
107+
LaunchedEffect(isCurrentPage) {
108+
if (isCurrentPage) vm.startLoading()
109+
}
107110
CollectNavEvents(vm, navigator)
108111
CollectNavEvents(installVm, navigator)
109112
HomeScreen(vm, installVm)
@@ -115,18 +118,24 @@ fun MainScreen(initialTab: Int = Tab.HOME.ordinal) {
115118
vm.authenticate = { onSuccess ->
116119
activity.extension.withAuthentication { if (it) onSuccess() }
117120
}
118-
vm.startLoading()
121+
}
122+
LaunchedEffect(isCurrentPage) {
123+
if (isCurrentPage) vm.startLoading()
119124
}
120125
SuperuserScreen(vm)
121126
}
122127
Tab.LOG -> {
123128
val vm: LogViewModel = viewModel(factory = VMFactory)
124-
LaunchedEffect(Unit) { vm.startLoading() }
129+
LaunchedEffect(isCurrentPage) {
130+
if (isCurrentPage) vm.startLoading()
131+
}
125132
LogScreen(vm)
126133
}
127134
Tab.MODULES -> {
128135
val vm: ModuleViewModel = viewModel(factory = VMFactory)
129-
LaunchedEffect(Unit) { vm.startLoading() }
136+
LaunchedEffect(isCurrentPage) {
137+
if (isCurrentPage) vm.startLoading()
138+
}
130139
CollectNavEvents(vm, navigator)
131140
ModuleScreen(vm)
132141
}

0 commit comments

Comments
 (0)