diff --git a/zeapp/android/src/main/java/de/berlindroid/zeapp/zeui/LazyListScrollDirections.kt b/zeapp/android/src/main/java/de/berlindroid/zeapp/zeui/LazyListScrollDirections.kt new file mode 100644 index 00000000..f9c61c43 --- /dev/null +++ b/zeapp/android/src/main/java/de/berlindroid/zeapp/zeui/LazyListScrollDirections.kt @@ -0,0 +1,5 @@ +package de.berlindroid.zeapp.zeui + +enum class LazyListScrollDirections { + UP, DOWN +} diff --git a/zeapp/android/src/main/java/de/berlindroid/zeapp/zeui/ZeFloatingScroller.kt b/zeapp/android/src/main/java/de/berlindroid/zeapp/zeui/ZeFloatingScroller.kt index 25df397f..328c892f 100644 --- a/zeapp/android/src/main/java/de/berlindroid/zeapp/zeui/ZeFloatingScroller.kt +++ b/zeapp/android/src/main/java/de/berlindroid/zeapp/zeui/ZeFloatingScroller.kt @@ -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 @@ -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 @@ -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, + ) + } } }, ) { diff --git a/zeapp/android/src/main/java/de/berlindroid/zeapp/zeui/ZeNavigationPad.kt b/zeapp/android/src/main/java/de/berlindroid/zeapp/zeui/ZeNavigationPad.kt index 7dc8a6a2..3f1b0703 100644 --- a/zeapp/android/src/main/java/de/berlindroid/zeapp/zeui/ZeNavigationPad.kt +++ b/zeapp/android/src/main/java/de/berlindroid/zeapp/zeui/ZeNavigationPad.kt @@ -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 } } @@ -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)) } }