我试图使一个浮动ActionButton,让我使用onLongClick和手势检测的情况下是拖了起来。只是创建电报或新闻记录按钮的行为。
测试1使用Material3中的FloatingActionButton不起作用,原因是长时间单击:
FloatingActionButton(
modifier = Modifier
.size(48.dp)
.combinedClickable(
onClick = {
if (!textEmpty) {
onMessageChange(input.value.text)
input.value = TextFieldValue("")
}
if (recordingIsLock) {
stopRecord()
}
},
onLongClick = {
if (textEmpty) {
record()
}
}
)
.pointerInput(Unit) {
detectVerticalDragGestures(
onDragStart = {},
onDragCancel = {},
onDragEnd = {
if (!recordingIsLock) {
btnIndicatorHeight = 0F
}
},
onVerticalDrag = { change, dragAmount ->
// saber si no hay nada escrito
// saber si el drag es hacia arriba
// saber si esta grabando
if (textEmpty && change.position.y < 0 && dragAmount < 0 && isRecording) {
val aux = kotlin.math.abs(dragAmount)
btnIndicatorHeight += if (
!recordingIsLock &&
btnIndicatorHeight < 48
) {
println("!!!!")
aux / 10
} else if (btnIndicatorHeight >= 48) {
if (!recordingIsLock) {
recordingIsLock = true
}
0F
} else {
0F
}
}
})
},
onClick = {}
) {
Icon(
modifier = Modifier.size(24.dp),
tint = MaterialTheme.colorScheme.background,
imageVector = if (textEmpty) Icons.Filled.Mic else Icons.Filled.Send,
contentDescription = null
)
Box(
modifier = Modifier
.fillMaxWidth()
.height(btnIndicatorHeight.dp)
.background(color = MaterialTheme.colorScheme.primary),
contentAlignment = Alignment.Center
) {
if (!recordingIsLock)
Icon(
tint = Color.White,
imageVector = Icons.Outlined.Lock,
contentDescription = null
)
else
LottieAnimation(
modifier = Modifier.size(30.dp),
composition = recordingAnimationComposition,
iterations = Int.MAX_VALUE
)
}
}
测试2:创建自定义组件不会执行拖动行为。
ElevatedCard(
modifier = modifier
.size(48.dp)
.combinedClickable(
onClick = {
if (!textEmpty) {
onMessageChange(input.value.text)
input.value = TextFieldValue("")
}
if (recordingIsLock) {
stopRecord()
}
},
onLongClick = {
if (textEmpty) {
record()
}
}
)
.pointerInput(Unit) {
detectVerticalDragGestures(
onDragStart = {},
onDragCancel = {},
onDragEnd = {
if (!recordingIsLock) {
btnIndicatorHeight = 0F
}
},
onVerticalDrag = { change, dragAmount ->
// saber si no hay nada escrito
// saber si el drag es hacia arriba
// saber si esta grabando
if (textEmpty && change.position.y < 0 && dragAmount < 0 && isRecording) {
val aux = kotlin.math.abs(dragAmount)
btnIndicatorHeight += if (
!recordingIsLock &&
btnIndicatorHeight < 48
) {
println("!!!!")
aux / 10
} else if (btnIndicatorHeight >= 48) {
if (!recordingIsLock) {
recordingIsLock = true
}
0F
} else {
0F
}
}
})
}
.background(
color = MaterialTheme.colorScheme.surface,
shape = RoundedCornerShape(10.dp)
)
) {
Box(contentAlignment = Alignment.Center) {
component()
}
}
1条答案
按热度按时间x7rlezfr1#
我找到了创建我的自定义按钮的方法。它有西班牙语的注解,我相信你们都可以像我一样翻译你的答案;):