Skip to content

Commit 2b18563

Browse files
committed
Render appearance modifiers, overlay, and fill-width colors
1 parent 90fe5bc commit 2b18563

1 file changed

Lines changed: 37 additions & 4 deletions

File tree

  • Demo/swiftui/src/commonMain/kotlin/com/pureswift/swiftui

Demo/swiftui/src/commonMain/kotlin/com/pureswift/swiftui/Render.kt

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.pureswift.swiftui
22

33
import androidx.compose.foundation.background
4+
import androidx.compose.foundation.border
45
import androidx.compose.foundation.clickable
56
import androidx.compose.foundation.rememberScrollState
67
import androidx.compose.foundation.horizontalScroll
@@ -94,6 +95,7 @@ import androidx.compose.ui.draw.alpha
9495
import androidx.compose.ui.draw.clip
9596
import androidx.compose.ui.draw.rotate
9697
import androidx.compose.ui.draw.scale
98+
import androidx.compose.ui.draw.shadow
9799
import androidx.compose.ui.graphics.Brush
98100
import androidx.compose.ui.graphics.Color
99101
import androidx.compose.ui.graphics.RectangleShape
@@ -193,13 +195,27 @@ fun Render(node: ViewNode) {
193195
}
194196
}
195197

198+
// A Color greedily fills the space offered it (SwiftUI semantics);
199+
// fillMaxWidth is applied after the chain so an explicit frame width
200+
// still constrains it.
196201
"Color" -> Box(
197202
modifier = node.composeModifiers()
203+
.fillMaxWidth()
198204
.background(Color((node.long("color") ?: 0).toInt()))
199205
)
200206

201207
"Image" -> RenderImage(node)
202208

209+
"Overlay" -> Box(
210+
contentAlignment = zStackAlignment(node),
211+
modifier = node.composeModifiers(),
212+
) {
213+
node.children.getOrNull(0)?.let { Render(it) }
214+
Box(modifier = Modifier.matchParentSize(), contentAlignment = zStackAlignment(node)) {
215+
node.children.getOrNull(1)?.let { Render(it) }
216+
}
217+
}
218+
203219
"Shape" -> RenderShape(node)
204220

205221
"LinearGradient" -> RenderGradient(node)
@@ -529,10 +545,10 @@ private fun RenderGradient(node: ViewNode) {
529545
startX == endX -> Brush.verticalGradient(colors)
530546
else -> Brush.linearGradient(colors)
531547
}
532-
// A gradient fills the available width by default (SwiftUI semantics); an
533-
// explicit frame width in the chain still constrains it. fillMaxWidth is
534-
// first so a cornerRadius clip in the chain sees the full width.
535-
Box(modifier = Modifier.fillMaxWidth().then(node.composeModifiers()).background(brush))
548+
// A gradient fills the available width by default (SwiftUI semantics);
549+
// fillMaxWidth is applied after the chain so an explicit frame width still
550+
// constrains it.
551+
Box(modifier = node.composeModifiers().fillMaxWidth().background(brush))
536552
}
537553

538554
@Composable
@@ -720,6 +736,23 @@ internal fun ViewNode.composeModifiers(): Modifier {
720736

721737
"opacity" -> modifier.alpha((entry.args.double("opacity") ?: 1.0).toFloat())
722738

739+
"border" -> {
740+
val color = entry.args.long("color")?.let { Color(it.toInt()) } ?: Color.Black
741+
modifier.border((entry.args.double("width") ?: 1.0).dp, color)
742+
}
743+
744+
"shadow" -> modifier.shadow((entry.args.double("radius") ?: 0.0).dp)
745+
746+
"clipShape" -> {
747+
val shape = when (entry.args.string("shape")) {
748+
"circle" -> CircleShape
749+
"capsule" -> RoundedCornerShape(percent = 50)
750+
"roundedRectangle" -> RoundedCornerShape((entry.args.double("cornerRadius") ?: 0.0).dp)
751+
else -> RectangleShape
752+
}
753+
modifier.clip(shape)
754+
}
755+
723756
"onTapGesture" -> {
724757
val id = entry.args.long("action")
725758
if (id != null) modifier.clickable { SwiftBridge.sink.invokeVoid(id) } else modifier

0 commit comments

Comments
 (0)