@@ -44,7 +44,11 @@ import androidx.compose.foundation.lazy.grid.LazyHorizontalGrid
4444import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
4545import androidx.compose.material3.AlertDialog
4646import androidx.compose.material3.Button
47+ import androidx.compose.material3.ButtonDefaults
4748import androidx.compose.material3.CircularProgressIndicator
49+ import androidx.compose.material3.ProgressIndicatorDefaults
50+ import androidx.compose.material3.SliderDefaults
51+ import androidx.compose.material3.SwitchDefaults
4852import androidx.compose.material3.DatePicker
4953import androidx.compose.material3.DatePickerDialog
5054import androidx.compose.material3.rememberDatePickerState
@@ -150,6 +154,7 @@ internal val LocalInheritedFontSize = compositionLocalOf { TextUnit.Unspecified
150154internal val LocalInheritedFontWeight = compositionLocalOf<FontWeight ?> { null }
151155internal val LocalInheritedColor = compositionLocalOf { Color .Unspecified }
152156internal val LocalInheritedDisabled = compositionLocalOf { false }
157+ internal val LocalTint = compositionLocalOf<Color ?> { null }
153158
154159// / Interprets a Swift-evaluated node tree into Material 3 composables.
155160// /
@@ -180,6 +185,7 @@ internal fun RenderChild(node: ViewNode) {
180185 var fontWeight = LocalInheritedFontWeight .current
181186 var color = LocalInheritedColor .current
182187 var disabled = LocalInheritedDisabled .current
188+ var tint = LocalTint .current
183189 for (m in node.modifiers) {
184190 when (m.kind) {
185191 " font" -> {
@@ -193,6 +199,7 @@ internal fun RenderChild(node: ViewNode) {
193199 " fontWeight" -> m.args.string(" weight" )?.let { fontWeight = fontWeightFor(it) }
194200 " foregroundColor" -> m.args.long(" color" )?.let { color = Color (it.toInt()) }
195201 " disabled" -> if ((m.args[" value" ] as ? kotlinx.serialization.json.JsonPrimitive )?.content == " true" ) disabled = true
202+ " tint" -> m.args.long(" color" )?.let { tint = Color (it.toInt()) }
196203 }
197204 }
198205
@@ -202,6 +209,7 @@ internal fun RenderChild(node: ViewNode) {
202209 LocalInheritedFontWeight provides fontWeight,
203210 LocalInheritedColor provides color,
204211 LocalInheritedDisabled provides disabled,
212+ LocalTint provides tint,
205213 ) { RenderResolved (node) }
206214}
207215
@@ -214,10 +222,12 @@ private fun RenderResolved(node: ViewNode) {
214222
215223 " Button" -> {
216224 val onTap = node.long(" onTap" )
225+ val tint = LocalTint .current
217226 Button (
218227 // own disabled and any inherited `.disabled` both apply
219228 onClick = { onTap?.let { SwiftBridge .sink.invokeVoid(it) } },
220229 enabled = ! node.isDisabled() && ! LocalInheritedDisabled .current,
230+ colors = if (tint != null ) ButtonDefaults .buttonColors(containerColor = tint) else ButtonDefaults .buttonColors(),
221231 modifier = node.composeModifiers(),
222232 ) {
223233 RenderChildren (node)
@@ -226,11 +236,13 @@ private fun RenderResolved(node: ViewNode) {
226236
227237 " Toggle" -> {
228238 val onChange = node.long(" onChange" )
239+ val tint = LocalTint .current
229240 Row (verticalAlignment = Alignment .CenterVertically , modifier = node.composeModifiers()) {
230241 RenderChildren (node)
231242 Switch (
232243 checked = node.bool(" isOn" ) ? : false ,
233244 onCheckedChange = { onChange?.let { id -> SwiftBridge .sink.invokeBool(id, it) } },
245+ colors = if (tint != null ) SwitchDefaults .colors(checkedTrackColor = tint) else SwitchDefaults .colors(),
234246 )
235247 }
236248 }
@@ -313,21 +325,31 @@ private fun RenderResolved(node: ViewNode) {
313325
314326 " ProgressView" -> {
315327 val value = node.double(" value" )
328+ val tint = LocalTint .current
316329 if (value != null ) {
317- LinearProgressIndicator (progress = { value.toFloat() }, modifier = node.composeModifiers().fillMaxWidth())
330+ LinearProgressIndicator (
331+ progress = { value.toFloat() },
332+ color = tint ? : ProgressIndicatorDefaults .linearColor,
333+ modifier = node.composeModifiers().fillMaxWidth(),
334+ )
318335 } else {
319- CircularProgressIndicator (modifier = node.composeModifiers())
336+ CircularProgressIndicator (
337+ color = tint ? : ProgressIndicatorDefaults .circularColor,
338+ modifier = node.composeModifiers(),
339+ )
320340 }
321341 }
322342
323343 " Slider" -> {
324344 val onChange = node.long(" onChange" )
325345 val min = (node.double(" min" ) ? : 0.0 ).toFloat()
326346 val max = (node.double(" max" ) ? : 1.0 ).toFloat()
347+ val tint = LocalTint .current
327348 Slider (
328349 value = (node.double(" value" ) ? : 0.0 ).toFloat(),
329350 onValueChange = { onChange?.let { id -> SwiftBridge .sink.invokeDouble(id, it.toDouble()) } },
330351 valueRange = min.. max,
352+ colors = if (tint != null ) SliderDefaults .colors(thumbColor = tint, activeTrackColor = tint) else SliderDefaults .colors(),
331353 modifier = node.composeModifiers().fillMaxWidth(),
332354 )
333355 }
0 commit comments