Skip to content

Commit 2cea7ae

Browse files
committed
Add BoxScope for Box
1 parent 0ea9170 commit 2cea7ae

File tree

3 files changed

+17
-5
lines changed
  • compose-multiplatform-common/src
    • commonMain/kotlin/com/huanshankeji/compose/layout
    • jsMain/kotlin/com/huanshankeji/compose/layout
    • jvmMain/kotlin/com/huanshankeji/compose/layout

3 files changed

+17
-5
lines changed

compose-multiplatform-common/src/commonMain/kotlin/com/huanshankeji/compose/layout/Layouts.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,7 @@ import com.huanshankeji.compose.ui.ModifierOrAttrs
66

77
expect abstract class BoxElement : Element
88

9+
expect interface BoxScope
10+
911
@Composable
10-
expect fun Box(modifierOrAttrs: ModifierOrAttrs<BoxElement> = null, content: @Composable () -> Unit)
12+
expect fun Box(modifierOrAttrs: ModifierOrAttrs<BoxElement> = null, content: @Composable BoxScope.() -> Unit)

compose-multiplatform-common/src/jsMain/kotlin/com/huanshankeji/compose/layout/Layouts.kt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,18 @@ import androidx.compose.runtime.Composable
44
import com.huanshankeji.compose.ui.ModifierOrAttrs
55
import com.huanshankeji.compose.ui.toAttrs
66
import org.jetbrains.compose.web.dom.Div
7+
import org.jetbrains.compose.web.dom.ElementScope
78
import org.w3c.dom.HTMLDivElement
89

910
actual typealias BoxElement = HTMLDivElement
1011

12+
//actual typealias BoxScope = ElementScope<HTMLDivElement>
13+
actual interface BoxScope {
14+
val htmlDivElementScope: ElementScope<HTMLDivElement>
15+
16+
class Impl(override val htmlDivElementScope: ElementScope<HTMLDivElement>) : BoxScope
17+
}
18+
1119
@Composable
12-
actual fun Box(modifierOrAttrs: ModifierOrAttrs<BoxElement>, content: @Composable () -> Unit) =
13-
Div(modifierOrAttrs.toAttrs()) { content() }
20+
actual fun Box(modifierOrAttrs: ModifierOrAttrs<BoxElement>, content: @Composable BoxScope.() -> Unit) =
21+
Div(modifierOrAttrs.toAttrs()) { BoxScope.Impl(this).content() }

compose-multiplatform-common/src/jvmMain/kotlin/com/huanshankeji/compose/layout/Layouts.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import com.huanshankeji.compose.ui.toModifier
77

88
actual abstract class BoxElement : Element()
99

10+
actual typealias BoxScope = androidx.compose.foundation.layout.BoxScope
11+
1012
@Composable
11-
actual fun Box(modifierOrAttrs: ModifierOrAttrs<BoxElement>, content: @Composable () -> Unit) =
12-
androidx.compose.foundation.layout.Box(modifierOrAttrs.toModifier()) { content() }
13+
actual fun Box(modifierOrAttrs: ModifierOrAttrs<BoxElement>, content: @Composable BoxScope.() -> Unit) =
14+
androidx.compose.foundation.layout.Box(modifierOrAttrs.toModifier(), content = content)

0 commit comments

Comments
 (0)