iamthevoid
04/27/2024, 1:39 PMonClick
handler. I tried few ways, but those click actions interfere between each other. Actually last one overrides first one. May I somehow combine library-long-click and client code click?iamthevoid
04/27/2024, 1:41 PMAlex Styl
04/27/2024, 4:33 PMClient code use this modifier and also would like to addhow does that look like from an API pov?handler.onClick
iamthevoid
04/27/2024, 4:54 PMtooltip
just provided own "onClick" behavior. For now I decided to add tooltip for clickable views, and the best way (in my head) was to add into api boolean
flag clickable
. Under the hood depends on this flag modifier can provide onClick
or onLongClick
action to show tooltipAlex Styl
04/28/2024, 9:39 AMiamthevoid
04/28/2024, 9:40 AMiamthevoid
04/28/2024, 9:41 AMfun Modifier.tooltip(
config: TooltipConfig = TooltipConfig(),
onAnchorClick: (() -> Unit)? = null,
content: @Composable () -> Unit,
) = composed {
var coordinates by remember { mutableStateOf<LayoutCoordinates?>(null) }
fun showTooltip() {
tooltipBundle = coordinates?.let {
TooltipBundle(content, config, it)
}
}
onGloballyPositioned { coordinates = it }
.then(if (onAnchorClick != null) {
Modifier.combinedClickable(
onLongClick = ::showTooltip,
onClick = onAnchorClick
)
} else {
Modifier.pointerInput("Modifier.tooltip.key") {
detectTapGestures(onPress = {
showTooltip()
})
}
})
}
iamthevoid
04/28/2024, 9:42 AMonAnchorClick
is duct tape to combine long and short clicksiamthevoid
04/28/2024, 9:42 AMiamthevoid
04/28/2024, 9:43 AMTooltipOverlay
, that show tooltip by TooltipBundle
and coordinates, passed from anchoriamthevoid
04/28/2024, 9:44 AMiamthevoid
04/28/2024, 9:47 AMonClick
in client code, and somehow tell about that for that modifier, for example by flag clickable
. And if clickable
is true
i want show tooltip with long click, and if it is false
then i would like to show tooltip by shortClickAlex Styl
04/28/2024, 8:15 PMAlex Styl
04/28/2024, 8:16 PMclickable
parameter on the modifier parameter and the use it to use the respentive Modifier in your if else
block? you are already doing itiamthevoid
04/29/2024, 10:14 AMModifier.tooltip
click handlers override client code click handlers if tooltip modifier applied after clickable
modifier of client code. nd in opposite case if tooltip applied before that client code click handlers override tooltip click handlers
For now code in listing works, but it is a bit of cringe, to pass client code click hndler into tooltip. Tooltip should know nothing about client code clicks, maximum - clickable view or not