admin管理员组文章数量:1026308
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 badges1 Answer
Reset to default 1You 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.
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 badges1 Answer
Reset to default 1You 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.
本文标签:
版权声明:本文标题:How disable scrolling for a single column in a row under certain conditions in Jetpack Compose? - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745626392a2159888.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论