add Profile Screen on Compose#38
Conversation
compose-sample/src/main/kotlin/me/aartikov/sesamecomposesample/di/ViewModelModule.kt
Outdated
Show resolved
Hide resolved
|
|
||
| interface ProfileComponent { | ||
|
|
||
| val profileState: StateFlow<Loading.State<Profile>> |
There was a problem hiding this comment.
было бы круто, если бы тип был:
val profileState: Loading.State<Profile>
Для этого нужно сделать утилитную функцию, которая преобразует StateFlow в композовскую стейт-переменную.
| when (profileState) { | ||
| is Loading.State.Data -> { | ||
| val profileData = (profileState as Loading.State.Data<Profile>).data | ||
| val isRefreshing = (profileState as Loading.State.Data<Profile>).refreshing |
There was a problem hiding this comment.
Хотелось бы использовать тут смарт-касты. Это получится, если исправить тип profileState в ProfileComponent и добавить промежуточную переменную.
when (val profileState = component.profileState) {
}
compose-sample/src/main/kotlin/me/aartikov/sesamecomposesample/profile/ui/ProfileUi.kt
Outdated
Show resolved
Hide resolved
| load = { profileViewModel.loadProfile() } | ||
| ) | ||
|
|
||
| override val profileState = profileLoading.stateFlow |
There was a problem hiding this comment.
вот тут написать и использовать утилиту:
override val profileState by profileLoading.stateFlow.collectAsState(coroutineScope)
compose-sample/src/main/kotlin/me/aartikov/sesamecomposesample/theme/Theme.kt
Outdated
Show resolved
Hide resolved
compose-sample/build.gradle
Outdated
|
|
||
| implementation "com.google.accompanist:accompanist-swiperefresh:0.19.0" | ||
|
|
||
| implementation "io.insert-koin:koin-android:3.1.2" |
There was a problem hiding this comment.
давай, организуем зависимости так же, как остальные сделаны
| import kotlinx.coroutines.flow.collect | ||
| import kotlinx.coroutines.launch | ||
|
|
||
| fun <T> StateFlow<T>.toComposeState(coroutineScope: CoroutineScope, startState: T = this.value): State<T> { |
There was a problem hiding this comment.
Давай, уберем возможность задавать startState. Всегда будем брать начальное значение из this.value
| import kotlinx.coroutines.launch | ||
|
|
||
| fun <T> StateFlow<T>.toComposeState(coroutineScope: CoroutineScope, startState: T = this.value): State<T> { | ||
| val profileState: MutableState<T> = mutableStateOf(startState) |
There was a problem hiding this comment.
profileState - переименуем в state
No description provided.