diff --git a/core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/component/scrollbar/AppScrollbars.kt b/core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/component/scrollbar/AppScrollbars.kt index ca282aa7a..fa913cb27 100644 --- a/core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/component/scrollbar/AppScrollbars.kt +++ b/core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/component/scrollbar/AppScrollbars.kt @@ -61,14 +61,14 @@ private const val SCROLLBAR_INACTIVE_TO_DORMANT_TIME_IN_MS = 2_000L * @param modifier a [Modifier] for the [Scrollbar] * @param state the driving state for the [Scrollbar] * @param orientation the orientation of the scrollbar - * @param onThumbDisplaced the fast scroll implementation + * @param onThumbMoved the fast scroll implementation */ @Composable fun ScrollableState.DraggableScrollbar( modifier: Modifier = Modifier, state: ScrollbarState, orientation: Orientation, - onThumbDisplaced: (Float) -> Unit, + onThumbMoved: (Float) -> Unit, ) { val interactionSource = remember { MutableInteractionSource() } Scrollbar( @@ -82,7 +82,7 @@ fun ScrollableState.DraggableScrollbar( orientation = orientation, ) }, - onThumbDisplaced = onThumbDisplaced, + onThumbMoved = onThumbMoved, ) } diff --git a/core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/component/scrollbar/LazyScrollbarUtilities.kt b/core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/component/scrollbar/LazyScrollbarUtilities.kt index c7ef8fe91..8c4063b15 100644 --- a/core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/component/scrollbar/LazyScrollbarUtilities.kt +++ b/core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/component/scrollbar/LazyScrollbarUtilities.kt @@ -78,7 +78,7 @@ internal inline fun LazyState.scrol ) ScrollbarState( thumbSizePercent = thumbSizePercent, - thumbDisplacementPercent = when { + thumbMovedPercent = when { reverseLayout() -> 1f - thumbTravelPercent else -> thumbTravelPercent }, diff --git a/core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/component/scrollbar/Scrollbar.kt b/core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/component/scrollbar/Scrollbar.kt index f4710f2c6..11997468c 100644 --- a/core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/component/scrollbar/Scrollbar.kt +++ b/core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/component/scrollbar/Scrollbar.kt @@ -80,7 +80,7 @@ value class ScrollbarState internal constructor( companion object { val FULL = ScrollbarState( thumbSizePercent = 1f, - thumbDisplacementPercent = 0f, + thumbMovedPercent = 0f, ) } } @@ -104,16 +104,16 @@ private value class ScrollbarTrack( * @param thumbSizePercent the thumb size of the scrollbar as a percentage of the total track size. * Refers to either the thumb width (for horizontal scrollbars) * or height (for vertical scrollbars). - * @param thumbDisplacementPercent the distance the thumb has traveled as a percentage of total + * @param thumbMovedPercent the distance the thumb has traveled as a percentage of total * track size. */ fun ScrollbarState( thumbSizePercent: Float, - thumbDisplacementPercent: Float, + thumbMovedPercent: Float, ) = ScrollbarState( packFloats( val1 = thumbSizePercent, - val2 = thumbDisplacementPercent, + val2 = thumbMovedPercent, ), ) @@ -126,7 +126,7 @@ val ScrollbarState.thumbSizePercent /** * Returns the distance the thumb has traveled as a percentage of total track size */ -val ScrollbarState.thumbDisplacementPercent +val ScrollbarState.thumbMovedPercent get() = unpackFloat2(packedValue) /** @@ -179,7 +179,7 @@ internal fun Orientation.valueOf(intOffset: IntOffset) = when (this) { * @param minThumbSize the minimum size of the scrollbar thumb * @param interactionSource allows for observing the state of the scroll bar * @param thumb a composable for drawing the scrollbar thumb - * @param onThumbDisplaced an function for reacting to scroll bar displacements caused by direct + * @param onThumbMoved an function for reacting to scroll bar displacements caused by direct * interactions on the scrollbar thumb by the user, for example implementing a fast scroll */ @Composable @@ -190,7 +190,7 @@ fun Scrollbar( minThumbSize: Dp = 40.dp, interactionSource: MutableInteractionSource? = null, thumb: @Composable () -> Unit, - onThumbDisplaced: ((Float) -> Unit)? = null, + onThumbMoved: ((Float) -> Unit)? = null, ) { val localDensity = LocalDensity.current @@ -206,7 +206,7 @@ fun Scrollbar( var track by remember { mutableStateOf(ScrollbarTrack(packedValue = 0)) } val thumbTravelPercent = when { - interactionThumbTravelPercent.isNaN() -> state.thumbDisplacementPercent + interactionThumbTravelPercent.isNaN() -> state.thumbMovedPercent else -> interactionThumbTravelPercent } val thumbSizePx = max( @@ -217,7 +217,7 @@ fun Scrollbar( targetValue = with(localDensity) { thumbSizePx.toDp() }, label = "scrollbar thumb size", ) - val thumbDisplacementPx = min( + val thumbMovedPx = min( a = track.size * thumbTravelPercent, b = track.size - thumbSizePx, ) @@ -282,8 +282,8 @@ fun Scrollbar( }, ), ) { - val scrollbarThumbDisplacement = max( - a = with(localDensity) { thumbDisplacementPx.toDp() }, + val scrollbarThumbMovedDp = max( + a = with(localDensity) { thumbMovedPx.toDp() }, b = 0.dp, ) // scrollbar thumb container @@ -299,10 +299,10 @@ fun Scrollbar( .offset( y = when (orientation) { Orientation.Horizontal -> 0.dp - Orientation.Vertical -> scrollbarThumbDisplacement + Orientation.Vertical -> scrollbarThumbMovedDp }, x = when (orientation) { - Orientation.Horizontal -> scrollbarThumbDisplacement + Orientation.Horizontal -> scrollbarThumbMovedDp Orientation.Vertical -> 0.dp }, ), @@ -311,7 +311,7 @@ fun Scrollbar( } } - if (onThumbDisplaced == null) return + if (onThumbMoved == null) return // State that will be read inside the effects that follow // but will not cause re-triggering of them @@ -325,26 +325,26 @@ fun Scrollbar( return@LaunchedEffect } - var currentThumbDisplacement = updatedState.thumbDisplacementPercent - val destinationThumbDisplacement = track.thumbPosition( + var currentThumbMovedPercent = updatedState.thumbMovedPercent + val destinationThumbMovedPercent = track.thumbPosition( dimension = orientation.valueOf(pressedOffset), ) - val isPositive = currentThumbDisplacement < destinationThumbDisplacement + val isPositive = currentThumbMovedPercent < destinationThumbMovedPercent val delta = SCROLLBAR_PRESS_DELTA_PCT * if (isPositive) 1f else -1f - while (currentThumbDisplacement != destinationThumbDisplacement) { - currentThumbDisplacement = when { + while (currentThumbMovedPercent != destinationThumbMovedPercent) { + currentThumbMovedPercent = when { isPositive -> min( - a = currentThumbDisplacement + delta, - b = destinationThumbDisplacement, + a = currentThumbMovedPercent + delta, + b = destinationThumbMovedPercent, ) else -> max( - a = currentThumbDisplacement + delta, - b = destinationThumbDisplacement, + a = currentThumbMovedPercent + delta, + b = destinationThumbMovedPercent, ) } - onThumbDisplaced(currentThumbDisplacement) - interactionThumbTravelPercent = currentThumbDisplacement + onThumbMoved(currentThumbMovedPercent) + interactionThumbTravelPercent = currentThumbMovedPercent delay(SCROLLBAR_PRESS_DELAY_MS) } } @@ -358,7 +358,7 @@ fun Scrollbar( val currentTravel = track.thumbPosition( dimension = orientation.valueOf(draggedOffset), ) - onThumbDisplaced(currentTravel) + onThumbMoved(currentTravel) interactionThumbTravelPercent = currentTravel } } diff --git a/core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/component/scrollbar/ThumbExt.kt b/core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/component/scrollbar/ThumbExt.kt index 4ed966da4..4d187e269 100644 --- a/core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/component/scrollbar/ThumbExt.kt +++ b/core/designsystem/src/main/java/com/google/samples/apps/nowinandroid/core/designsystem/component/scrollbar/ThumbExt.kt @@ -31,9 +31,9 @@ import androidx.compose.runtime.setValue * @param itemsAvailable the amount of items in the list. */ @Composable -fun LazyListState.rememberFastScroller( +fun LazyListState.rememberDraggableScroller( itemsAvailable: Int, -): (Float) -> Unit = rememberFastScroller( +): (Float) -> Unit = rememberDraggableScroller( itemsAvailable = itemsAvailable, scroll = ::scrollToItem, ) @@ -43,9 +43,9 @@ fun LazyListState.rememberFastScroller( * @param itemsAvailable the amount of items in the grid. */ @Composable -fun LazyGridState.rememberFastScroller( +fun LazyGridState.rememberDraggableScroller( itemsAvailable: Int, -): (Float) -> Unit = rememberFastScroller( +): (Float) -> Unit = rememberDraggableScroller( itemsAvailable = itemsAvailable, scroll = ::scrollToItem, ) @@ -56,7 +56,7 @@ fun LazyGridState.rememberFastScroller( * @param scroll a function to be invoked when an index has been identified to scroll to. */ @Composable -private inline fun rememberFastScroller( +private inline fun rememberDraggableScroller( itemsAvailable: Int, crossinline scroll: suspend (index: Int) -> Unit, ): (Float) -> Unit { diff --git a/feature/bookmarks/src/main/java/com/google/samples/apps/nowinandroid/feature/bookmarks/BookmarksScreen.kt b/feature/bookmarks/src/main/java/com/google/samples/apps/nowinandroid/feature/bookmarks/BookmarksScreen.kt index d4363f12c..e46ada015 100644 --- a/feature/bookmarks/src/main/java/com/google/samples/apps/nowinandroid/feature/bookmarks/BookmarksScreen.kt +++ b/feature/bookmarks/src/main/java/com/google/samples/apps/nowinandroid/feature/bookmarks/BookmarksScreen.kt @@ -63,7 +63,7 @@ import androidx.lifecycle.LifecycleEventObserver import androidx.lifecycle.compose.collectAsStateWithLifecycle import com.google.samples.apps.nowinandroid.core.designsystem.component.NiaLoadingWheel import com.google.samples.apps.nowinandroid.core.designsystem.component.scrollbar.DraggableScrollbar -import com.google.samples.apps.nowinandroid.core.designsystem.component.scrollbar.rememberFastScroller +import com.google.samples.apps.nowinandroid.core.designsystem.component.scrollbar.rememberDraggableScroller import com.google.samples.apps.nowinandroid.core.designsystem.component.scrollbar.scrollbarState import com.google.samples.apps.nowinandroid.core.designsystem.theme.LocalTintTheme import com.google.samples.apps.nowinandroid.core.designsystem.theme.NiaTheme @@ -216,7 +216,7 @@ private fun BookmarksGrid( .align(Alignment.CenterEnd), state = scrollbarState, orientation = Orientation.Vertical, - onThumbDisplaced = scrollableState.rememberFastScroller( + onThumbMoved = scrollableState.rememberDraggableScroller( itemsAvailable = itemsAvailable, ), ) diff --git a/feature/foryou/src/main/java/com/google/samples/apps/nowinandroid/feature/foryou/ForYouScreen.kt b/feature/foryou/src/main/java/com/google/samples/apps/nowinandroid/feature/foryou/ForYouScreen.kt index dbcfe7eeb..f536c3385 100644 --- a/feature/foryou/src/main/java/com/google/samples/apps/nowinandroid/feature/foryou/ForYouScreen.kt +++ b/feature/foryou/src/main/java/com/google/samples/apps/nowinandroid/feature/foryou/ForYouScreen.kt @@ -93,7 +93,7 @@ import com.google.samples.apps.nowinandroid.core.designsystem.component.NiaIconT import com.google.samples.apps.nowinandroid.core.designsystem.component.NiaOverlayLoadingWheel import com.google.samples.apps.nowinandroid.core.designsystem.component.scrollbar.DecorativeScrollbar import com.google.samples.apps.nowinandroid.core.designsystem.component.scrollbar.DraggableScrollbar -import com.google.samples.apps.nowinandroid.core.designsystem.component.scrollbar.rememberFastScroller +import com.google.samples.apps.nowinandroid.core.designsystem.component.scrollbar.rememberDraggableScroller import com.google.samples.apps.nowinandroid.core.designsystem.component.scrollbar.scrollbarState import com.google.samples.apps.nowinandroid.core.designsystem.icon.NiaIcons import com.google.samples.apps.nowinandroid.core.designsystem.theme.NiaTheme @@ -238,7 +238,7 @@ internal fun ForYouScreen( .align(Alignment.CenterEnd), state = scrollbarState, orientation = Orientation.Vertical, - onThumbDisplaced = state.rememberFastScroller( + onThumbMoved = state.rememberDraggableScroller( itemsAvailable = itemsAvailable, ), ) diff --git a/feature/interests/src/main/java/com/google/samples/apps/nowinandroid/feature/interests/TabContent.kt b/feature/interests/src/main/java/com/google/samples/apps/nowinandroid/feature/interests/TabContent.kt index 7ae652344..d865f5e1a 100644 --- a/feature/interests/src/main/java/com/google/samples/apps/nowinandroid/feature/interests/TabContent.kt +++ b/feature/interests/src/main/java/com/google/samples/apps/nowinandroid/feature/interests/TabContent.kt @@ -36,7 +36,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.platform.testTag import androidx.compose.ui.unit.dp import com.google.samples.apps.nowinandroid.core.designsystem.component.scrollbar.DraggableScrollbar -import com.google.samples.apps.nowinandroid.core.designsystem.component.scrollbar.rememberFastScroller +import com.google.samples.apps.nowinandroid.core.designsystem.component.scrollbar.rememberDraggableScroller import com.google.samples.apps.nowinandroid.core.designsystem.component.scrollbar.scrollbarState import com.google.samples.apps.nowinandroid.core.model.data.FollowableTopic @@ -91,7 +91,7 @@ fun TopicsTabContent( .align(Alignment.CenterEnd), state = scrollbarState, orientation = Orientation.Vertical, - onThumbDisplaced = scrollableState.rememberFastScroller( + onThumbMoved = scrollableState.rememberDraggableScroller( itemsAvailable = topics.size, ), ) diff --git a/feature/search/src/main/java/com/google/samples/apps/nowinandroid/feature/search/SearchScreen.kt b/feature/search/src/main/java/com/google/samples/apps/nowinandroid/feature/search/SearchScreen.kt index 08356d938..fede7766b 100644 --- a/feature/search/src/main/java/com/google/samples/apps/nowinandroid/feature/search/SearchScreen.kt +++ b/feature/search/src/main/java/com/google/samples/apps/nowinandroid/feature/search/SearchScreen.kt @@ -81,7 +81,7 @@ import androidx.compose.ui.unit.dp import androidx.hilt.navigation.compose.hiltViewModel import androidx.lifecycle.compose.collectAsStateWithLifecycle import com.google.samples.apps.nowinandroid.core.designsystem.component.scrollbar.DraggableScrollbar -import com.google.samples.apps.nowinandroid.core.designsystem.component.scrollbar.rememberFastScroller +import com.google.samples.apps.nowinandroid.core.designsystem.component.scrollbar.rememberDraggableScroller import com.google.samples.apps.nowinandroid.core.designsystem.component.scrollbar.scrollbarState import com.google.samples.apps.nowinandroid.core.designsystem.icon.NiaIcons import com.google.samples.apps.nowinandroid.core.designsystem.theme.NiaTheme @@ -389,7 +389,7 @@ private fun SearchResultBody( .align(Alignment.CenterEnd), state = scrollbarState, orientation = Orientation.Vertical, - onThumbDisplaced = state.rememberFastScroller( + onThumbMoved = state.rememberDraggableScroller( itemsAvailable = itemsAvailable, ), ) diff --git a/feature/topic/src/main/java/com/google/samples/apps/nowinandroid/feature/topic/TopicScreen.kt b/feature/topic/src/main/java/com/google/samples/apps/nowinandroid/feature/topic/TopicScreen.kt index 84975b4ea..075e7f881 100644 --- a/feature/topic/src/main/java/com/google/samples/apps/nowinandroid/feature/topic/TopicScreen.kt +++ b/feature/topic/src/main/java/com/google/samples/apps/nowinandroid/feature/topic/TopicScreen.kt @@ -55,7 +55,7 @@ import com.google.samples.apps.nowinandroid.core.designsystem.component.NiaBackg import com.google.samples.apps.nowinandroid.core.designsystem.component.NiaFilterChip import com.google.samples.apps.nowinandroid.core.designsystem.component.NiaLoadingWheel import com.google.samples.apps.nowinandroid.core.designsystem.component.scrollbar.DraggableScrollbar -import com.google.samples.apps.nowinandroid.core.designsystem.component.scrollbar.rememberFastScroller +import com.google.samples.apps.nowinandroid.core.designsystem.component.scrollbar.rememberDraggableScroller import com.google.samples.apps.nowinandroid.core.designsystem.component.scrollbar.scrollbarState import com.google.samples.apps.nowinandroid.core.designsystem.icon.NiaIcons import com.google.samples.apps.nowinandroid.core.designsystem.theme.NiaTheme @@ -159,7 +159,7 @@ internal fun TopicScreen( .align(Alignment.CenterEnd), state = scrollbarState, orientation = Orientation.Vertical, - onThumbDisplaced = state.rememberFastScroller( + onThumbMoved = state.rememberDraggableScroller( itemsAvailable = itemsAvailable, ), )