Skip to content

Commit

Permalink
Fix Modifier.pointerHoverIcon for browser apps (#565) (#629)
Browse files Browse the repository at this point in the history
  • Loading branch information
eymar authored and mazunin-v-jb committed Jul 11, 2023
1 parent b5d45f2 commit 0fc0682
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import androidx.compose.runtime.setValue
import androidx.compose.runtime.withFrameNanos
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.pointer.PointerIcon
import androidx.compose.ui.input.pointer.pointerHoverIcon
import androidx.compose.ui.unit.dp
import androidx.compose.ui.platform.LocalClipboardManager
import androidx.compose.ui.platform.LocalUriHandler
Expand Down Expand Up @@ -64,7 +66,7 @@ fun Example1() {
.width(100.dp).height(100.dp)
.clickable {
println("Red box: clicked")
}
}.pointerHoverIcon(PointerIcon.Text)
) {
Box(
modifier = Modifier
Expand All @@ -73,7 +75,7 @@ fun Example1() {
.width(20.dp).height(20.dp)
.clickable {
println("Small box: clicked")
}
}.pointerHoverIcon(PointerIcon.Hand)
)
}
Spacer(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ package androidx.compose.ui.input.pointer

object DummyPointerIcon : PointerIcon

internal actual val pointerIconDefault: PointerIcon = DummyPointerIcon
internal actual val pointerIconCrosshair: PointerIcon = DummyPointerIcon
internal actual val pointerIconText: PointerIcon = DummyPointerIcon
internal actual val pointerIconHand: PointerIcon = DummyPointerIcon
internal data class BrowserCursor(val id: String): PointerIcon

internal actual val pointerIconDefault: PointerIcon = BrowserCursor("default")
internal actual val pointerIconCrosshair: PointerIcon = BrowserCursor("crosshair")
internal actual val pointerIconText: PointerIcon = BrowserCursor("text")
internal actual val pointerIconHand: PointerIcon = BrowserCursor("pointer")
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.createSkiaLayer
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.input.pointer.BrowserCursor
import androidx.compose.ui.input.pointer.PointerIcon
import androidx.compose.ui.native.ComposeLayer
import androidx.compose.ui.platform.JSTextInputService
import androidx.compose.ui.platform.Platform
Expand Down Expand Up @@ -54,6 +56,12 @@ internal actual class ComposeWindow(val canvasId: String) {
override val doubleTapMinTimeMillis: Long = 40
override val touchSlop: Float get() = with(density) { 18.dp.toPx() }
}

override fun setPointerIcon(pointerIcon: PointerIcon) {
if (pointerIcon is BrowserCursor) {
setCursor(canvasId, pointerIcon.id)
}
}
}
private val layer = ComposeLayer(
layer = createSkiaLayer(),
Expand Down Expand Up @@ -159,4 +167,7 @@ fun CanvasBasedWindow(
}
}
}
}
}

private fun setCursor(elementId: String, value: String): Unit =
js("document.getElementById(elementId).style.cursor = value")

0 comments on commit 0fc0682

Please sign in to comment.