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

Fixes scroll TOP/BOTTOM scrolling #337

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
@@ -0,0 +1,5 @@
package de.berlindroid.zeapp.zeui

enum class LazyListScrollDirections {
UP, DOWN
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package de.berlindroid.zeapp.zeui

import androidx.compose.foundation.border
import androidx.compose.foundation.gestures.animateScrollBy
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.foundation.shape.RoundedCornerShape
Expand All @@ -21,9 +20,13 @@ import androidx.compose.material3.Text as ZeText
fun ZeFloatingScroller(
coroutineScope: CoroutineScope,
lazyListState: LazyListState,
scrollLength: Float,
text: String,
direction: LazyListScrollDirections,
) {
val text = when (direction) {
LazyListScrollDirections.UP -> "↑"
LazyListScrollDirections.DOWN -> "↓"
}

FloatingActionButton(
containerColor = ZeBlack,
modifier = Modifier
Expand All @@ -35,7 +38,12 @@ fun ZeFloatingScroller(
),
onClick = {
coroutineScope.launch {
lazyListState.animateScrollBy(scrollLength)
when (direction) {
LazyListScrollDirections.UP -> lazyListState.animateScrollToItem(0)
LazyListScrollDirections.DOWN -> lazyListState.animateScrollToItem(
lazyListState.layoutInfo.totalItemsCount - 1,
)
}
}
},
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,10 @@ 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 {

val topReached by remember {
derivedStateOf {
lazyListState.layoutInfo.visibleItemsInfo
.lastOrNull()?.index == lazyListState.layoutInfo.totalItemsCount - 1
lazyListState.firstVisibleItemIndex == 0 && lazyListState.firstVisibleItemScrollOffset == 0
}
}

Expand All @@ -35,12 +33,15 @@ fun ZeNavigationPad(
.padding(24.dp),
horizontalAlignment = Alignment.End,
) {
if (!topReached) {
ZeFloatingScroller(coroutineScope, lazyListState, -scrollLength, "↑")
}
Spacer(modifier = Modifier.size(10.dp))
if (!bottomReached) {
ZeFloatingScroller(coroutineScope, lazyListState, scrollLength, "↓")
}
ZeFloatingScroller(
coroutineScope = coroutineScope,
lazyListState = lazyListState,
direction = if (topReached) {
LazyListScrollDirections.DOWN
} else {
LazyListScrollDirections.UP
},
)
Spacer(modifier = Modifier.size(16.dp))
}
}