Move launcher icon click events out of icon composable
This commit is contained in:
parent
3c3fec4754
commit
bf39ea426b
@ -101,8 +101,6 @@ fun ShapedLauncherIcon(
|
||||
size: Dp,
|
||||
icon: () -> LauncherIcon? = { null },
|
||||
badge: () -> Badge? = { null },
|
||||
onClick: (() -> Unit)? = null,
|
||||
onLongClick: (() -> Unit)? = null,
|
||||
shape: Shape = LocalIconShape.current
|
||||
) {
|
||||
|
||||
@ -149,17 +147,7 @@ fun ShapedLauncherIcon(
|
||||
) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.then(
|
||||
if (onClick != null || onLongClick != null) {
|
||||
Modifier.pointerInput(onClick, onLongClick) {
|
||||
detectTapGestures(
|
||||
onLongPress = { onLongClick?.invoke() },
|
||||
onTap = { onClick?.invoke() },
|
||||
)
|
||||
}
|
||||
} else Modifier
|
||||
),
|
||||
.fillMaxSize(),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
val bmp = currentBitmap
|
||||
@ -253,17 +241,7 @@ fun ShapedLauncherIcon(
|
||||
tonalElevation = 1.dp,
|
||||
modifier = Modifier
|
||||
.size(size * 0.33f)
|
||||
.align(Alignment.BottomEnd)
|
||||
.then(
|
||||
if (onClick != null || onLongClick != null) {
|
||||
Modifier.pointerInput(onClick, onLongClick) {
|
||||
detectTapGestures(
|
||||
onLongPress = { onLongClick?.invoke() },
|
||||
onTap = { onClick?.invoke() },
|
||||
)
|
||||
}
|
||||
} else Modifier
|
||||
),
|
||||
.align(Alignment.BottomEnd),
|
||||
color = MaterialTheme.colorScheme.secondary,
|
||||
shape = CircleShape
|
||||
) {
|
||||
|
||||
@ -5,6 +5,8 @@ import androidx.activity.compose.BackHandler
|
||||
import androidx.compose.animation.core.animateFloatAsState
|
||||
import androidx.compose.animation.core.tween
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.combinedClickable
|
||||
import androidx.compose.foundation.interaction.MutableInteractionSource
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.absoluteOffset
|
||||
@ -87,11 +89,27 @@ fun GridItem(
|
||||
var showPopup by remember(item.key) { mutableStateOf(false) }
|
||||
var bounds by remember { mutableStateOf(Rect.Zero) }
|
||||
|
||||
Column(modifier = modifier, horizontalAlignment = Alignment.CenterHorizontally) {
|
||||
val launchOnPress = !item.preferDetailsOverLaunch
|
||||
val hapticFeedback = LocalHapticFeedback.current
|
||||
|
||||
Column(
|
||||
modifier = modifier
|
||||
.combinedClickable(
|
||||
onClick = {
|
||||
if (!launchOnPress || !viewModel.launch(context, bounds)) {
|
||||
showPopup = true
|
||||
}},
|
||||
onLongClick = {
|
||||
hapticFeedback.performHapticFeedback(HapticFeedbackType.LongPress)
|
||||
showPopup = true
|
||||
},
|
||||
indication = null,
|
||||
interactionSource = remember { MutableInteractionSource() },
|
||||
),
|
||||
horizontalAlignment = Alignment.CenterHorizontally) {
|
||||
val badge by viewModel.badge.collectAsStateWithLifecycle()
|
||||
val icon by viewModel.icon.collectAsStateWithLifecycle()
|
||||
|
||||
val launchOnPress = !item.preferDetailsOverLaunch
|
||||
|
||||
val windowSize = LocalWindowSize.current
|
||||
|
||||
@ -115,7 +133,6 @@ fun GridItem(
|
||||
}
|
||||
}
|
||||
|
||||
val hapticFeedback = LocalHapticFeedback.current
|
||||
val iconShape = LocalIconShape.current
|
||||
|
||||
Box(
|
||||
@ -141,15 +158,6 @@ fun GridItem(
|
||||
size = LocalGridSettings.current.iconSize.dp,
|
||||
badge = { badge },
|
||||
icon = { icon },
|
||||
onClick = {
|
||||
if (!launchOnPress || !viewModel.launch(context, bounds)) {
|
||||
showPopup = true
|
||||
}
|
||||
},
|
||||
onLongClick = {
|
||||
hapticFeedback.performHapticFeedback(HapticFeedbackType.LongPress)
|
||||
showPopup = true
|
||||
}
|
||||
)
|
||||
}
|
||||
if (showLabels) {
|
||||
|
||||
@ -4,6 +4,7 @@ import android.content.pm.PackageManager
|
||||
import android.graphics.drawable.InsetDrawable
|
||||
import androidx.activity.compose.BackHandler
|
||||
import androidx.appcompat.content.res.AppCompatResources
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
@ -121,7 +122,7 @@ fun CustomizeSearchableSheet(
|
||||
icon = badgeDrawable
|
||||
)
|
||||
},
|
||||
onClick = {
|
||||
modifier = Modifier.clickable {
|
||||
viewModel.openIconPicker()
|
||||
}
|
||||
)
|
||||
@ -350,7 +351,7 @@ fun IconPreview(
|
||||
ShapedLauncherIcon(
|
||||
size = iconSize,
|
||||
icon = { item?.preview },
|
||||
onClick = onClick
|
||||
modifier = Modifier.clickable(onClick = onClick),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,6 +4,7 @@ import android.graphics.drawable.ColorDrawable
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.compose.animation.AnimatedVisibility
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
@ -364,7 +365,7 @@ fun IconShapePreference(
|
||||
)
|
||||
)
|
||||
},
|
||||
onClick = {
|
||||
modifier = Modifier.clickable {
|
||||
onValueChanged(it)
|
||||
showDialog = false
|
||||
},
|
||||
|
||||
@ -2,6 +2,7 @@ package de.mm20.launcher2.ui.settings.tags
|
||||
|
||||
import androidx.compose.animation.AnimatedVisibility
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
@ -203,10 +204,9 @@ fun ListItem(
|
||||
ShapedLauncherIcon(
|
||||
icon = { icon },
|
||||
size = 48.dp,
|
||||
modifier = Modifier.padding(4.dp),
|
||||
onClick = {
|
||||
modifier = Modifier.padding(4.dp).clickable {
|
||||
onTagChanged(!item.isTagged)
|
||||
}
|
||||
},
|
||||
)
|
||||
if (item.isTagged) {
|
||||
Surface(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user