Declarative UI in the middle of a Whirlwind
Declarative UI seems to be the mainstream of the future in mobile programming.
Just as Apple introduces SwiftUI in WWDC 2019, and Google I/O last month develops Jetpack Compose, both dominant platforms offer their declarative toolkit for building UI. (And Google already have another framework, Flutter, that uses Dart to develop declarative UI.)
They are kinds of React, I am sure Jordan Walke will feel very proud.
SwiftUI is the power of Swift, and Jetpack Compose is built with the benefits of Kotlin as well. With the movement towards declarative UI, ObjC and Java will be eliminated faster than I expected before.
SwiftUI
import SwiftUI
struct ContentView: View {
var body: some View {
VStack(alignment: .leading) {
Text("Turtle Rock")
.font(.title)
HStack {
Text("Joshua Tree National Park")
.font(.subheadline)
Spacer()
Text("California")
.font(.subheadline)
}
}
.padding()
}
}
struct ContentView_Preview: PreviewProvider {
static var previews: some View {
ContentView()
}
}
Jetpack Compose
import androidx.compose.*
import androidx.ui.core.*
@Composable
fun Greeting(name: String) {
Text ("Hello $name!")
}
