Skip to content

Commit

Permalink
Fix Loading bar clipping behind content (#1540)
Browse files Browse the repository at this point in the history
Co-authored-by: Dessalines <[email protected]>
  • Loading branch information
MV-GH and dessalines authored Jun 13, 2024
1 parent 6b74822 commit 9a7c7f8
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 211 deletions.
2 changes: 2 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 @@ -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 @@ -732,6 +733,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 @@ -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.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
Expand All @@ -45,7 +42,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 @@ -56,9 +52,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 @@ -230,26 +225,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 @@ -434,26 +411,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 @@ -630,26 +589,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 @@ -671,9 +612,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 @@ -25,9 +25,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 @@ -54,7 +51,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 @@ -71,6 +67,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 @@ -661,11 +658,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 @@ -694,15 +690,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

0 comments on commit 9a7c7f8

Please sign in to comment.