update to Jetpack Compose dev05
This commit is contained in:
parent
b1c7d2c89f
commit
80e6da5274
2 changed files with 20 additions and 16 deletions
|
@ -34,10 +34,12 @@ dependencies {
|
||||||
implementation 'androidx.appcompat:appcompat:1.1.0'
|
implementation 'androidx.appcompat:appcompat:1.1.0'
|
||||||
implementation 'androidx.core:core-ktx:1.1.0'
|
implementation 'androidx.core:core-ktx:1.1.0'
|
||||||
|
|
||||||
implementation 'androidx.ui:ui-framework:0.1.0-dev03'
|
implementation 'androidx.ui:ui-framework:0.1.0-dev05'
|
||||||
implementation 'androidx.ui:ui-layout:0.1.0-dev03'
|
implementation 'androidx.ui:ui-layout:0.1.0-dev05'
|
||||||
implementation 'androidx.ui:ui-material:0.1.0-dev03'
|
implementation 'androidx.ui:ui-material:0.1.0-dev05'
|
||||||
implementation 'androidx.ui:ui-tooling:0.1.0-dev03'
|
implementation 'androidx.ui:ui-tooling:0.1.0-dev05'
|
||||||
|
implementation 'androidx.ui:ui-graphics:0.1.0-dev05'
|
||||||
|
|
||||||
|
|
||||||
implementation 'com.google.android.material:material:1.0.0'
|
implementation 'com.google.android.material:material:1.0.0'
|
||||||
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
|
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
|
||||||
|
|
|
@ -6,11 +6,11 @@ import androidx.compose.*
|
||||||
import androidx.lifecycle.LiveData
|
import androidx.lifecycle.LiveData
|
||||||
import androidx.lifecycle.Observer
|
import androidx.lifecycle.Observer
|
||||||
import androidx.ui.core.Text
|
import androidx.ui.core.Text
|
||||||
import androidx.ui.core.dp
|
|
||||||
import androidx.ui.core.setContent
|
import androidx.ui.core.setContent
|
||||||
import androidx.ui.layout.Column
|
import androidx.ui.layout.Column
|
||||||
import androidx.ui.layout.Padding
|
import androidx.ui.layout.LayoutPadding
|
||||||
import androidx.ui.material.MaterialTheme
|
import androidx.ui.material.MaterialTheme
|
||||||
|
import androidx.ui.unit.dp
|
||||||
import com.surrus.common.remote.Assignment
|
import com.surrus.common.remote.Assignment
|
||||||
import org.koin.android.viewmodel.ext.android.viewModel
|
import org.koin.android.viewmodel.ext.android.viewModel
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ class MainActivity : AppCompatActivity() {
|
||||||
@Composable
|
@Composable
|
||||||
fun mainLayout(peopleInSpaceViewModel: PeopleInSpaceViewModel) {
|
fun mainLayout(peopleInSpaceViewModel: PeopleInSpaceViewModel) {
|
||||||
MaterialTheme {
|
MaterialTheme {
|
||||||
val people = +observe(peopleInSpaceViewModel.peopleInSpace)
|
val people = observe(peopleInSpaceViewModel.peopleInSpace)
|
||||||
Column {
|
Column {
|
||||||
people?.forEach { person ->
|
people?.forEach { person ->
|
||||||
Row(person)
|
Row(person)
|
||||||
|
@ -40,24 +40,26 @@ fun mainLayout(peopleInSpaceViewModel: PeopleInSpaceViewModel) {
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun Row(person: Assignment) {
|
fun Row(person: Assignment) {
|
||||||
Padding(16.dp) {
|
Text(
|
||||||
Text(text = "${person.name} (${person.craft})")
|
text = "${person.name} (${person.craft})",
|
||||||
}
|
modifier = LayoutPadding(16.dp)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// from https://medium.com/swlh/android-mvi-with-jetpack-compose-b0890f5156ac
|
// from https://medium.com/swlh/android-mvi-with-jetpack-compose-b0890f5156ac
|
||||||
fun <T> observe(data: LiveData<T>) = effectOf<T?> {
|
// update: since dev05, version from that article was updated based
|
||||||
val result = +state<T?> { data.value }
|
// on https://twitter.com/intelligibabble/status/1205318193960472576
|
||||||
val observer = +memo { Observer<T> { result.value = it } }
|
@Composable fun <T> observe(data: LiveData<T>) : T? {
|
||||||
|
val result = state<T?> { data.value }
|
||||||
|
val observer = remember { Observer<T> { result.value = it } }
|
||||||
|
|
||||||
+onCommit(data) {
|
onCommit(data) {
|
||||||
data.observeForever(observer)
|
data.observeForever(observer)
|
||||||
onDispose { data.removeObserver(observer) }
|
onDispose { data.removeObserver(observer) }
|
||||||
}
|
}
|
||||||
|
|
||||||
result.value
|
return result.value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue