Skip to content

add Profile Screen on Compose#38

Merged
aartikov merged 8 commits intoaartikov:composefrom
developer-kaczmarek:feature/profile_screen
Oct 7, 2021
Merged

add Profile Screen on Compose#38
aartikov merged 8 commits intoaartikov:composefrom
developer-kaczmarek:feature/profile_screen

Conversation

@developer-kaczmarek
Copy link
Collaborator

No description provided.


interface ProfileComponent {

val profileState: StateFlow<Loading.State<Profile>>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

было бы круто, если бы тип был:
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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Хотелось бы использовать тут смарт-касты. Это получится, если исправить тип profileState в ProfileComponent и добавить промежуточную переменную.

when (val profileState = component.profileState) {

}

load = { profileViewModel.loadProfile() }
)

override val profileState = profileLoading.stateFlow
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

вот тут написать и использовать утилиту:

override val profileState by profileLoading.stateFlow.collectAsState(coroutineScope)


implementation "com.google.accompanist:accompanist-swiperefresh:0.19.0"

implementation "io.insert-koin:koin-android:3.1.2"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

давай, организуем зависимости так же, как остальные сделаны

import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.launch

fun <T> StateFlow<T>.toComposeState(coroutineScope: CoroutineScope, startState: T = this.value): State<T> {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Давай, уберем возможность задавать 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)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

profileState - переименуем в state

@aartikov aartikov merged commit 2278e28 into aartikov:compose Oct 7, 2021
@developer-kaczmarek developer-kaczmarek deleted the feature/profile_screen branch November 28, 2021 12:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants