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