SwiftyCompose
Build Composable components on iOS, Android, Desktop, and Web using SwiftUI-like syntax with this Compose Multiplatform library.
Try out the WASM build of the sample app at https://deanalvero.github.io/swiftycompose-compose-multiplatform/.
Dependency
Add the dependency to your build.gradle. Replace version with what is available here.
implementation("io.github.deanalvero:swiftycompose-cmp:<version>")
Usage
Prepend an !, +, or a - before the SwiftUI view name.
@Composable
fun ExampleComposable() {
!HStack {
+Text(
text = "Swifty"
).background(color = Color.Blue)
.strikethrough()
.underline()
-Text(
text = "Compose"
).bold()
}.background(color = Color.Red)
}
Or, call (), invoke(), or build() at the end the chain call.
@Composable
fun ExampleComposable() {
// TODO: replace, for now this is equivalent to @State private var toggleValue: Bool = false
val toggleValue = stateBinding(false)
// TODO: replace, for now this is equivalent to @State private var sliderValue: =
val = stateBinding(f)
VStack {
Toggle(
= toggleValue
).background( = Color.Yellow)
.invoke()
Slider(
= sliderValue,
= f..f
)()
!ProgressView( = f)
.frame( = Dp.Infinity, height = .dp)
}.background( = Color.Green)
.build()
}
The choice is yours. I prefer to prepend ! though.
Supported Components
- VStack
- HStack
- ZStack
- LazyVStack
- LazyHStack
Notes
Enjoy!