Daniele B
07/11/2023, 11:52 AMPointerIcon
doesn't get recognized anymore.
So, is it not available for Compose JS/Canvas?
UPDATE: It looks like also AlertDialog
is missing, and also the onClick
modifier.
Is it expected these to be included any soon in both JS/Canvas and Wasm/Canvas?Oleksandr Karpovich [JB]
07/11/2023, 1:24 PMOleksandr Karpovich [JB]
07/11/2023, 1:29 PMDaniele B
07/11/2023, 2:11 PMe: file:///.../MyButton.kt:25:46 Unresolved reference. None of the following candidates is applicable because of receiver type mismatch:
public operator fun <T, R> DeepRecursiveFunction<TypeVariable(T), TypeVariable(R)>.invoke(value: TypeVariable(T)): TypeVariable(R) defined in kotlin
Oleksandr Karpovich [JB]
07/11/2023, 2:12 PMDaniele B
07/11/2023, 2:17 PMfun MyButton(text: String, clickFunction: () -> Unit, bgColor: Color = Purple700) {
val interactionSource = remember { MutableInteractionSource() }
val isHovered by interactionSource.collectIsHoveredAsState()
Button(
modifier = Modifier.pointerHoverIcon(PointerIcon(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR))),
interactionSource = interactionSource,
colors = ButtonDefaults.buttonColors(
backgroundColor = if (isHovered) Teal200 else bgColor
),
onClick = { clickFunction() },
) {
Text(text = text, style = MaterialTheme.typography.button)
}
}
Oleksandr Karpovich [JB]
07/11/2023, 2:52 PMPointerIcon(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR))
This thing is desktop only, because Cursor.getPredefinedCursor(...)
is from java.awt
I changed your function a bit and was able to run it without issues:
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.interaction.collectIsHoveredAsState
import androidx.compose.material.Button
import androidx.compose.material.ButtonDefaults
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
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.graphics.Color
import androidx.compose.ui.input.pointer.PointerIcon
import androidx.compose.ui.input.pointer.pointerHoverIcon
@Composable
fun MyButton(text: String, clickFunction: () -> Unit, bgColor: Color = Color.Gray) {
val interactionSource = remember { MutableInteractionSource() }
val isHovered by interactionSource.collectIsHoveredAsState()
Button(
modifier = Modifier.pointerHoverIcon(
PointerIcon.Hand
),
interactionSource = interactionSource,
colors = ButtonDefaults.buttonColors(
backgroundColor = if (isHovered) Color.Black else bgColor
),
onClick = { clickFunction() },
) {
Text(text = text, style = MaterialTheme.typography.button)
}
}
Let me know how it works for youDaniele B
07/11/2023, 3:20 PMOleksandr Karpovich [JB]
07/11/2023, 3:22 PM