diff --git a/app/src/main/java/com/example/android/architecture/blueprints/todoapp/addedittask/AddEditTaskScreen.kt b/app/src/main/java/com/example/android/architecture/blueprints/todoapp/addedittask/AddEditTaskScreen.kt index 26e381546..51c902295 100644 --- a/app/src/main/java/com/example/android/architecture/blueprints/todoapp/addedittask/AddEditTaskScreen.kt +++ b/app/src/main/java/com/example/android/architecture/blueprints/todoapp/addedittask/AddEditTaskScreen.kt @@ -50,8 +50,7 @@ import androidx.lifecycle.compose.ExperimentalLifecycleComposeApi import androidx.lifecycle.compose.collectAsStateWithLifecycle import com.example.android.architecture.blueprints.todoapp.R import com.example.android.architecture.blueprints.todoapp.util.AddEditTaskTopAppBar -import com.google.accompanist.swiperefresh.SwipeRefresh -import com.google.accompanist.swiperefresh.rememberSwipeRefreshState +import com.example.android.architecture.blueprints.todoapp.util.LoadingContent @OptIn(ExperimentalLifecycleComposeApi::class) @Composable @@ -112,11 +111,12 @@ private fun AddEditTaskContent( modifier: Modifier = Modifier ) { if (loading) { - SwipeRefresh( - // Show the loading spinner—`loading` is `true` in this code path - state = rememberSwipeRefreshState(true), + LoadingContent( + loading = true, onRefresh = { /* DO NOTHING */ }, - content = { }, + empty = false, + emptyContent = { /* DO NOTHING */ }, + content = {} ) } else { Column( diff --git a/app/src/main/java/com/example/android/architecture/blueprints/todoapp/tasks/TasksScreen.kt b/app/src/main/java/com/example/android/architecture/blueprints/todoapp/tasks/TasksScreen.kt index 16cf81e86..52fa2a2a8 100644 --- a/app/src/main/java/com/example/android/architecture/blueprints/todoapp/tasks/TasksScreen.kt +++ b/app/src/main/java/com/example/android/architecture/blueprints/todoapp/tasks/TasksScreen.kt @@ -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 ) { diff --git a/app/src/main/java/com/example/android/architecture/blueprints/todoapp/util/ComposeUtils.kt b/app/src/main/java/com/example/android/architecture/blueprints/todoapp/util/ComposeUtils.kt index 84d641712..89b3e043f 100644 --- a/app/src/main/java/com/example/android/architecture/blueprints/todoapp/util/ComposeUtils.kt +++ b/app/src/main/java/com/example/android/architecture/blueprints/todoapp/util/ComposeUtils.kt @@ -16,11 +16,15 @@ 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 -import com.google.accompanist.swiperefresh.rememberSwipeRefreshState val primaryDarkColor: Color = Color(0xFF263238) @@ -34,6 +38,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 +48,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)) } }