README update
This commit is contained in:
parent
1ffe7b570e
commit
c039cb45ee
1 changed files with 72 additions and 0 deletions
72
README.md
72
README.md
|
@ -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/)
|
||||
|
|
Loading…
Reference in a new issue