Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何使用Jetpack Compose AdapterList保持滚动位置?_Android_Kotlin_Android Jetpack Compose - Fatal编程技术网

Android 如何使用Jetpack Compose AdapterList保持滚动位置?

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

我有一个用Jetpack Compose构建的列表详细流程的应用程序。从详细信息视图返回列表视图时,我希望保留滚动位置

根据模型状态交换曲面:

@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团队将在后续版本中添加它。