Rick Regan
03/07/2021, 12:40 AMButton
to respond to both a press and a long press? I tried modifier .pointerInput
with detectTapGestures
and onLongPress
but it does not detect the long press (or any of the other gestures).
If I include a Text
in the Button I can get the long press to work on the text portion, but I want to cover the whole button. (See code in thread.)
Edit: I can't get Modifier.combinedClickable
to do it either (see second code example in thread).Rick Regan
03/07/2021, 12:41 AM@Composable
fun LongPressButtonTest() {
Button(
modifier = Modifier.size(100.dp).pointerInput(Unit) {
detectTapGestures(
onTap = { println("(Button onTap)") },
onDoubleTap = { println("(Button onDoubleTap)") },
onLongPress = { println("(Button onLongPress)") }
)
},
onClick = { println("(Button onClick)") }
) {
Text(
text = "Text",
color = Color.White,
modifier = Modifier.pointerInput(Unit) {
detectTapGestures(
onTap = { println("(Text onTap)") },
onDoubleTap = { println("(Text onDoubleTap)") },
onLongPress = { println("(Text onLongPress)") }
)
}
)
}
}
Rick Regan
03/07/2021, 4:05 AM@ExperimentalFoundationApi
Modifier.combinedClickable
and I can't get that to work either (what am I missing?):
@ExperimentalFoundationApi
@Composable
fun CombinedClickableButtonTest() {
Button(
modifier = Modifier.size(100.dp)
.combinedClickable(
onLongClick = { println("(Button modifier onLongClick)") },
onDoubleClick = { println("(Button modifier onDoubleClick)") },
onClick = { println("(Button modifier onClick)") }
),
onClick = { println("(Button onClick)") }
) {
Text(
text = "Text",
color = Color.White,
)
}
}
Denis
03/07/2021, 8:23 AMRick Regan
03/07/2021, 2:27 PMText
and Icon
. I suppose I could get button behaviors like elevation and indication through modifiers, but how would I get enabled
?Denis
03/07/2021, 3:13 PMRick Regan
03/07/2021, 6:17 PMCompositionLocalProvider
and ProvideTextStyle
, and I also think about having to merge changes that may occur every two weeks with each release.