diff --git a/app/src/main/java/com/jerboa/ui/components/common/AppBars.kt b/app/src/main/java/com/jerboa/ui/components/common/AppBars.kt index 7a6058476..ce2fcf107 100644 --- a/app/src/main/java/com/jerboa/ui/components/common/AppBars.kt +++ b/app/src/main/java/com/jerboa/ui/components/common/AppBars.kt @@ -14,10 +14,13 @@ import androidx.compose.foundation.layout.FlowRow import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyListState import androidx.compose.foundation.lazy.rememberLazyListState +import androidx.compose.material.ExperimentalMaterialApi import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.KeyboardArrowDown import androidx.compose.material.icons.filled.KeyboardArrowUp import androidx.compose.material.icons.outlined.* +import androidx.compose.material.pullrefresh.PullRefreshIndicator +import androidx.compose.material.pullrefresh.PullRefreshState import androidx.compose.material3.* import androidx.compose.runtime.Composable import androidx.compose.runtime.DisposableEffect @@ -682,3 +685,28 @@ fun CreateSubmitHeader( }, ) } + +/** + * M3 doesn't have a built-in way to do this yet, so we have to do it ourselves. + * + * Supports M3 theming + */ +@OptIn(ExperimentalMaterialApi::class) +@Composable +fun JerboaPullRefreshIndicator( + refreshing: Boolean, + state: PullRefreshState, + modifier: Modifier = Modifier, + backgroundColor: Color = MaterialTheme.colorScheme.surfaceColorAtElevation(6.dp), + contentColor: Color = MaterialTheme.colorScheme.onSurface, + scale: Boolean = true, +) { + PullRefreshIndicator( + refreshing, + state, + modifier, + backgroundColor, + contentColor, + scale, + ) +} diff --git a/app/src/main/java/com/jerboa/ui/components/community/CommunityActivity.kt b/app/src/main/java/com/jerboa/ui/components/community/CommunityActivity.kt index b7e9f3df3..5ee70ee1a 100644 --- a/app/src/main/java/com/jerboa/ui/components/community/CommunityActivity.kt +++ b/app/src/main/java/com/jerboa/ui/components/community/CommunityActivity.kt @@ -3,11 +3,11 @@ package com.jerboa.ui.components.community import android.util.Log import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.padding import androidx.compose.foundation.lazy.rememberLazyListState import androidx.compose.material.ExperimentalMaterialApi import androidx.compose.material.icons.Icons import androidx.compose.material.icons.outlined.Add -import androidx.compose.material.pullrefresh.PullRefreshIndicator import androidx.compose.material.pullrefresh.pullRefresh import androidx.compose.material.pullrefresh.rememberPullRefreshState import androidx.compose.material3.ExperimentalMaterial3Api @@ -27,7 +27,6 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.input.nestedscroll.nestedScroll import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.stringResource -import androidx.compose.ui.unit.dp import androidx.compose.ui.zIndex import arrow.core.Either import com.jerboa.ConsumeReturn @@ -65,6 +64,7 @@ import com.jerboa.scrollToTop import com.jerboa.toEnumSafe import com.jerboa.ui.components.common.ApiEmptyText import com.jerboa.ui.components.common.ApiErrorText +import com.jerboa.ui.components.common.JerboaPullRefreshIndicator import com.jerboa.ui.components.common.JerboaSnackbarHost import com.jerboa.ui.components.common.LoadingBar import com.jerboa.ui.components.common.getCurrentAccount @@ -165,8 +165,6 @@ fun CommunityActivity( else -> {} } }, - // Needs to be lower else it can hide behind the top bar - refreshingOffset = 150.dp, ) Scaffold( @@ -251,10 +249,11 @@ fun CommunityActivity( content = { padding -> Box(modifier = Modifier.pullRefresh(pullRefreshState)) { // zIndex needed bc some elements of a post get drawn above it. - PullRefreshIndicator( + JerboaPullRefreshIndicator( communityViewModel.postsRes.isRefreshing(), pullRefreshState, Modifier + .padding(padding) .align(Alignment.TopCenter) .zIndex(100F), ) diff --git a/app/src/main/java/com/jerboa/ui/components/home/HomeActivity.kt b/app/src/main/java/com/jerboa/ui/components/home/HomeActivity.kt index 5e1a3a14f..c170aa968 100644 --- a/app/src/main/java/com/jerboa/ui/components/home/HomeActivity.kt +++ b/app/src/main/java/com/jerboa/ui/components/home/HomeActivity.kt @@ -5,11 +5,11 @@ import androidx.activity.compose.ReportDrawn import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.PaddingValues +import androidx.compose.foundation.layout.padding import androidx.compose.foundation.lazy.LazyListState import androidx.compose.material.ExperimentalMaterialApi import androidx.compose.material.icons.Icons import androidx.compose.material.icons.outlined.Add -import androidx.compose.material.pullrefresh.PullRefreshIndicator import androidx.compose.material.pullrefresh.pullRefresh import androidx.compose.material.pullrefresh.rememberPullRefreshState import androidx.compose.material3.DrawerState @@ -34,7 +34,6 @@ import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.stringResource import androidx.compose.ui.semantics.semantics import androidx.compose.ui.semantics.testTagsAsResourceId -import androidx.compose.ui.unit.dp import androidx.compose.ui.zIndex import com.jerboa.ConsumeReturn import com.jerboa.CreatePostDeps @@ -65,6 +64,7 @@ import com.jerboa.rootChannel import com.jerboa.scrollToTop import com.jerboa.ui.components.common.ApiEmptyText import com.jerboa.ui.components.common.ApiErrorText +import com.jerboa.ui.components.common.JerboaPullRefreshIndicator import com.jerboa.ui.components.common.JerboaSnackbarHost import com.jerboa.ui.components.common.LoadingBar import com.jerboa.ui.components.common.apiErrorToast @@ -237,16 +237,15 @@ fun MainPostListingsContent( onRefresh = { homeViewModel.refreshPosts(account) }, - // Needs to be lower else it can hide behind the top bar - refreshingOffset = 150.dp, ) Box(modifier = Modifier.pullRefresh(pullRefreshState)) { // zIndex needed bc some elements of a post get drawn above it. - PullRefreshIndicator( + JerboaPullRefreshIndicator( homeViewModel.postsRes.isRefreshing(), pullRefreshState, Modifier + .padding(padding) .align(Alignment.TopCenter) .zIndex(100f), ) diff --git a/app/src/main/java/com/jerboa/ui/components/inbox/InboxActivity.kt b/app/src/main/java/com/jerboa/ui/components/inbox/InboxActivity.kt index b7aed0e8c..6ab9d5efe 100644 --- a/app/src/main/java/com/jerboa/ui/components/inbox/InboxActivity.kt +++ b/app/src/main/java/com/jerboa/ui/components/inbox/InboxActivity.kt @@ -14,7 +14,6 @@ import androidx.compose.foundation.lazy.rememberLazyListState import androidx.compose.foundation.pager.HorizontalPager import androidx.compose.foundation.pager.rememberPagerState 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.material3.DrawerState @@ -70,6 +69,7 @@ import com.jerboa.ui.components.comment.mentionnode.CommentMentionNode import com.jerboa.ui.components.comment.replynode.CommentReplyNodeInbox import com.jerboa.ui.components.common.ApiEmptyText import com.jerboa.ui.components.common.ApiErrorText +import com.jerboa.ui.components.common.JerboaPullRefreshIndicator import com.jerboa.ui.components.common.JerboaSnackbarHost import com.jerboa.ui.components.common.LoadingBar import com.jerboa.ui.components.common.getCurrentAccount @@ -344,7 +344,7 @@ fun InboxTabs( } Box(modifier = Modifier.pullRefresh(refreshState)) { - PullRefreshIndicator( + JerboaPullRefreshIndicator( refreshing, refreshState, Modifier @@ -542,7 +542,7 @@ fun InboxTabs( .pullRefresh(refreshState) .fillMaxSize(), ) { - PullRefreshIndicator( + JerboaPullRefreshIndicator( refreshing, refreshState, Modifier @@ -752,7 +752,7 @@ fun InboxTabs( .pullRefresh(refreshState) .fillMaxSize(), ) { - PullRefreshIndicator( + JerboaPullRefreshIndicator( refreshing, refreshState, Modifier diff --git a/app/src/main/java/com/jerboa/ui/components/person/PersonProfileActivity.kt b/app/src/main/java/com/jerboa/ui/components/person/PersonProfileActivity.kt index 023185a1c..be8830bd3 100644 --- a/app/src/main/java/com/jerboa/ui/components/person/PersonProfileActivity.kt +++ b/app/src/main/java/com/jerboa/ui/components/person/PersonProfileActivity.kt @@ -15,7 +15,6 @@ import androidx.compose.foundation.lazy.rememberLazyListState import androidx.compose.foundation.pager.HorizontalPager import androidx.compose.foundation.pager.rememberPagerState 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.material3.DrawerState @@ -88,6 +87,7 @@ import com.jerboa.ui.components.comment.edit.CommentEditReturn import com.jerboa.ui.components.comment.reply.CommentReplyReturn import com.jerboa.ui.components.common.ApiEmptyText import com.jerboa.ui.components.common.ApiErrorText +import com.jerboa.ui.components.common.JerboaPullRefreshIndicator import com.jerboa.ui.components.common.JerboaSnackbarHost import com.jerboa.ui.components.common.LoadingBar import com.jerboa.ui.components.common.apiErrorToast @@ -469,7 +469,7 @@ fun UserTabs( .pullRefresh(pullRefreshState) .fillMaxSize(), ) { - PullRefreshIndicator( + JerboaPullRefreshIndicator( personProfileViewModel.personDetailsRes.isRefreshing(), pullRefreshState, // zIndex needed bc some elements of a post get drawn above it. @@ -712,7 +712,7 @@ fun UserTabs( .pullRefresh(pullRefreshState) .fillMaxSize(), ) { - PullRefreshIndicator( + JerboaPullRefreshIndicator( personProfileViewModel.personDetailsRes.isRefreshing(), pullRefreshState, // zIndex needed bc some elements of a post get drawn above it. diff --git a/app/src/main/java/com/jerboa/ui/components/post/PostActivity.kt b/app/src/main/java/com/jerboa/ui/components/post/PostActivity.kt index 4199a8964..75bed137f 100644 --- a/app/src/main/java/com/jerboa/ui/components/post/PostActivity.kt +++ b/app/src/main/java/com/jerboa/ui/components/post/PostActivity.kt @@ -5,6 +5,7 @@ import androidx.compose.foundation.focusable import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.foundation.lazy.LazyColumn @@ -13,7 +14,6 @@ import androidx.compose.material.ExperimentalMaterialApi import androidx.compose.material.icons.Icons import androidx.compose.material.icons.outlined.ArrowBack import androidx.compose.material.icons.outlined.Sort -import androidx.compose.material.pullrefresh.PullRefreshIndicator import androidx.compose.material.pullrefresh.pullRefresh import androidx.compose.material.pullrefresh.rememberPullRefreshState import androidx.compose.material3.ExperimentalMaterial3Api @@ -96,6 +96,7 @@ import com.jerboa.ui.components.comment.reply.CommentReplyReturn import com.jerboa.ui.components.common.ApiErrorText import com.jerboa.ui.components.common.CommentNavigationBottomAppBar import com.jerboa.ui.components.common.CommentSortOptionsDropdown +import com.jerboa.ui.components.common.JerboaPullRefreshIndicator import com.jerboa.ui.components.common.JerboaSnackbarHost import com.jerboa.ui.components.common.LoadingBar import com.jerboa.ui.components.common.apiErrorToast @@ -204,8 +205,6 @@ fun PostActivity( onRefresh = { postViewModel.getData(account, ApiState.Refreshing) }, - // Needs to be lower else it can hide behind the top bar - refreshingOffset = 150.dp, ) LaunchedEffect(Unit) { @@ -294,14 +293,19 @@ fun PostActivity( } }, content = { padding -> - Box(modifier = Modifier.pullRefresh(pullRefreshState)) { + Box( + modifier = Modifier + .fillMaxSize() + .pullRefresh(pullRefreshState), + ) { parentListStateIndexes.clear() lazyListIndexTracker = 2 - PullRefreshIndicator( + JerboaPullRefreshIndicator( postViewModel.postRes.isRefreshing(), pullRefreshState, // zIndex needed bc some elements of a post get drawn above it. Modifier + .padding(padding) .align(Alignment.TopCenter) .zIndex(100f), )