Skip to content

Commit

Permalink
Merge pull request #948 from Corvus400/enhancement/implement_loading_…
Browse files Browse the repository at this point in the history
…ui_state_contributors_screen

♻️ [iOS & Android ContributorsScreen]Added loading indicator since it is missing.
  • Loading branch information
ry-itto committed Sep 5, 2024
2 parents c08832c + 4234e4d commit b1daaea
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,26 @@ struct KmpPresenterContributorView: View {

var body: some View {
Group {
if let contributors = currentState.map(\.contributors) {
ScrollView {
LazyVStack(spacing: 0) {
ForEach(contributors, id: \.id) { value in
let contributor = Model.Contributor(
id: Int(value.id),
userName: value.username,
profileUrl: value.profileUrl.map { URL(string: $0)! } ,
iconUrl: URL(string: value.iconUrl)!
)
ContributorListItemView(
contributor: contributor,
onContributorButtonTapped: onContributorButtonTapped
)
if let state = currentState {
if let existsState = state as? Exists {
ScrollView {
LazyVStack(spacing: 0) {
ForEach(existsState.contributors, id: \.id) { value in
let contributor = Model.Contributor(
id: Int(value.id),
userName: value.username,
profileUrl: value.profileUrl.map { URL(string: $0)! },
iconUrl: URL(string: value.iconUrl)!
)
ContributorListItemView(
contributor: contributor,
onContributorButtonTapped: onContributorButtonTapped
)
}
}
}
} else if state is Loading {
ProgressView()
}
} else {
ProgressView()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
package io.github.droidkaigi.confsched.contributors

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Scaffold
import androidx.compose.material3.SnackbarHost
import androidx.compose.material3.SnackbarHostState
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.platform.testTag
Expand Down Expand Up @@ -46,10 +49,18 @@ fun NavGraphBuilder.contributorsScreens(
}
}

data class ContributorsUiState(
sealed class ContributorsUiState {
abstract val userMessageStateHolder: UserMessageStateHolder
}

class Loading(
override val userMessageStateHolder: UserMessageStateHolder,
) : ContributorsUiState()

class Exists(
override val userMessageStateHolder: UserMessageStateHolder,
val contributors: PersistentList<Contributor>,
val userMessageStateHolder: UserMessageStateHolder,
)
) : ContributorsUiState()

@Composable
fun ContributorsScreen(
Expand Down Expand Up @@ -109,21 +120,33 @@ fun ContributorsScreen(
}
},
) { padding ->
Contributors(
contributors = uiState.contributors,
onContributorsItemClick = onContributorsItemClick,
contentPadding = PaddingValues(bottom = padding.calculateBottomPadding()),
modifier = Modifier
.fillMaxSize()
.padding(top = padding.calculateTopPadding())
.let {
if (scrollBehavior != null) {
it.nestedScroll(scrollBehavior.nestedScrollConnection)
} else {
it
}
},
)
when (uiState) {
is Exists -> {
Contributors(
contributors = uiState.contributors,
onContributorsItemClick = onContributorsItemClick,
contentPadding = PaddingValues(bottom = padding.calculateBottomPadding()),
modifier = Modifier
.fillMaxSize()
.padding(top = padding.calculateTopPadding())
.let {
if (scrollBehavior != null) {
it.nestedScroll(scrollBehavior.nestedScrollConnection)
} else {
it
}
},
)
}
is Loading -> {
Box(
contentAlignment = Alignment.Center,
modifier = Modifier.padding(padding).fillMaxSize(),
) {
CircularProgressIndicator()
}
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ fun contributorsScreenPresenter(
val contributors by rememberUpdatedState(contributorsRepository.contributors())
EventEffect(events) { event ->
}
ContributorsUiState(
if (contributors.isEmpty()) return@providePresenterDefaults Loading(userMessageStateHolder)
Exists(
contributors = contributors,
userMessageStateHolder = userMessageStateHolder,
)
Expand Down

0 comments on commit b1daaea

Please sign in to comment.