You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
2.1 KiB
Kotlin
57 lines
2.1 KiB
Kotlin
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
package org.mozilla.fenix.compose
|
|
|
|
import androidx.compose.foundation.ExperimentalFoundationApi
|
|
import androidx.compose.foundation.combinedClickable
|
|
import androidx.compose.foundation.interaction.MutableInteractionSource
|
|
import androidx.compose.foundation.layout.Box
|
|
import androidx.compose.material.ContentAlpha
|
|
import androidx.compose.material.IconButton
|
|
import androidx.compose.material.LocalContentAlpha
|
|
import androidx.compose.material.minimumInteractiveComponentSize
|
|
import androidx.compose.material.ripple.rememberRipple
|
|
import androidx.compose.runtime.Composable
|
|
import androidx.compose.runtime.CompositionLocalProvider
|
|
import androidx.compose.runtime.remember
|
|
import androidx.compose.ui.Alignment
|
|
import androidx.compose.ui.Modifier
|
|
import androidx.compose.ui.semantics.Role
|
|
import androidx.compose.ui.unit.dp
|
|
|
|
/**
|
|
* An [IconButton] that supports a long press gesture.
|
|
*/
|
|
|
|
@OptIn(ExperimentalFoundationApi::class)
|
|
@Composable
|
|
fun LongPressIconButton(
|
|
onClick: () -> Unit,
|
|
onLongClick: () -> Unit,
|
|
modifier: Modifier = Modifier,
|
|
enabled: Boolean = true,
|
|
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
|
|
content: @Composable () -> Unit,
|
|
) {
|
|
Box(
|
|
modifier = modifier
|
|
.minimumInteractiveComponentSize()
|
|
.combinedClickable(
|
|
onClick = onClick,
|
|
onLongClick = onLongClick,
|
|
enabled = enabled,
|
|
role = Role.Button,
|
|
interactionSource = interactionSource,
|
|
indication = rememberRipple(bounded = false, radius = RippleRadius),
|
|
),
|
|
contentAlignment = Alignment.Center,
|
|
) {
|
|
val contentAlpha = if (enabled) LocalContentAlpha.current else ContentAlpha.disabled
|
|
CompositionLocalProvider(LocalContentAlpha provides contentAlpha, content = content)
|
|
}
|
|
}
|
|
|
|
private val RippleRadius = 24.dp
|