Lauri Koskela
05/04/2025, 12:44 PMscrollable
implementation that sometimes passes drag gestures to the activity and some times not. Here's a minimal sample:
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
installSplashScreen()
super.onCreate(savedInstanceState)
setContent { WearApp() }
}
override fun onTouchEvent(event: MotionEvent?): Boolean {
Log.d(TAG, "onTouchEvent: $event")
return super.onTouchEvent(event)
}
}
@Composable
fun WearApp() {
MyTestAppComposeTheme {
Box(
modifier = Modifier.fillMaxSize().padding(horizontal = 8.dp)
) {
val offsetX = remember { mutableFloatStateOf(0f) }
val scrollState = rememberScrollableState {
offsetX.floatValue += it
it
}
Box(
modifier = Modifier
.fillMaxRectangle()
.border(width = 1.dp, color = Color.White)
.scrollable(scrollState, Orientation.Horizontal)
contentAlignment = Alignment.Center
) {
Text(offsetX.floatValue.toString())
}
}
}
}
This renders a box that is horizontally swipeable. As far as I know it should never let the activity swipe-to-dismiss trigger as long as the scrolling gestures start inside the box, right?
Defining horizontal scroll semantics mostly fixes this; for example adding this after .scrollable
in the above snippet
.semantics {
horizontalScrollAxisRange = ScrollAxisRange(
{ offsetX.floatValue }, { 100f /* dummy value */ })
},
Is it a bug or should this be working without the semantics modifier? I know horizontal scrolling has been discussed many times here but I could not find this particular issue anywherestevebower
05/07/2025, 2:22 PM