Android 如何使用Jetpack Compose AdapterList保持滚动位置?
我有一个用Jetpack Compose构建的列表详细流程的应用程序。从详细信息视图返回列表视图时,我希望保留滚动位置 根据模型状态交换曲面:Android 如何使用Jetpack Compose AdapterList保持滚动位置?,android,kotlin,android-jetpack-compose,Android,Kotlin,Android Jetpack Compose,我有一个用Jetpack Compose构建的列表详细流程的应用程序。从详细信息视图返回列表视图时,我希望保留滚动位置 根据模型状态交换曲面: @Composable private fun AppContent() { val scrollerPosition = ScrollerPosition() Crossfade(State.currentScreen) { screen -> Surface(color = MaterialTheme.color
@Composable
private fun AppContent() {
val scrollerPosition = ScrollerPosition()
Crossfade(State.currentScreen) { screen ->
Surface(color = MaterialTheme.colors.background) {
when (screen) {
is Screen.List -> ListScreen(scrollerPosition)
is Screen.Details -> DetailsScreen(screen.transaction)
is Screen.New -> NewScreen()
}
}
}
}
ListScreen以前有一个垂直滚动条,我给它一个滚动位置,以便在屏幕更改后保留该位置。但是,此解决方案不适用于AdapterList
过去是这样的:
@Composable
private fun TransactionsList(modifier: Modifier, scrollerPosition: ScrollerPosition) {
Box(modifier = modifier.fillMaxSize().wrapContentSize(Alignment.Center)) {
VerticalScroller(scrollerPosition = scrollerPosition) {
AdapterList(State.transactions, itemCallback = { transaction ->
TransactionListRow(transaction)
ListDivider()
})
}
}
}
如何使AdapterList保持滚动位置
@Composable
private fun TransactionsList(modifier: Modifier, scrollerPosition: ScrollerPosition) {
Box(modifier = modifier.fillMaxSize().wrapContentSize(Alignment.Center)) {
AdapterList(State.transactions, itemCallback = { transaction ->
TransactionListRow(transaction)
ListDivider()
})
}
}
目前(dev13)不可能,但compose团队将在后续版本中添加它。