Skip to content

Commit

Permalink
Introduce PointerIcon.PlatformPointer
Browse files Browse the repository at this point in the history
  • Loading branch information
alexstyl committed Jul 1, 2024
1 parent 56412ea commit fcb07dd
Show file tree
Hide file tree
Showing 18 changed files with 132 additions and 3 deletions.
8 changes: 8 additions & 0 deletions .idea/artifacts/composetheme_js_1_2_0_alpha.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/artifacts/composetheme_jvm_1_2_0_alpha.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/artifacts/composetheme_material3_js_1_2_0_alpha.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/artifacts/composetheme_material3_jvm_1_2_0_alpha.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/artifacts/composetheme_material_js_1_2_0_alpha.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/artifacts/composetheme_material_jvm_1_2_0_alpha.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/artifacts/composetheme_material_wasm_js_1_2_0_alpha.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/artifacts/composetheme_wasm_js_1_2_0_alpha.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.composables.composetheme

import androidx.compose.ui.input.pointer.PointerIcon

internal actual val PlatformPointerIcon: PointerIcon = PointerIcon.Default
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ fun buildComposeTheme(themeBuilder: ThemeBuilder.() -> Unit): ThemeComposable {
val theme = ResolvedTheme(builder.name, builder.indication, allProperties, builder.themeWrapper)

return { content ->
CompositionLocalProvider(LocalTheme provides theme, LocalIndication provides builder.indication, content = {
CompositionLocalProvider(LocalTheme provides theme, LocalIndication provides builder.indication, LocalPlatformPointer provides PlatformPointerIcon, content = {
theme.Extend(content)
})
}
Expand Down Expand Up @@ -183,4 +183,4 @@ class MutableThemeProperties internal constructor() {
operator fun <T> set(property: DesignProperty<T>, value: T) {
entries[property] = value as Any
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.composables.composetheme

import androidx.compose.runtime.Composable
import androidx.compose.runtime.staticCompositionLocalOf
import androidx.compose.ui.input.pointer.PointerIcon

internal val LocalPlatformPointer = staticCompositionLocalOf { PointerIcon.Default }
internal expect val PlatformPointerIcon: PointerIcon

/**
* [PointerIcon] used to indicate the hovered item is interactive. The icon displayed depends on the platform the icon will be used on.
*
* For example, this will show a [PointerIcon.Hand] icon when used on web vs a [PointerIcon.Default] icon on desktop.
*/
val PointerIcon.Companion.PlatformPointer: PointerIcon
@Composable get() {
return LocalPlatformPointer.current
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.composables.composetheme

import androidx.compose.ui.input.pointer.PointerIcon

internal actual val PlatformPointerIcon: PointerIcon = PointerIcon.Default
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.composables.composetheme

import androidx.compose.ui.input.pointer.PointerIcon

internal actual val PlatformPointerIcon: PointerIcon = PointerIcon.Hand
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.composables.composetheme

import androidx.compose.ui.input.pointer.PointerIcon

internal actual val PlatformPointerIcon: PointerIcon = PointerIcon.Default
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.composables.composetheme

import androidx.compose.ui.input.pointer.PointerIcon

internal actual val PlatformPointerIcon: PointerIcon = PointerIcon.Hand
3 changes: 2 additions & 1 deletion samples/src/desktopMain/kotlin/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ fun main() = singleWindowApplication {
// CustomPropertiesDemo()
// DefaultsDemo()
// DynamicThemeDemo()
ExtendDemo()
// ExtendDemo()
// ExtendMaterial3Demo()
// ExtendMaterialDemo()
// PointerIconDemo()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.composables.composetheme.samples

import androidx.compose.foundation.text.BasicText
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.input.pointer.PointerIcon
import androidx.compose.ui.input.pointer.pointerHoverIcon
import com.composables.composetheme.PlatformPointer

@Composable
fun PointerIconDemo() {
BasicText(text = "Hover over me", modifier = Modifier.pointerHoverIcon(PointerIcon.PlatformPointer))
}

0 comments on commit fcb07dd

Please sign in to comment.