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

Fix PullRefreshIndicator theming and placement #1220

Merged
merged 1 commit into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions app/src/main/java/com/jerboa/ui/components/common/AppBars.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -165,8 +165,6 @@ fun CommunityActivity(
else -> {}
}
},
// Needs to be lower else it can hide behind the top bar
refreshingOffset = 150.dp,
)

Scaffold(
Expand Down Expand Up @@ -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),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -344,7 +344,7 @@ fun InboxTabs(
}

Box(modifier = Modifier.pullRefresh(refreshState)) {
PullRefreshIndicator(
JerboaPullRefreshIndicator(
refreshing,
refreshState,
Modifier
Expand Down Expand Up @@ -542,7 +542,7 @@ fun InboxTabs(
.pullRefresh(refreshState)
.fillMaxSize(),
) {
PullRefreshIndicator(
JerboaPullRefreshIndicator(
refreshing,
refreshState,
Modifier
Expand Down Expand Up @@ -752,7 +752,7 @@ fun InboxTabs(
.pullRefresh(refreshState)
.fillMaxSize(),
) {
PullRefreshIndicator(
JerboaPullRefreshIndicator(
refreshing,
refreshState,
Modifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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),
)
Expand Down