最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

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

matteradmin10PV0评论

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.

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far