Fixed fast clickable for lists & added hover effect to it

This commit is contained in:
Abdelilah El Aissaoui 2022-10-10 18:01:06 +02:00
parent add5666d89
commit 4f019ca8ed
3 changed files with 22 additions and 8 deletions

View file

@ -1,7 +1,11 @@
package com.jetpackduba.gitnuro.extensions
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.*
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.interaction.collectIsHoveredAsState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.awt.awtEventOrNull
@ -38,9 +42,11 @@ fun Modifier.handOnHover(): Modifier {
// TODO Try to restore hover that was shown with clickable modifier
@OptIn(ExperimentalComposeUiApi::class)
fun Modifier.fastClickable(onClick: () -> Unit) =
@Composable
fun Modifier.fastClickable(key: Any = Unit, onClick: () -> Unit) =
this.handOnHover()
.pointerInput(Unit) {
.hoverBackground()
.pointerInput(key) {
while (true) {
val lastMouseEvent = awaitPointerEventScope { awaitFirstDownEvent() }
val mouseEvent = lastMouseEvent.awtEventOrNull
@ -51,4 +57,12 @@ fun Modifier.fastClickable(onClick: () -> Unit) =
}
}
}
}
}
@Composable
private fun Modifier.hoverBackground(): Modifier {
val hoverInteraction = remember { MutableInteractionSource() }
return this.hoverable(hoverInteraction)
.indication(hoverInteraction, LocalIndication.current)
}

View file

@ -861,7 +861,7 @@ fun DiffLineText(line: Line, diffEntryType: DiffEntryType, onActionTriggered: ()
contentDescription = null,
tint = Color.White,
modifier = Modifier
.fastClickable { onActionTriggered() }
.fastClickable(line) { onActionTriggered() }
.size(14.dp)
.clip(RoundedCornerShape(2.dp))
.background(color),

View file

@ -619,7 +619,7 @@ fun UncommitedChangesLine(
modifier = Modifier
.height(40.dp)
.fillMaxWidth()
.fastClickable { onUncommitedChangesSelected() }
.handMouseClickable { onUncommitedChangesSelected() }
.padding(start = graphWidth)
.backgroundIf(isSelected, MaterialTheme.colors.backgroundSelected)
.padding(DIVIDER_WIDTH.dp),
@ -742,7 +742,7 @@ fun CommitLine(
) {
Box(
modifier = Modifier
.fastClickable { onRevCommitSelected() }
.fastClickable(graphNode) { onRevCommitSelected() }
.padding(start = graphWidth)
.height(LINE_HEIGHT.dp)
.backgroundIf(isSelected, MaterialTheme.colors.backgroundSelected)