Skip to content

Commit f921762

Browse files
authored
Merge pull request #16 from huanshankeji/material-3
Add some Material 3 composables, support some additional features, and revamp some existing ones
2 parents eb1ada7 + cc42bc3 commit f921762

File tree

172 files changed

+5083
-663
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

172 files changed

+5083
-663
lines changed

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
[![Maven Central](https://img.shields.io/maven-central/v/com.huanshankeji/compose-multiplatform-material)](https://search.maven.org/search?q=g:com.huanshankeji%20AND%20a:compose-multiplatform-*)
44
![Kotlin version](https://kotlin-version.aws.icerock.dev/kotlin-version?group=com.huanshankeji&name=compose-multiplatform-material)
55

6-
Some simple unified Compose Multiplatform wrappers of common components, layouts, and Material Design components for `androidx.compose.material` (officially supported on Android, desktop (JVM), iOS, web (Kotlin/Wasm)) and Compose HTML (mainly based on [Kobweb Silk](https://github.com/varabyte/kobweb?tab=readme-ov-file#silk) and [KMDC](https://github.com/mpetuska/kmdc))
6+
Some simple unified Compose Multiplatform wrappers of common components, layouts, and Material Design components for `androidx.compose.material` (officially supported on Android, desktop (JVM), iOS, web (Kotlin/Wasm)) and Compose HTML (mainly based on [Kobweb Silk](https://github.com/varabyte/kobweb?tab=readme-ov-file#silk) [Compose](https://github.com/varabyte/kobweb/tree/main/frontend/kobweb-compose), [KMDC](https://github.com/mpetuska/kmdc), and [Compose HTML Material](https://github.com/huanshankeji/compose-html-material) (which is then based on [Material Web](https://github.com/material-components/material-web)))
77

88
<!-- a set of APIs for Compose HTML similar to those in `androidx.compose.material` -->
99

@@ -52,6 +52,10 @@ This project is prototype and there is no documentation yet. Check out [the demo
5252
- `RadioRow`
5353
- `RadioGroupRow`
5454

55+
#### Material 3 components
56+
57+
- `Button`
58+
5559
#### Components in the `ext` packages
5660

5761
The components in the `ext` packages don't follow the `androidx.compose` APIs exactly, but rather provide wrappers are idiomatic and conventional on both kinds of targets, wrapping different APIs which can't be unified following the `androidx.compose` APIs.
@@ -102,6 +106,10 @@ repositories {
102106
}
103107
```
104108

109+
### Material Symbols & Icons on JS
110+
111+
See [the corresponding section in Compose HTML Material]() for Material Icons on JS.
112+
105113
## About Kobweb Silk
106114

107115
The Kotlin/JS (Compose HTML) portion of this project depends on [Kobweb Compose](https://github.com/varabyte/kobweb/blob/main/frontend/kobweb-compose/README.md) of [Kobweb Silk](https://github.com/varabyte/kobweb?tab=readme-ov-file#silk) which is a UI layer built upon Compose HTML that provides `Modifier` (type-safe CSS API wrappers) and layout APIs. Here is a list of topics in their README.md that should be helpful when you use this library in Compose HTML, especially if you need to customize the components further on Kotlin/JS (Compose HTML):

buildSrc/src/main/kotlin/VersionsAndDependencies.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
val projectVersion = "0.2.0-SNAPSHOT"
1+
import org.jetbrains.compose.ComposeBuildConfig
2+
3+
val projectVersion = "0.3.0-SNAPSHOT"
24

35
object DependencyVersions {
4-
val composeMultiplatform = "1.6.2" // manually specified for "ui-unit"
6+
const val composeMultiplatform = ComposeBuildConfig.composeVersion // for "ui-unit"
57
val kobweb = "0.17.3"
6-
val huanshankejiComposeWeb = "0.2.2"
8+
val huanshankejiComposeHtml = "0.3.0"
79
val kmdc = "0.1.2"
810

911
object Androidx {

buildSrc/src/main/kotlin/common-conventions.gradle.kts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
12
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl
23

34
plugins {
@@ -35,4 +36,10 @@ kotlin {
3536
// for JS and HTML wrappers
3637

3738
js()
39+
40+
41+
@OptIn(ExperimentalKotlinGradlePluginApi::class)
42+
compilerOptions {
43+
freeCompilerArgs.add("-Xexpect-actual-classes")
44+
}
3845
}

compose-multiplatform-common/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ kotlin {
3838
api(compose.html.core)
3939
// see: https://github.com/varabyte/kobweb/blob/main/frontend/kobweb-compose/build.gradle.kts
4040
api("com.varabyte.kobweb:kobweb-compose:${DependencyVersions.kobweb}")
41+
implementation("com.huanshankeji:compose-html-common:${DependencyVersions.huanshankejiComposeHtml}")
4142
}
4243
}
4344
}

compose-multiplatform-common/legacy/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ kotlin {
2222
dependencies {
2323
implementation(compose.html.core)
2424

25-
api("com.huanshankeji:compose-web-common:${DependencyVersions.huanshankejiComposeWeb}")
25+
api("com.huanshankeji:compose-html-common:${DependencyVersions.huanshankejiComposeHtml}")
2626
}
2727
}
2828
}
@@ -33,7 +33,7 @@ publishing.publications.withType<MavenPublication> {
3333
project,
3434
"Legacy Compose Multiplatform common wrappers",
3535
"Legacy common wrappers of components (including layouts) and styles for Compose Multiplatform on (desktop/Android and web)\n" +
36-
"This legacy module depends on `com.huanshankeji:compose-web-common` instead of Kobweb Silk " +
36+
"This legacy module depends on `com.huanshankeji:compose-html-common` instead of Kobweb Silk " +
3737
"and its components use the `ModifierOrAttrsScope` class to configure styles."
3838
) {
3939
`Shreck Ye`()
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.huanshankeji.compose
2+
3+
import androidx.compose.runtime.Composable
4+
import com.huanshankeji.compose.ui.Modifier
5+
6+
fun (@Composable (Modifier) -> Unit).toContentWithoutModifier(): @Composable () -> Unit =
7+
{ this(Modifier) }
8+
9+
fun (@Composable (Modifier) -> Unit)?.toNullableContentWithoutModifier(): @Composable (() -> Unit)? =
10+
this?.toContentWithoutModifier()
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.huanshankeji.compose.foundation
2+
3+
import androidx.compose.foundation.horizontalScroll
4+
import androidx.compose.foundation.rememberScrollState
5+
import androidx.compose.foundation.verticalScroll
6+
import androidx.compose.runtime.Composable
7+
import com.huanshankeji.compose.ui.Modifier
8+
9+
@Composable
10+
actual fun rememberScrollState(initial: Int): ScrollState =
11+
rememberScrollState(initial)
12+
13+
actual typealias ScrollState = androidx.compose.foundation.ScrollState
14+
15+
actual fun Modifier.verticalScroll(state: ScrollState): Modifier =
16+
platformModify { verticalScroll(state) }
17+
18+
actual fun Modifier.horizontalScroll(state: ScrollState): Modifier =
19+
platformModify { horizontalScroll(state) }

compose-multiplatform-common/src/androidxCommonMain/kotlin/com/huanshankeji/compose/foundation/layout/Column.androidxCommon.kt

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package com.huanshankeji.compose.foundation.layout
22

3+
import androidx.annotation.FloatRange
34
import androidx.compose.runtime.Composable
45
import androidx.compose.runtime.Stable
56
import com.huanshankeji.compose.ui.Alignment
67
import com.huanshankeji.compose.ui.Modifier
78
import kotlin.jvm.JvmInline
8-
import androidx.compose.foundation.layout.ColumnScope as PlatformColumnScope
99

1010
@Composable
1111
actual fun Column(
@@ -18,14 +18,25 @@ actual fun Column(
1818
modifier.platformModifier,
1919
verticalArrangement.platformValue,
2020
horizontalAlignment.platformHorizontal,
21-
) { ColumnScope.Impl(this).content() }
21+
content.toCommonColumnScopeContent()
22+
)
23+
24+
25+
actual typealias PlatformColumnScope = androidx.compose.foundation.layout.ColumnScope
2226

2327
//@LayoutScopeMarker
2428
actual interface ColumnScope {
25-
val platformValue: PlatformColumnScope
29+
actual val platformValue: PlatformColumnScope
2630

2731
@JvmInline
28-
value class Impl(override val platformValue: PlatformColumnScope) : ColumnScope
32+
actual value class Impl(override val platformValue: PlatformColumnScope) : ColumnScope
33+
34+
@Stable
35+
actual fun Modifier.weight(
36+
@FloatRange(from = 0.0, fromInclusive = false)
37+
weight: Float
38+
): Modifier =
39+
with(platformValue) { platformModify { weight(weight) } }
2940

3041
@Stable
3142
actual fun Modifier.align(alignment: Alignment.Horizontal): Modifier =

compose-multiplatform-common/src/androidxCommonMain/kotlin/com/huanshankeji/compose/foundation/layout/Row.androidxCommon.kt

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package com.huanshankeji.compose.foundation.layout
22

3+
import androidx.annotation.FloatRange
34
import androidx.compose.runtime.Composable
45
import androidx.compose.runtime.Stable
56
import com.huanshankeji.compose.ui.Alignment
67
import com.huanshankeji.compose.ui.Modifier
78
import kotlin.jvm.JvmInline
8-
import androidx.compose.foundation.layout.RowScope as PlatformRowScope
99

1010
@Composable
1111
actual fun Row(
@@ -18,14 +18,24 @@ actual fun Row(
1818
modifier.platformModifier,
1919
horizontalArrangement.platformValue,
2020
verticalAlignment.platformHorizontal,
21-
) { RowScope.Impl(this).content() }
21+
content.toPlatformRowScopeContent(),
22+
)
23+
24+
25+
actual typealias PlatformRowScope = androidx.compose.foundation.layout.RowScope
2226

2327
//@LayoutScopeMarker
2428
actual interface RowScope {
25-
val platformValue: PlatformRowScope
29+
actual val platformValue: PlatformRowScope
2630

2731
@JvmInline
28-
value class Impl(override val platformValue: PlatformRowScope) : RowScope
32+
actual value class Impl(override val platformValue: PlatformRowScope) : RowScope
33+
34+
actual fun Modifier.weight(
35+
@FloatRange(from = 0.0, fromInclusive = false)
36+
weight: Float
37+
): Modifier =
38+
with(platformValue) { platformModify { weight(weight) } }
2939

3040
@Stable
3141
actual fun Modifier.align(alignment: Alignment.Vertical): Modifier =
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package com.huanshankeji.compose.foundation.lazy
2+
3+
import androidx.compose.foundation.lazy.LazyScopeMarker
4+
import androidx.compose.runtime.Composable
5+
import com.huanshankeji.compose.foundation.layout.Arrangement
6+
import com.huanshankeji.compose.ui.Alignment
7+
import com.huanshankeji.compose.ui.Modifier
8+
9+
@LazyScopeMarker
10+
//@JvmDefaultWithCompatibility
11+
actual class LazyListScope(val platformValue: androidx.compose.foundation.lazy.LazyListScope) {
12+
actual fun item(
13+
key: Any?,
14+
contentType: Any?,
15+
content: @Composable LazyItemScope.() -> Unit
16+
) =
17+
platformValue.item(key, contentType) { LazyItemScope(this).content() }
18+
19+
20+
actual fun items(
21+
count: Int,
22+
key: ((index: Int) -> Any)?,
23+
contentType: (index: Int) -> Any?,
24+
itemContent: @Composable LazyItemScope.(index: Int) -> Unit
25+
) =
26+
platformValue.items(count, key, contentType) { index -> LazyItemScope(this).itemContent(index) }
27+
}
28+
29+
@Composable
30+
actual fun LazyRow(
31+
modifier: Modifier,
32+
reverseLayout: Boolean,
33+
horizontalArrangement: Arrangement.Horizontal,
34+
verticalAlignment: Alignment.Vertical,
35+
content: LazyListScope.() -> Unit
36+
) =
37+
androidx.compose.foundation.lazy.LazyRow(
38+
modifier.platformModifier,
39+
reverseLayout = reverseLayout,
40+
horizontalArrangement = horizontalArrangement.platformValue,
41+
verticalAlignment = verticalAlignment.platformHorizontal
42+
) { LazyListScope(this).content() }
43+
44+
@Composable
45+
actual fun LazyColumn(
46+
modifier: Modifier,
47+
reverseLayout: Boolean,
48+
verticalArrangement: Arrangement.Vertical,
49+
horizontalAlignment: Alignment.Horizontal,
50+
content: LazyListScope.() -> Unit
51+
) =
52+
androidx.compose.foundation.lazy.LazyColumn(
53+
modifier.platformModifier,
54+
reverseLayout = reverseLayout,
55+
verticalArrangement = verticalArrangement.platformValue,
56+
horizontalAlignment = horizontalAlignment.platformHorizontal
57+
) { LazyListScope(this).content() }

0 commit comments

Comments
 (0)