最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How disable scrolling for a single column in a row under certain conditions in Jetpack Compose? - Stack Overflow

programmeradmin2浏览0评论

I have a complex dialog with multiple scrollable sections. The left panel should remain non-scrollable until the right panel is fully scrolled to the bottom. Once the right panel reaches the bottom, both panels should scroll together, and the bottom content should then appear. How can I implement this behavior?

Here is code example:

@Composable
fun DialogScreen(
    // params
) {
    // ...
    val subscriptionCardsScrollState = rememberScrollState()

    Box {

        Column(
            modifier = Modifier
                .verticalScroll(state = subscriptionCardsScrollState),
        ) {
            Row {
                RightPanel(
                    modifier = Modifier
                        .scrollable(
                            enabled = false,
                            state = subscriptionCardsScrollState,
                            orientation = Orientation.Vertical,
                        ),
                )

                LeftPanel(
                    modifier = Modifier,
                )
            }

            // bottom content
        }
    }
}

Here is a picture that illustrates an example of how the screen looks:

I have a complex dialog with multiple scrollable sections. The left panel should remain non-scrollable until the right panel is fully scrolled to the bottom. Once the right panel reaches the bottom, both panels should scroll together, and the bottom content should then appear. How can I implement this behavior?

Here is code example:

@Composable
fun DialogScreen(
    // params
) {
    // ...
    val subscriptionCardsScrollState = rememberScrollState()

    Box {

        Column(
            modifier = Modifier
                .verticalScroll(state = subscriptionCardsScrollState),
        ) {
            Row {
                RightPanel(
                    modifier = Modifier
                        .scrollable(
                            enabled = false,
                            state = subscriptionCardsScrollState,
                            orientation = Orientation.Vertical,
                        ),
                )

                LeftPanel(
                    modifier = Modifier,
                )
            }

            // bottom content
        }
    }
}

Here is a picture that illustrates an example of how the screen looks:

Share Improve this question asked Nov 18, 2024 at 10:21 Denis PopkovDenis Popkov 554 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

You can make use of the canScrollForward boolean of the ScrolLState. Please try the following code:

@Composable
fun DialogScreen(
) {
    val subscriptionCardsScrollState = rememberScrollState()

    Box {

        Column(
            modifier = Modifier
                .verticalScroll(
                    enabled = !subscriptionCardsScrollState.canScrollForward,
                    state = rememberScrollState()
                ),
        ) {
            Row {
                Column(
                    modifier = Modifier,
                ) {
                    repeat(25) {
                        Text("LEFT ITEM $it")
                    }
                }
                Column(
                    modifier = Modifier
                        .height(250.dp)
                        .verticalScroll(
                            enabled = subscriptionCardsScrollState.canScrollForward,
                            state = subscriptionCardsScrollState
                        ),
                ) {
                    repeat(45) {
                        Text("RIGHT ITEM $it")
                    }
                }
            }

            if (!subscriptionCardsScrollState.canScrollForward) {
                Text("BOTTOM CONTENT")
            }
        }
    }
}

Note that you can't have two vertically scrolling Composables nested while both are using fillMaxHeight. You need to set a fixed height on the inner scrollable Composable.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论