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: scrolling button not scroll to first/last item #335

Closed
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 @@ -19,25 +19,20 @@ import androidx.compose.material3.Text as ZeText

@Composable
fun ZeFloatingScroller(
coroutineScope: CoroutineScope,
lazyListState: LazyListState,
scrollLength: Float,
modifier: Modifier = Modifier,
text: String,
onClick: () -> Unit,
) {
FloatingActionButton(
containerColor = ZeBlack,
modifier = Modifier
modifier = modifier
.padding(16.dp)
.border(
width = 1.dp,
color = ZeWhite,
shape = RoundedCornerShape(16.dp),
),
onClick = {
coroutineScope.launch {
lazyListState.animateScrollBy(scrollLength)
}
},
onClick = onClick,
) {
ZeText(
text = text,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package de.berlindroid.zeapp.zeui

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.derivedStateOf
Expand All @@ -14,13 +12,13 @@ import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import kotlinx.coroutines.launch

@Composable
fun ZeNavigationPad(
lazyListState: LazyListState,
) {
val coroutineScope = rememberCoroutineScope()
val scrollLength = 425f
val topReached by remember { derivedStateOf { lazyListState.layoutInfo.visibleItemsInfo.firstOrNull()?.offset == 0 } }
val bottomReached by remember {
derivedStateOf {
Expand All @@ -36,11 +34,14 @@ fun ZeNavigationPad(
horizontalAlignment = Alignment.End,
) {
if (!topReached) {
ZeFloatingScroller(coroutineScope, lazyListState, -scrollLength, "↑")
ZeFloatingScroller(text = "↑") {
coroutineScope.launch { lazyListState.animateScrollToItem(0) }
}
}
Spacer(modifier = Modifier.size(10.dp))
if (!bottomReached) {
ZeFloatingScroller(coroutineScope, lazyListState, scrollLength, "↓")
ZeFloatingScroller(text = "↓") {
coroutineScope.launch { lazyListState.animateScrollToItem(lazyListState.layoutInfo.totalItemsCount - 1) }
}
}
}
}