File tree Expand file tree Collapse file tree 17 files changed +246
-39
lines changed
compose-multiplatform-common/src
androidxCommonMain/kotlin/com/huanshankeji/compose/foundation/layout
commonMain/kotlin/com/huanshankeji/compose
jsMain/kotlin/com/huanshankeji/compose/foundation/layout
compose-multiplatform-material3/src
androidxCommonMain/kotlin/com/huanshankeji/compose/material3
commonMain/kotlin/com/huanshankeji/compose/material3
jsMain/kotlin/com/huanshankeji/compose/material3
demo/src/commonMain/kotlin/com/huanshankeji/compose/material/demo Expand file tree Collapse file tree 17 files changed +246
-39
lines changed Original file line number Diff line number Diff line change @@ -6,7 +6,6 @@ import androidx.compose.runtime.Stable
66import com.huanshankeji.compose.ui.Alignment
77import com.huanshankeji.compose.ui.Modifier
88import kotlin.jvm.JvmInline
9- import androidx.compose.foundation.layout.ColumnScope as PlatformColumnScope
109
1110@Composable
1211actual fun Column (
@@ -19,14 +18,18 @@ actual fun Column(
1918 modifier.platformModifier,
2019 verticalArrangement.platformValue,
2120 horizontalAlignment.platformHorizontal,
22- ) { ColumnScope .Impl (this ).content() }
21+ content.toCommonColumnScopeContent()
22+ )
23+
24+
25+ actual typealias PlatformColumnScope = androidx.compose.foundation.layout.ColumnScope
2326
2427// @LayoutScopeMarker
2528actual interface ColumnScope {
26- val platformValue: PlatformColumnScope
29+ actual val platformValue: PlatformColumnScope
2730
2831 @JvmInline
29- value class Impl (override val platformValue : PlatformColumnScope ) : ColumnScope
32+ actual value class Impl (override val platformValue : PlatformColumnScope ) : ColumnScope
3033
3134 @Stable
3235 actual fun Modifier.weight (
Original file line number Diff line number Diff line change @@ -6,7 +6,6 @@ import androidx.compose.runtime.Stable
66import com.huanshankeji.compose.ui.Alignment
77import com.huanshankeji.compose.ui.Modifier
88import kotlin.jvm.JvmInline
9- import androidx.compose.foundation.layout.RowScope as PlatformRowScope
109
1110@Composable
1211actual fun Row (
@@ -22,12 +21,15 @@ actual fun Row(
2221 content.toPlatformRowScopeContent(),
2322 )
2423
24+
25+ actual typealias PlatformRowScope = androidx.compose.foundation.layout.RowScope
26+
2527// @LayoutScopeMarker
2628actual interface RowScope {
27- val platformValue: PlatformRowScope
29+ actual val platformValue: PlatformRowScope
2830
2931 @JvmInline
30- value class Impl (override val platformValue : PlatformRowScope ) : RowScope
32+ actual value class Impl (override val platformValue : PlatformRowScope ) : RowScope
3133
3234 actual fun Modifier.weight (
3335 @FloatRange(from = 0.0 , fromInclusive = false )
@@ -39,7 +41,3 @@ actual interface RowScope {
3941 actual fun Modifier.align (alignment : Alignment .Vertical ): Modifier =
4042 with (platformValue) { platformModify { align(alignment.platformHorizontal) } }
4143}
42-
43-
44- fun (@Composable (RowScope .() -> Unit )).toPlatformRowScopeContent(): @Composable PlatformRowScope .() -> Unit =
45- { RowScope .Impl (this ).(this @toPlatformRowScopeContent)() }
Original file line number Diff line number Diff line change 1+ package com.huanshankeji.compose
2+
3+ /*
4+ // This API seems to reduce the readability of code
5+ fun <Scope> (@Composable () -> Unit).toContentWithoutScope(): @Composable Scope.() -> Unit =
6+ { this@toContentWithoutScope() }
7+ */
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ import androidx.compose.runtime.Composable
55import androidx.compose.runtime.Stable
66import com.huanshankeji.compose.ui.Alignment
77import com.huanshankeji.compose.ui.Modifier
8+ import kotlin.jvm.JvmInline
89
910@Composable
1011expect fun Column (
@@ -14,8 +15,16 @@ expect fun Column(
1415 content : @Composable ColumnScope .() -> Unit
1516)
1617
18+
19+ expect interface PlatformColumnScope
20+
1721// @LayoutScopeMarker
1822expect interface ColumnScope {
23+ val platformValue: PlatformColumnScope
24+
25+ @JvmInline
26+ value class Impl (override val platformValue : PlatformColumnScope ) : ColumnScope
27+
1928 @Stable
2029 open fun Modifier.weight (
2130 @FloatRange(from = 0.0 , fromInclusive = false )
@@ -25,3 +34,6 @@ expect interface ColumnScope {
2534 @Stable
2635 open fun Modifier.align (alignment : Alignment .Horizontal ): Modifier
2736}
37+
38+ fun (@Composable (ColumnScope .() -> Unit )).toCommonColumnScopeContent(): @Composable PlatformColumnScope .() -> Unit =
39+ { ColumnScope .Impl (this ).this @toCommonColumnScopeContent() }
Original file line number Diff line number Diff line change @@ -14,8 +14,15 @@ expect fun Row(
1414 content : @Composable RowScope .() -> Unit
1515)
1616
17+
18+ expect interface PlatformRowScope
19+
1720// @LayoutScopeMarker
1821expect interface RowScope {
22+ val platformValue: PlatformRowScope
23+
24+ value class Impl (override val platformValue : PlatformRowScope ) : RowScope
25+
1926 @Stable
2027 open fun Modifier.weight (
2128 @FloatRange(from = 0.0 , fromInclusive = false )
@@ -25,3 +32,6 @@ expect interface RowScope {
2532 @Stable
2633 open fun Modifier.align (alignment : Alignment .Vertical ): Modifier
2734}
35+
36+ fun (@Composable (RowScope .() -> Unit )).toPlatformRowScopeContent(): @Composable PlatformRowScope .() -> Unit =
37+ { RowScope .Impl (this ).this @toPlatformRowScopeContent() }
Original file line number Diff line number Diff line change @@ -8,7 +8,6 @@ import com.huanshankeji.compose.ui.Modifier
88import com.huanshankeji.compose.ui.PlatformModifier
99import com.huanshankeji.kobweb.compose.ui.modifiers.sizeFitContent
1010import com.varabyte.kobweb.compose.foundation.layout.LayoutScopeMarker
11- import com.varabyte.kobweb.compose.foundation.layout.ColumnScope as PlatformColumnScope
1211
1312@Composable
1413actual fun Column (
@@ -23,15 +22,19 @@ actual fun Column(
2322 .sizeFitContent() // "fit-content" is added to make it consistent with the `androidx` one
2423 .then(modifier.platformModifier),
2524 verticalArrangement.platformValue,
26- horizontalAlignment.platformValue
27- ) { ColumnScope .Impl (this ).content() }
25+ horizontalAlignment.platformValue,
26+ content = content.toCommonColumnScopeContent()
27+ )
2828}
2929
30+
31+ actual typealias PlatformColumnScope = com.varabyte.kobweb.compose.foundation.layout.ColumnScope
32+
3033@LayoutScopeMarker
3134actual interface ColumnScope {
32- val platformValue: PlatformColumnScope
35+ actual val platformValue: PlatformColumnScope
3336
34- value class Impl (override val platformValue : PlatformColumnScope ) : ColumnScope
37+ actual value class Impl (override val platformValue : PlatformColumnScope ) : ColumnScope
3538
3639 @Stable
3740 actual fun Modifier.weight (
Original file line number Diff line number Diff line change @@ -8,7 +8,6 @@ import com.huanshankeji.compose.ui.Modifier
88import com.huanshankeji.compose.ui.PlatformModifier
99import com.huanshankeji.kobweb.compose.ui.modifiers.sizeFitContent
1010import com.varabyte.kobweb.compose.foundation.layout.LayoutScopeMarker
11- import com.varabyte.kobweb.compose.foundation.layout.RowScope as PlatformRowScope
1211
1312@Composable
1413actual fun Row (
@@ -28,11 +27,14 @@ actual fun Row(
2827 )
2928}
3029
30+
31+ actual typealias PlatformRowScope = com.varabyte.kobweb.compose.foundation.layout.RowScope
32+
3133@LayoutScopeMarker
3234actual interface RowScope {
33- val platformValue: PlatformRowScope
35+ actual val platformValue: PlatformRowScope
3436
35- value class Impl (override val platformValue : PlatformRowScope ) : RowScope
37+ actual value class Impl (override val platformValue : PlatformRowScope ) : RowScope
3638
3739 @Stable
3840 actual fun Modifier.weight (
@@ -45,7 +47,3 @@ actual interface RowScope {
4547 actual fun Modifier.align (alignment : Alignment .Vertical ): Modifier =
4648 with (platformValue) { platformModify { align(alignment.platformValue) } }
4749}
48-
49-
50- fun (@Composable (RowScope .() -> Unit )).toPlatformRowScopeContent(): @Composable PlatformRowScope .() -> Unit =
51- { RowScope .Impl (this ).(this @toPlatformRowScopeContent)() }
Original file line number Diff line number Diff line change 1+ package com.huanshankeji.compose.material3
2+
3+ import androidx.compose.runtime.Composable
4+ import com.huanshankeji.compose.foundation.layout.ColumnScope
5+ import com.huanshankeji.compose.foundation.layout.toCommonColumnScopeContent
6+ import com.huanshankeji.compose.ui.Modifier
7+
8+ @Composable
9+ actual fun Card (modifier : Modifier , content : @Composable ColumnScope .() -> Unit ) =
10+ androidx.compose.material3.Card (modifier.platformModifier, content = content.toCommonColumnScopeContent())
11+
12+ @Composable
13+ actual fun ElevatedCard (modifier : Modifier , content : @Composable ColumnScope .() -> Unit ) =
14+ androidx.compose.material3.ElevatedCard (modifier.platformModifier, content = content.toCommonColumnScopeContent())
15+
16+ @Composable
17+ actual fun OutlinedCard (modifier : Modifier , content : @Composable ColumnScope .() -> Unit ) =
18+ androidx.compose.material3.OutlinedCard (modifier.platformModifier, content = content.toCommonColumnScopeContent())
Original file line number Diff line number Diff line change 1+ package com.huanshankeji.compose.material3.ext
2+
3+ import androidx.compose.runtime.Composable
4+ import com.huanshankeji.compose.ui.Modifier
5+
6+ @Composable
7+ actual fun Card (modifier : Modifier , content : @Composable () -> Unit ) =
8+ com.huanshankeji.compose.material3.Card (modifier) { content() }
9+
10+ @Composable
11+ actual fun ElevatedCard (modifier : Modifier , content : @Composable () -> Unit ) =
12+ com.huanshankeji.compose.material3.ElevatedCard (modifier) { content() }
13+
14+ @Composable
15+ actual fun OutlinedCard (modifier : Modifier , content : @Composable () -> Unit ) =
16+ com.huanshankeji.compose.material3.OutlinedCard (modifier) { content() }
Original file line number Diff line number Diff line change 1+ package com.huanshankeji.compose.material3
2+
3+ import androidx.compose.runtime.Composable
4+ import com.huanshankeji.compose.foundation.layout.ColumnScope
5+ import com.huanshankeji.compose.material3.ext.Card
6+ import com.huanshankeji.compose.ui.Modifier
7+
8+ @Composable
9+ expect fun Card (
10+ modifier : Modifier = Modifier ,
11+ content : @Composable ColumnScope .() -> Unit
12+ )
13+
14+ /* *
15+ * An alias for [Card].
16+ */
17+ @Composable
18+ fun FilledCard (
19+ modifier : Modifier = Modifier ,
20+ content : @Composable ColumnScope .() -> Unit
21+ ) =
22+ Card (modifier, content)
23+
24+ // TODO clickable cards
25+
26+ @Composable
27+ expect fun ElevatedCard (
28+ modifier : Modifier = Modifier ,
29+ content : @Composable ColumnScope .() -> Unit
30+ )
31+
32+ @Composable
33+ expect fun OutlinedCard (
34+ modifier : Modifier = Modifier ,
35+ content : @Composable ColumnScope .() -> Unit
36+ )
You can’t perform that action at this time.
0 commit comments