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 Loading bar clipping behind content #1540

Merged
merged 2 commits into from
Jun 13, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.TextUnit
import androidx.compose.ui.unit.TextUnitType
import androidx.compose.ui.unit.dp
import androidx.compose.ui.zIndex
import com.jerboa.R
import com.jerboa.api.ApiState
import com.jerboa.datatypes.UserViewType
Expand Down Expand Up @@ -734,6 +735,7 @@ fun LoadingBar(padding: PaddingValues = PaddingValues(0.dp)) {
Modifier
.fillMaxWidth()
.padding(padding)
.zIndex(99F)
.testTag("jerboa:loading"),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import com.jerboa.isScrolledToEnd
@Composable
fun TriggerWhenReachingEnd(
listState: LazyListState,
loadMorePosts: () -> Unit,
showPostAppendRetry: Boolean,
loadMorePosts: () -> Unit,
) {
// observer when reached end of list
val endOfListReached by remember {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,11 +287,10 @@ fun CommunityScreen(
accountViewModel,
) {
communityViewModel.savePost(
form =
SavePost(
post_id = postView.post.id,
save = !postView.saved,
),
form = SavePost(
post_id = postView.post.id,
save = !postView.saved,
),
)
}
},
Expand Down
78 changes: 9 additions & 69 deletions app/src/main/java/com/jerboa/ui/components/inbox/InboxScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.material3.pulltorefresh.PullToRefreshBox
import androidx.compose.material3.rememberTopAppBarState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
Expand All @@ -44,7 +41,6 @@ import com.jerboa.feat.VoteType
import com.jerboa.feat.doIfReadyElseDisplayInfo
import com.jerboa.feat.newVote
import com.jerboa.getCommentParentId
import com.jerboa.isScrolledToEnd
import com.jerboa.model.AccountViewModel
import com.jerboa.model.InboxViewModel
import com.jerboa.model.ReplyItem
Expand All @@ -55,9 +51,8 @@ import com.jerboa.ui.components.common.ApiEmptyText
import com.jerboa.ui.components.common.ApiErrorText
import com.jerboa.ui.components.common.JerboaLoadingBar
import com.jerboa.ui.components.common.JerboaSnackbarHost
import com.jerboa.ui.components.common.LoadingBar
import com.jerboa.ui.components.common.TriggerWhenReachingEnd
import com.jerboa.ui.components.common.getCurrentAccount
import com.jerboa.ui.components.common.isLoading
import com.jerboa.ui.components.common.isRefreshing
import com.jerboa.ui.components.common.simpleVerticalScrollbar
import com.jerboa.ui.components.privatemessage.PrivateMessage
Expand Down Expand Up @@ -231,26 +226,8 @@ fun InboxTabs(
InboxTab.Replies.ordinal -> {
val listState = rememberLazyListState()

// observer when reached end of list
val endOfListReached by remember {
derivedStateOf {
listState.isScrolledToEnd()
}
}

// act when end of list reached
if (endOfListReached) {
LaunchedEffect(Unit) {
account.doIfReadyElseDisplayInfo(
appState,
ctx,
snackbarHostState,
scope,
siteViewModel,
) {
inboxViewModel.appendReplies()
}
}
TriggerWhenReachingEnd(listState, false) {
inboxViewModel.appendReplies()
}

val goToComment = { crv: CommentReplyView ->
Expand Down Expand Up @@ -435,26 +412,8 @@ fun InboxTabs(
InboxTab.Mentions.ordinal -> {
val listState = rememberLazyListState()

// observer when reached end of list
val endOfListReached by remember {
derivedStateOf {
listState.isScrolledToEnd()
}
}

// act when end of list reached
if (endOfListReached) {
LaunchedEffect(Unit) {
account.doIfReadyElseDisplayInfo(
appState,
ctx,
snackbarHostState,
scope,
siteViewModel,
) {
inboxViewModel.appendMentions()
}
}
TriggerWhenReachingEnd(listState, false) {
inboxViewModel.appendMentions()
}

PullToRefreshBox(
Expand Down Expand Up @@ -631,26 +590,8 @@ fun InboxTabs(
InboxTab.Messages.ordinal -> {
val listState = rememberLazyListState()

// observer when reached end of list
val endOfListReached by remember {
derivedStateOf {
listState.isScrolledToEnd()
}
}

// act when end of list reached
if (endOfListReached) {
LaunchedEffect(Unit) {
account.doIfReadyElseDisplayInfo(
appState,
ctx,
snackbarHostState,
scope,
siteViewModel,
) {
inboxViewModel.appendMessages()
}
}
TriggerWhenReachingEnd(listState, false) {
inboxViewModel.appendMessages()
}

PullToRefreshBox(
Expand All @@ -672,9 +613,8 @@ fun InboxTabs(
}
},
) {
if (inboxViewModel.messagesRes.isLoading()) {
LoadingBar()
}
JerboaLoadingBar(inboxViewModel.messagesRes)

when (val messagesRes = inboxViewModel.messagesRes) {
ApiState.Empty -> ApiEmptyText()
is ApiState.Failure -> ApiErrorText(messagesRes.msg)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.material3.pulltorefresh.PullToRefreshBox
import androidx.compose.material3.rememberTopAppBarState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateListOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
Expand All @@ -53,7 +50,6 @@ import com.jerboa.feat.VoteType
import com.jerboa.feat.canMod
import com.jerboa.feat.doIfReadyElseDisplayInfo
import com.jerboa.feat.newVote
import com.jerboa.isScrolledToEnd
import com.jerboa.model.AccountViewModel
import com.jerboa.model.AppSettingsViewModel
import com.jerboa.model.PersonProfileViewModel
Expand All @@ -70,6 +66,7 @@ import com.jerboa.ui.components.common.ApiErrorText
import com.jerboa.ui.components.common.JerboaLoadingBar
import com.jerboa.ui.components.common.JerboaSnackbarHost
import com.jerboa.ui.components.common.LoadingBar
import com.jerboa.ui.components.common.TriggerWhenReachingEnd
import com.jerboa.ui.components.common.apiErrorToast
import com.jerboa.ui.components.common.getCurrentAccount
import com.jerboa.ui.components.common.getPostViewMode
Expand Down Expand Up @@ -662,11 +659,10 @@ fun UserTabs(

val listState = rememberLazyListState()

// observer when reached end of list
val endOfListReached by remember {
derivedStateOf {
listState.isScrolledToEnd()
}
TriggerWhenReachingEnd(listState, false) {
personProfileViewModel.appendData(
profileRes.data.person_view.person.id,
)
}

// Holds the un-expanded comment ids
Expand Down Expand Up @@ -695,15 +691,6 @@ fun UserTabs(

val showActionBarByDefault = true

// act when end of list reached
if (endOfListReached) {
LaunchedEffect(Unit) {
personProfileViewModel.appendData(
profileRes.data.person_view.person.id,
)
}
}

CommentNodes(
nodes = nodes,
admins = siteViewModel.admins(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ fun PostListings(
}
}

TriggerWhenReachingEnd(listState, loadMorePosts, showPostAppendRetry)
TriggerWhenReachingEnd(listState, showPostAppendRetry, loadMorePosts)
}

@Preview
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ import androidx.compose.material3.TopAppBar
import androidx.compose.material3.TopAppBarScrollBehavior
import androidx.compose.material3.pulltorefresh.PullToRefreshBox
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
Expand All @@ -56,7 +54,6 @@ import com.jerboa.datatypes.samplePendingRegistrationApplicationView
import com.jerboa.db.entity.Account
import com.jerboa.db.entity.AnonAccount
import com.jerboa.feat.doIfReadyElseDisplayInfo
import com.jerboa.isScrolledToEnd
import com.jerboa.model.RegistrationApplicationsViewModel
import com.jerboa.model.SiteViewModel
import com.jerboa.ui.components.common.ApiEmptyText
Expand All @@ -66,6 +63,7 @@ import com.jerboa.ui.components.common.JerboaLoadingBar
import com.jerboa.ui.components.common.MarkdownTextField
import com.jerboa.ui.components.common.MyMarkdownText
import com.jerboa.ui.components.common.TimeAgo
import com.jerboa.ui.components.common.TriggerWhenReachingEnd
import com.jerboa.ui.components.common.UnreadOrAllOptionsDropDown
import com.jerboa.ui.components.common.isRefreshing
import com.jerboa.ui.components.common.simpleVerticalScrollbar
Expand Down Expand Up @@ -156,25 +154,15 @@ fun RegistrationApplications(
) {
val listState = rememberLazyListState()

// observer when reached end of list
val endOfListReached by remember {
derivedStateOf {
listState.isScrolledToEnd()
}
}

// act when end of list reached
if (endOfListReached) {
LaunchedEffect(Unit) {
account.doIfReadyElseDisplayInfo(
appState,
ctx,
snackbarHostState,
scope,
siteViewModel,
) {
registrationApplicationsViewModel.appendApplications()
}
TriggerWhenReachingEnd(listState, false) {
account.doIfReadyElseDisplayInfo(
appState,
ctx,
snackbarHostState,
scope,
siteViewModel,
) {
registrationApplicationsViewModel.appendApplications()
}
}

Expand Down
Loading