@@ -27,10 +27,14 @@ import androidx.compose.material3.pulltorefresh.rememberPullToRefreshState
2727import androidx.compose.runtime.Composable
2828import androidx.compose.runtime.CompositionLocalProvider
2929import androidx.compose.runtime.DisposableEffect
30+ import androidx.compose.runtime.LaunchedEffect
3031import androidx.compose.runtime.collectAsState
3132import androidx.compose.runtime.getValue
33+ import androidx.compose.runtime.mutableIntStateOf
3234import androidx.compose.runtime.mutableStateOf
3335import androidx.compose.runtime.remember
36+ import androidx.compose.runtime.saveable.LocalSaveableStateRegistry
37+ import androidx.compose.runtime.saveable.rememberSaveable
3438import androidx.compose.runtime.setValue
3539import androidx.compose.ui.Alignment
3640import androidx.compose.ui.Modifier
@@ -42,7 +46,9 @@ import androidx.compose.ui.semantics.stateDescription
4246import androidx.compose.ui.text.style.TextOverflow
4347import androidx.compose.ui.unit.dp
4448import androidx.lifecycle.viewmodel.compose.viewModel
49+ import kotlinx.coroutines.flow.drop
4550import kotlinx.coroutines.flow.update
51+ import kotlinx.coroutines.launch
4652import li.songe.gkd.MainActivity
4753import li.songe.gkd.R
4854import li.songe.gkd.data.AppInfo
@@ -75,6 +81,7 @@ import li.songe.gkd.ui.style.EmptyHeight
7581import li.songe.gkd.ui.style.appItemPadding
7682import li.songe.gkd.util.AppGroupOption
7783import li.songe.gkd.util.AppSortOption
84+ import li.songe.gkd.util.LogUtils
7885import li.songe.gkd.util.appListAuthAbnormalFlow
7986import li.songe.gkd.util.getUpDownTransform
8087import li.songe.gkd.util.ruleSummaryFlow
@@ -98,12 +105,33 @@ fun useAppListPage(): ScaffoldExt {
98105 } else {
99106 null
100107 }
101- val appListKey by mainVm.appListKeyFlow.collectAsState()
102108 val showSearchBar by vm.showSearchBarFlow.collectAsState()
103- val (scrollBehavior, listState) = useListScrollState(appListKey)
104109 val refreshing by updateAppMutex.state.collectAsState()
105110 val pullToRefreshState = rememberPullToRefreshState()
106111 val editWhiteListMode by vm.editWhiteListModeFlow.collectAsState()
112+ val savedStateRegistry = LocalSaveableStateRegistry .current
113+ if (savedStateRegistry != null ) {
114+ LogUtils .d(savedStateRegistry.performSave())
115+ }
116+ val scrollKey = rememberSaveable { mutableIntStateOf(0 ) }
117+ val (scrollBehavior, listState) = useListScrollState(scrollKey)
118+ LaunchedEffect (null ) {
119+ listOf (
120+ canQueryPkgState.stateFlow,
121+ vm.appInfosFlow,
122+ ).forEach {
123+ launch {
124+ it.drop(1 ).collect {
125+ scrollKey.intValue++
126+ }
127+ }
128+ }
129+ mainVm.resetPageScrollEvent.collect {
130+ if (it == BottomNavItem .AppList ) {
131+ scrollKey.intValue++
132+ }
133+ }
134+ }
107135 return ScaffoldExt (
108136 navItem = BottomNavItem .AppList ,
109137 modifier = Modifier .nestedScroll(scrollBehavior.nestedScrollConnection),
@@ -134,7 +162,7 @@ fun useAppListPage(): ScaffoldExt {
134162 val titleModifier = Modifier
135163 .noRippleClickable(
136164 onClick = throttle {
137- mainVm.appListKeyFlow.update { it + 1 }
165+ scrollKey.intValue ++
138166 }
139167 )
140168 if (editWhiteListMode) {
0 commit comments