Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pull to refresh doesn't work when there are no tasks #934

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
Migration of swipe refresh to PullRefresh and also resolving issues o…
…f showing a spinner loading when task list is empty
AnirudhPudari committed Mar 27, 2023
commit 1f90fb6af54d761fd1fc009ffc645fdb83d7a798
Original file line number Diff line number Diff line change
@@ -29,6 +29,8 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.Checkbox
import androidx.compose.material.FloatingActionButton
import androidx.compose.material.Icon
@@ -215,7 +217,7 @@ private fun TasksEmptyContent(
modifier: Modifier = Modifier
) {
Column(
modifier = modifier.fillMaxSize(),
modifier = modifier.fillMaxSize().verticalScroll(rememberScrollState()),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
Original file line number Diff line number Diff line change
@@ -16,7 +16,13 @@

package com.example.android.architecture.blueprints.todoapp.util

import androidx.compose.foundation.layout.Box
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material.pullrefresh.PullRefreshIndicator
import androidx.compose.material.pullrefresh.pullRefresh
import androidx.compose.material.pullrefresh.rememberPullRefreshState
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import com.google.accompanist.swiperefresh.SwipeRefresh
@@ -34,6 +40,7 @@ val primaryDarkColor: Color = Color(0xFF263238)
* @param modifier the modifier to apply to this layout.
* @param content (slot) the main content to show
*/
@OptIn(ExperimentalMaterialApi::class)
@Composable
fun LoadingContent(
loading: Boolean,
@@ -43,14 +50,13 @@ fun LoadingContent(
modifier: Modifier = Modifier,
content: @Composable () -> Unit
) {
if (empty) {
emptyContent()
} else {
SwipeRefresh(
state = rememberSwipeRefreshState(loading),
onRefresh = onRefresh,
modifier = modifier,
content = content,
)
val pullRefreshState = rememberPullRefreshState(loading, onRefresh)
Box(modifier = modifier.pullRefresh(pullRefreshState)) {
if (empty) {
emptyContent()
} else {
content()
}
PullRefreshIndicator(loading, pullRefreshState, Modifier.align(Alignment.TopCenter))
}
}