README update

This commit is contained in:
John O'Reilly 2019-12-22 21:34:15 +00:00
parent 1ffe7b570e
commit c039cb45ee

View file

@ -8,6 +8,78 @@ using **Jetpack Compose** and on iOS using **SwiftUI**
**Note**: You need to use Android Studio v4.0 (currently on Canary 6). Have tested on XCode v11.3
### SwiftUI Code
```
struct ContentView: View {
@ObservedObject var peopleInSpaceViewModel = PeopleInSpaceViewModel(repository: PeopleInSpaceRepository())
var body: some View {
NavigationView {
List(peopleInSpaceViewModel.people, id: \.name) { person in
PersonView(person: person)
}
.navigationBarTitle(Text("PeopleInSpace"), displayMode: .large)
.onAppear(perform: {
self.peopleInSpaceViewModel.fetch()
})
}
}
}
struct PersonView : View {
var person: Assignment
var body: some View {
HStack {
VStack(alignment: .leading) {
Text(person.name).font(.headline)
Text(person.craft).font(.subheadline)
}
}
}
```
### Jetpack Compose code
```
class MainActivity : AppCompatActivity() {
private val peopleInSpaceViewModel: PeopleInSpaceViewModel by viewModel()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
mainLayout(peopleInSpaceViewModel)
}
}
}
@Composable
fun mainLayout(peopleInSpaceViewModel: PeopleInSpaceViewModel) {
MaterialTheme {
val people = +observe(peopleInSpaceViewModel.peopleInSpace)
Column {
people?.forEach { person ->
Row(person)
}
}
}
}
@Composable
fun Row(person: Assignment) {
Padding(16.dp) {
Text(text = "${person.name} (${person.craft})")
}
}
```
### Languages, libraries and tools used
* [Kotlin](https://kotlinlang.org/)