admin管理员组文章数量:1123703
If I make a column vertically scrollable with Modifier.verticalScroll() then try to detect a drag stop using detectVerticalDragGestures this breaks the scrolling.
Column(
modifier = Modifier
.verticalScroll(innerScrollState)
.pointerInput(Unit) {
detectVerticalDragGestures( // <- breaks scrolling
onDragEnd = {
// Do something here
}
) { change, dragAmount -> }
}
.nestedScroll(scrollConnection)
.fillMaxWidth()
)
What options do I have to detect the user has lifted his finger while maintaining scrollability, including the nestedScroll I have setup.
If I make a column vertically scrollable with Modifier.verticalScroll() then try to detect a drag stop using detectVerticalDragGestures this breaks the scrolling.
Column(
modifier = Modifier
.verticalScroll(innerScrollState)
.pointerInput(Unit) {
detectVerticalDragGestures( // <- breaks scrolling
onDragEnd = {
// Do something here
}
) { change, dragAmount -> }
}
.nestedScroll(scrollConnection)
.fillMaxWidth()
)
What options do I have to detect the user has lifted his finger while maintaining scrollability, including the nestedScroll I have setup.
Share Improve this question asked yesterday user29133385user29133385 11 bronze badge New contributor user29133385 is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.2 Answers
Reset to default 0You can check the isScrollInProgress
parameter of the scroll state, but I'm not sure it's enough with a custom nestedScroll
:
val scrollState = rememberScrollState()
val scrollBehavior = TopAppBarDefaults.enterAlwaysScrollBehavior()
LaunchedEffect(scrollState) {
snapshotFlow { scrollState.isScrollInProgress }
.collect { isScrollInProgress ->
if (!isScrollInProgress) {
/** doSomething **/
}
}
}
Scaffold(
modifier = Modifier.nestedScroll(scrollBehavior.nestedScrollConnection),
topBar = {
TopAppBar(
title = { Text("TopAppBar") },
navigationIcon = {
IconButton(onClick = { /** doSomething **/ }) {
Icon(
imageVector = Icons.Filled.Menu,
contentDescription = null
)
}
},
scrollBehavior = scrollBehavior
)
},
) { paddingValues ->
Column(
Modifier
.fillMaxSize()
.verticalScroll(scrollState)
.padding(paddingValues)
) {
repeat(200) {
Text(modifier = Modifier.fillMaxWidth(), text = "Title")
}
}
}
In case this helps someone, I dont know if this is the best answer. But if you use pointerInput but don't use detectDragXXX instead do your own, you can observe the values without breaking scrollable. Its not quite as good as dragStart and Stop, but it worked for my needs:
.pointerInput(Unit) {
awaitPointerEventScope {
while (true) {
val event = awaitPointerEvent()
event.changes.forEach { change ->
if (change.pressed && !change.previousPressed) { finger down }
if (!change.pressed) { finger up }
}
}
}
}
本文标签:
版权声明:本文标题:kotlin - Android Compose: How to detect drag stop (finger lifted) when using Modifier.verticalScroll - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736589673a1945058.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论