Skip to content

Commit 8e7d834

Browse files
committed
Merge branch 'main' into release
v0.3.0 release
2 parents 40df983 + 3487e71 commit 8e7d834

File tree

189 files changed

+5587
-545
lines changed

Some content is hidden

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

189 files changed

+5587
-545
lines changed

LEGACY_README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Legacy README
2+
3+
This file contains information on legacy code which is not removed yet.
4+
5+
## Supported features
6+
7+
### Styles
8+
9+
The `ModifierOrAttrsScope.styles` function and the `StyleScope` class provide a universal interface for `Modifier`s and CSS styles.
10+
11+
The functions in `StyleScope`:
12+
13+
- `height`
14+
- `margin`
15+
- `width`
16+
- `backgroundColor`
17+
- `platformBorder`
18+
- `outerBorder`

README.md

Lines changed: 85 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
1-
# Compose Multiplatform Material wrappers for `androidx.compose.material` and Compose HTML
1+
# Compose Multiplatform Material: unified Compose Multiplatform common extensions and Material wrappers for `androidx.compose` and Compose HTML
22

3-
[![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-*)
4-
![Kotlin version](https://kotlin-version.aws.icerock.dev/kotlin-version?group=com.huanshankeji&name=compose-multiplatform-material)
3+
[![Maven Central](https://img.shields.io/maven-central/v/com.huanshankeji/compose-multiplatform-material3)](https://search.maven.org/search?q=g:com.huanshankeji%20AND%20a:compose-multiplatform-*)
4+
![Kotlin version](https://kotlin-version.aws.icerock.dev/kotlin-version?group=com.huanshankeji&name=compose-multiplatform-material3)
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+
Unified Compose Multiplatform wrappers of common components, layouts, and Material Design components for `androidx.compose` (officially supported on Android, desktop (JVM), iOS, and 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

8-
<!-- a set of APIs for Compose HTML similar to those in `androidx.compose.material` -->
8+
We try to provide a set of common extensions and composable component APIs akin to those in `androidx.compose` (`androidx.compose.foundation`, `androidx.compose.material`, and `androidx.compose.material3`), meanwhile making them compatible with the Compose HTML APIs. However, only subsets of the composables and composable parameters are supported due to the API differences, limitations of the JS (web) platform and the Compose HTML composables this project depends on, and our limited effort.
99

10-
We try to make the function types of the composable components follow those in `androidx.compose.foundation` and `androidx.compose.material`, meanwhile being compatible with the Compose HTML APIs. However, only subsets of the composables and composable arguments are supported due to the API differences, limitations of the Compose HTML composables this project depends on, and our limited effort.
10+
Complete visual consistency across different platforms is not guaranteed.
1111

12-
Visual consistency across different platforms is not guaranteed.
13-
14-
This project is prototype and there is no documentation yet. Check out [the demo project](demo) on how to use the components.
12+
This project is still in development and has not reached the stable state yet. Some APIs are likely to be changed and there is no detailed documentation yet. Check out [the demo project](demo) on how to use the components in addition to the information below.
1513

1614
## Supported features
1715

1816
### Components
1917

20-
#### Common (Foundation) components
18+
#### Foundation components
2119

2220
- `BasicText`
2321

@@ -28,46 +26,80 @@ This project is prototype and there is no documentation yet. Check out [the demo
2826
##### Layouts
2927

3028
- `Box`
31-
- `Column` (via flexbox on web)
32-
- `Row` (via flexbox on web)
29+
- `Column` (via flexbox on JS)
30+
- `Row` (via flexbox on JS)
31+
- `Spacer`
32+
33+
##### Lazy
34+
35+
- `LazyColumn`
36+
- `LazyRow`
3337

34-
#### Material components
38+
#### Material 2 components
3539

3640
- `Button`
3741
- `Card`
42+
- `Checkbox`
43+
- `Divider` (not working properly on JS yet)
3844
- `Icon`
3945
- `IconButton`
40-
- `ScrollableList`/`LazyColumn` (visually inconsistent for now)
41-
- `Text`/`MaterialText`
42-
- `TextField`
46+
- `Switch`
47+
- `Text`
48+
49+
##### `ext` components
50+
51+
- `Button`
52+
- `IconButton`
53+
- `RadioRow`, `RadioGroupRow`
54+
- `SwitchWithLabel`
55+
- `MaterialText`, `InlineText`
56+
- `TextField`, `OutlinedTextField`
4357
- `TopAppBarScaffold`
4458

45-
#### Components in the `ext` packages
59+
##### `lazy.ext` components
4660

47-
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.
61+
- `List`/`LazyColumnList` (visually inconsistent for now)
4862

49-
### Styles (obsolete in the legacy module, for removal)
63+
#### Material 3 components
5064

51-
The `ModifierOrAttrsScope.styles` function and the `StyleScope` class provide a universal interface for `Modifier`s and CSS styles.
65+
- `Button` (`FilledButton`), `ElevatedButton`, `FilledTonalButton`, `OutlinedButton`, `TextButton`
66+
- `Card` (`FilledCard`), `ElevatedCard`, `OutlinedCard`
67+
- `Checkbox`
68+
- `FloatingActionButton`, `SmallFloatingActionButton`, `LargeFloatingActionButton`, `ExtendedFloatingActionButton`
69+
- `Icon`
70+
- `IconButton`, `IconToggleButton`, `FilledIconButton`, `FilledIconToggleButton`, `FilledTonalIconButton`, `FilledTonalIconToggleButton`, `OutlinedIconButton`, `OutlinedIconToggleButton`
71+
- `Switch`
72+
- `Text`
5273

53-
The functions in `StyleScope`:
74+
##### `ext` components
5475

55-
- `height`
56-
- `margin`
57-
- `width`
58-
- `backgroundColor`
59-
- `platformBorder`
60-
- `outerBorder`
76+
- `Button` (`FilledButton`), `ElevatedButton`, `FilledTonalButton`, `OutlinedButton`, `TextButton`
77+
- `Card` (`FilledCard`), `ElevatedCard`, `OutlinedCard`
78+
- `FloatingActionButton`, `SmallFloatingActionButton`, `LargeFloatingActionButton`, `ExtendedFloatingActionButton`
79+
- `IconButton`, `IconToggleButton`, `FilledIconButton`, `FilledIconToggleButton`, `FilledTonalIconButton`, `FilledTonalIconToggleButton`, `OutlinedIconButton`, `OutlinedIconToggleButton`
80+
- `NavigationBar`, `NavigationBarItem`
81+
- `MaterialText`, `InlineText`
82+
- `TextField`, `OutlinedTextField`
83+
84+
##### `lazy.ext` components
85+
86+
- `List`/`LazyColumnList` (slightly visually inconsistent)
87+
88+
#### About `ext` components (components in the `ext` packages)
89+
90+
The components in the `ext` packages don't follow the `androidx.compose` APIs exactly, but rather provide wrappers are more idiomatic and conventional on both kinds of targets, wrapping different APIs which can't be unified following the `androidx.compose` APIs.
6191

6292
### Modifiers
6393

6494
- size modifiers
65-
- `size`, `sizeIn`, `fillMaxSize`
66-
- `width`, `widthIn`, `fillMaxWidth`
67-
- `height`, `heightIn`, `fillMaxHeight`
95+
- `size`, `sizeIn`, `fillMaxSize`
96+
- `width`, `widthIn`, `fillMaxWidth`
97+
- `height`, `heightIn`, `fillMaxHeight`
6898
- `padding`
6999
- `background`
70100
- `border` (visually inconsistent)
101+
- `onClick`
102+
- `verticalScroll`, `horizontalScroll` (`ScrollState` not supported on JS yet)
71103

72104
#### `ext` modifiers
73105

@@ -82,22 +114,42 @@ Maven coordinate:
82114
"com.huanshankeji:compose-multiplatform-$module:$version"
83115
```
84116

117+
For example, depend on the Material 3 module with Gradle:
118+
119+
```kotlin
120+
kotlin {
121+
sourceSets {
122+
commonMain {
123+
dependencies {
124+
// ...
125+
implementation("com.huanshankeji:compose-multiplatform-material3:$version")
126+
}
127+
}
128+
}
129+
}
130+
```
131+
85132
View [all the artifacts on Maven Central](https://search.maven.org/search?q=g:com.huanshankeji%20AND%20a:compose-multiplatform-*).
86133

87134
This project depends on [Kobweb](https://github.com/varabyte/kobweb) which is not published to Maven Central yet, so you have to add the following Maven repository:
88135

89136
```kotlin
90137
repositories {
138+
mavenCentral()
91139
maven("https://us-central1-maven.pkg.dev/varabyte-repos/public")
92140
}
93141
```
94142

143+
### Material Symbols & Icons on JS
144+
145+
See [the corresponding section in Compose HTML Material](https://github.com/huanshankeji/compose-html-material?tab=readme-ov-file#material-symbols--icons) for configuring Material Icons on JS.
146+
95147
## About Kobweb Silk
96148

97-
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` APIs (type-safe CSS API wrappers) and layouts. Here is a list of topics in their README.md that should be helpful when you use this library in Compose HTML:
149+
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):
98150

99151
1. [Silk](https://github.com/varabyte/kobweb?tab=readme-ov-file#silk)
100-
1. [Modifier](https://github.com/varabyte/kobweb?tab=readme-ov-file#modifier)
101-
1. [attrsModifier and styleModifier](https://github.com/varabyte/kobweb?tab=readme-ov-file#attrsmodifier-and-stylemodifier)
152+
1. [Modifier](https://github.com/varabyte/kobweb?tab=readme-ov-file#modifier)
153+
1. [attrsModifier and styleModifier](https://github.com/varabyte/kobweb?tab=readme-ov-file#attrsmodifier-and-stylemodifier)
102154
1. [General purpose improvements on top of Compose HTML and Kotlin/JS](https://github.com/varabyte/kobweb?tab=readme-ov-file#general-purpose-improvements-on-top-of-compose-html-and-kotlinjs)
103155
1. [What about Compose Multiplatform for Web?](https://github.com/varabyte/kobweb?tab=readme-ov-file#what-about-compose-multiplatform-for-web)

buildSrc/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ repositories {
1212

1313
dependencies {
1414
implementation(kotlin("gradle-plugin", "1.9.23"))
15-
implementation("org.jetbrains.compose:compose-gradle-plugin:1.6.1")
15+
implementation("org.jetbrains.compose:compose-gradle-plugin:1.6.2")
1616
implementation("com.huanshankeji.team:gradle-plugins:0.5.1")
1717
implementation("com.android.tools.build:gradle:8.2.2")
1818
}
Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
val projectVersion = "0.2.0"
1+
import org.jetbrains.compose.ComposeBuildConfig
2+
3+
val projectVersion = "0.3.0"
24

35
object DependencyVersions {
4-
val composeMultiplatform = "1.6.1" // manually specified for "ui-unit"
5-
val kobweb = "0.17.1"
6-
val huanshankejiComposeWeb = "0.2.2"
6+
const val composeMultiplatform = ComposeBuildConfig.composeVersion // for "ui-unit"
7+
val kobweb = "0.17.3"
8+
val huanshankejiComposeHtml = "0.3.0"
79
val kmdc = "0.1.2"
8-
val materialIcons = "1.13.12"
10+
val materialSymbols = "0.17.4"
911

1012
object Androidx {
11-
val activityCompose = "1.8.2"
12-
val compose = "1.6.4"
13+
val activityCompose = "1.9.0"
14+
val compose = "1.6.6"
1315
}
1416
}

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`()
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()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.huanshankeji.compose.foundation
2+
3+
import androidx.compose.foundation.onClick
4+
import com.huanshankeji.compose.ui.Modifier
5+
6+
//@ExperimentalFoundationApi // `onClick` with a single parameter is likely to be always supported, so it does not require opt-in for now.
7+
@OptIn(androidx.compose.foundation.ExperimentalFoundationApi::class)
8+
actual fun Modifier.onClick(onClick: () -> Unit): Modifier =
9+
platformModify { onClick(onClick = onClick) }
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 =

0 commit comments

Comments
 (0)