Replace usages of 'displacement' to 'moved' in parameter names

Change-Id: I5b3da60041b046454e848d187f6dd2bfadf22b9a
pull/722/head
TJ Dahunsi 1 year ago
parent 806726a7f0
commit e13e84c155

@ -61,14 +61,14 @@ private const val SCROLLBAR_INACTIVE_TO_DORMANT_TIME_IN_MS = 2_000L
* @param modifier a [Modifier] for the [Scrollbar] * @param modifier a [Modifier] for the [Scrollbar]
* @param state the driving state for the [Scrollbar] * @param state the driving state for the [Scrollbar]
* @param orientation the orientation of the scrollbar * @param orientation the orientation of the scrollbar
* @param onThumbDisplaced the fast scroll implementation * @param onThumbMoved the fast scroll implementation
*/ */
@Composable @Composable
fun ScrollableState.DraggableScrollbar( fun ScrollableState.DraggableScrollbar(
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
state: ScrollbarState, state: ScrollbarState,
orientation: Orientation, orientation: Orientation,
onThumbDisplaced: (Float) -> Unit, onThumbMoved: (Float) -> Unit,
) { ) {
val interactionSource = remember { MutableInteractionSource() } val interactionSource = remember { MutableInteractionSource() }
Scrollbar( Scrollbar(
@ -82,7 +82,7 @@ fun ScrollableState.DraggableScrollbar(
orientation = orientation, orientation = orientation,
) )
}, },
onThumbDisplaced = onThumbDisplaced, onThumbMoved = onThumbMoved,
) )
} }

@ -78,7 +78,7 @@ internal inline fun <LazyState : ScrollableState, LazyStateItem> LazyState.scrol
) )
ScrollbarState( ScrollbarState(
thumbSizePercent = thumbSizePercent, thumbSizePercent = thumbSizePercent,
thumbDisplacementPercent = when { thumbMovedPercent = when {
reverseLayout() -> 1f - thumbTravelPercent reverseLayout() -> 1f - thumbTravelPercent
else -> thumbTravelPercent else -> thumbTravelPercent
}, },

@ -80,7 +80,7 @@ value class ScrollbarState internal constructor(
companion object { companion object {
val FULL = ScrollbarState( val FULL = ScrollbarState(
thumbSizePercent = 1f, 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. * @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) * Refers to either the thumb width (for horizontal scrollbars)
* or height (for vertical 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. * track size.
*/ */
fun ScrollbarState( fun ScrollbarState(
thumbSizePercent: Float, thumbSizePercent: Float,
thumbDisplacementPercent: Float, thumbMovedPercent: Float,
) = ScrollbarState( ) = ScrollbarState(
packFloats( packFloats(
val1 = thumbSizePercent, 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 * Returns the distance the thumb has traveled as a percentage of total track size
*/ */
val ScrollbarState.thumbDisplacementPercent val ScrollbarState.thumbMovedPercent
get() = unpackFloat2(packedValue) 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 minThumbSize the minimum size of the scrollbar thumb
* @param interactionSource allows for observing the state of the scroll bar * @param interactionSource allows for observing the state of the scroll bar
* @param thumb a composable for drawing the scrollbar thumb * @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 * interactions on the scrollbar thumb by the user, for example implementing a fast scroll
*/ */
@Composable @Composable
@ -190,7 +190,7 @@ fun Scrollbar(
minThumbSize: Dp = 40.dp, minThumbSize: Dp = 40.dp,
interactionSource: MutableInteractionSource? = null, interactionSource: MutableInteractionSource? = null,
thumb: @Composable () -> Unit, thumb: @Composable () -> Unit,
onThumbDisplaced: ((Float) -> Unit)? = null, onThumbMoved: ((Float) -> Unit)? = null,
) { ) {
val localDensity = LocalDensity.current val localDensity = LocalDensity.current
@ -206,7 +206,7 @@ fun Scrollbar(
var track by remember { mutableStateOf(ScrollbarTrack(packedValue = 0)) } var track by remember { mutableStateOf(ScrollbarTrack(packedValue = 0)) }
val thumbTravelPercent = when { val thumbTravelPercent = when {
interactionThumbTravelPercent.isNaN() -> state.thumbDisplacementPercent interactionThumbTravelPercent.isNaN() -> state.thumbMovedPercent
else -> interactionThumbTravelPercent else -> interactionThumbTravelPercent
} }
val thumbSizePx = max( val thumbSizePx = max(
@ -217,7 +217,7 @@ fun Scrollbar(
targetValue = with(localDensity) { thumbSizePx.toDp() }, targetValue = with(localDensity) { thumbSizePx.toDp() },
label = "scrollbar thumb size", label = "scrollbar thumb size",
) )
val thumbDisplacementPx = min( val thumbMovedPx = min(
a = track.size * thumbTravelPercent, a = track.size * thumbTravelPercent,
b = track.size - thumbSizePx, b = track.size - thumbSizePx,
) )
@ -282,8 +282,8 @@ fun Scrollbar(
}, },
), ),
) { ) {
val scrollbarThumbDisplacement = max( val scrollbarThumbMovedDp = max(
a = with(localDensity) { thumbDisplacementPx.toDp() }, a = with(localDensity) { thumbMovedPx.toDp() },
b = 0.dp, b = 0.dp,
) )
// scrollbar thumb container // scrollbar thumb container
@ -299,10 +299,10 @@ fun Scrollbar(
.offset( .offset(
y = when (orientation) { y = when (orientation) {
Orientation.Horizontal -> 0.dp Orientation.Horizontal -> 0.dp
Orientation.Vertical -> scrollbarThumbDisplacement Orientation.Vertical -> scrollbarThumbMovedDp
}, },
x = when (orientation) { x = when (orientation) {
Orientation.Horizontal -> scrollbarThumbDisplacement Orientation.Horizontal -> scrollbarThumbMovedDp
Orientation.Vertical -> 0.dp 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 // State that will be read inside the effects that follow
// but will not cause re-triggering of them // but will not cause re-triggering of them
@ -325,26 +325,26 @@ fun Scrollbar(
return@LaunchedEffect return@LaunchedEffect
} }
var currentThumbDisplacement = updatedState.thumbDisplacementPercent var currentThumbMovedPercent = updatedState.thumbMovedPercent
val destinationThumbDisplacement = track.thumbPosition( val destinationThumbMovedPercent = track.thumbPosition(
dimension = orientation.valueOf(pressedOffset), dimension = orientation.valueOf(pressedOffset),
) )
val isPositive = currentThumbDisplacement < destinationThumbDisplacement val isPositive = currentThumbMovedPercent < destinationThumbMovedPercent
val delta = SCROLLBAR_PRESS_DELTA_PCT * if (isPositive) 1f else -1f val delta = SCROLLBAR_PRESS_DELTA_PCT * if (isPositive) 1f else -1f
while (currentThumbDisplacement != destinationThumbDisplacement) { while (currentThumbMovedPercent != destinationThumbMovedPercent) {
currentThumbDisplacement = when { currentThumbMovedPercent = when {
isPositive -> min( isPositive -> min(
a = currentThumbDisplacement + delta, a = currentThumbMovedPercent + delta,
b = destinationThumbDisplacement, b = destinationThumbMovedPercent,
) )
else -> max( else -> max(
a = currentThumbDisplacement + delta, a = currentThumbMovedPercent + delta,
b = destinationThumbDisplacement, b = destinationThumbMovedPercent,
) )
} }
onThumbDisplaced(currentThumbDisplacement) onThumbMoved(currentThumbMovedPercent)
interactionThumbTravelPercent = currentThumbDisplacement interactionThumbTravelPercent = currentThumbMovedPercent
delay(SCROLLBAR_PRESS_DELAY_MS) delay(SCROLLBAR_PRESS_DELAY_MS)
} }
} }
@ -358,7 +358,7 @@ fun Scrollbar(
val currentTravel = track.thumbPosition( val currentTravel = track.thumbPosition(
dimension = orientation.valueOf(draggedOffset), dimension = orientation.valueOf(draggedOffset),
) )
onThumbDisplaced(currentTravel) onThumbMoved(currentTravel)
interactionThumbTravelPercent = currentTravel interactionThumbTravelPercent = currentTravel
} }
} }

@ -31,9 +31,9 @@ import androidx.compose.runtime.setValue
* @param itemsAvailable the amount of items in the list. * @param itemsAvailable the amount of items in the list.
*/ */
@Composable @Composable
fun LazyListState.rememberFastScroller( fun LazyListState.rememberDraggableScroller(
itemsAvailable: Int, itemsAvailable: Int,
): (Float) -> Unit = rememberFastScroller( ): (Float) -> Unit = rememberDraggableScroller(
itemsAvailable = itemsAvailable, itemsAvailable = itemsAvailable,
scroll = ::scrollToItem, scroll = ::scrollToItem,
) )
@ -43,9 +43,9 @@ fun LazyListState.rememberFastScroller(
* @param itemsAvailable the amount of items in the grid. * @param itemsAvailable the amount of items in the grid.
*/ */
@Composable @Composable
fun LazyGridState.rememberFastScroller( fun LazyGridState.rememberDraggableScroller(
itemsAvailable: Int, itemsAvailable: Int,
): (Float) -> Unit = rememberFastScroller( ): (Float) -> Unit = rememberDraggableScroller(
itemsAvailable = itemsAvailable, itemsAvailable = itemsAvailable,
scroll = ::scrollToItem, 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. * @param scroll a function to be invoked when an index has been identified to scroll to.
*/ */
@Composable @Composable
private inline fun rememberFastScroller( private inline fun rememberDraggableScroller(
itemsAvailable: Int, itemsAvailable: Int,
crossinline scroll: suspend (index: Int) -> Unit, crossinline scroll: suspend (index: Int) -> Unit,
): (Float) -> Unit { ): (Float) -> Unit {

@ -63,7 +63,7 @@ import androidx.lifecycle.LifecycleEventObserver
import androidx.lifecycle.compose.collectAsStateWithLifecycle import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.google.samples.apps.nowinandroid.core.designsystem.component.NiaLoadingWheel 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.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.component.scrollbar.scrollbarState
import com.google.samples.apps.nowinandroid.core.designsystem.theme.LocalTintTheme import com.google.samples.apps.nowinandroid.core.designsystem.theme.LocalTintTheme
import com.google.samples.apps.nowinandroid.core.designsystem.theme.NiaTheme import com.google.samples.apps.nowinandroid.core.designsystem.theme.NiaTheme
@ -216,7 +216,7 @@ private fun BookmarksGrid(
.align(Alignment.CenterEnd), .align(Alignment.CenterEnd),
state = scrollbarState, state = scrollbarState,
orientation = Orientation.Vertical, orientation = Orientation.Vertical,
onThumbDisplaced = scrollableState.rememberFastScroller( onThumbMoved = scrollableState.rememberDraggableScroller(
itemsAvailable = itemsAvailable, itemsAvailable = itemsAvailable,
), ),
) )

@ -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.NiaOverlayLoadingWheel
import com.google.samples.apps.nowinandroid.core.designsystem.component.scrollbar.DecorativeScrollbar 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.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.component.scrollbar.scrollbarState
import com.google.samples.apps.nowinandroid.core.designsystem.icon.NiaIcons import com.google.samples.apps.nowinandroid.core.designsystem.icon.NiaIcons
import com.google.samples.apps.nowinandroid.core.designsystem.theme.NiaTheme import com.google.samples.apps.nowinandroid.core.designsystem.theme.NiaTheme
@ -238,7 +238,7 @@ internal fun ForYouScreen(
.align(Alignment.CenterEnd), .align(Alignment.CenterEnd),
state = scrollbarState, state = scrollbarState,
orientation = Orientation.Vertical, orientation = Orientation.Vertical,
onThumbDisplaced = state.rememberFastScroller( onThumbMoved = state.rememberDraggableScroller(
itemsAvailable = itemsAvailable, itemsAvailable = itemsAvailable,
), ),
) )

@ -36,7 +36,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.testTag import androidx.compose.ui.platform.testTag
import androidx.compose.ui.unit.dp 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.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.component.scrollbar.scrollbarState
import com.google.samples.apps.nowinandroid.core.model.data.FollowableTopic import com.google.samples.apps.nowinandroid.core.model.data.FollowableTopic
@ -91,7 +91,7 @@ fun TopicsTabContent(
.align(Alignment.CenterEnd), .align(Alignment.CenterEnd),
state = scrollbarState, state = scrollbarState,
orientation = Orientation.Vertical, orientation = Orientation.Vertical,
onThumbDisplaced = scrollableState.rememberFastScroller( onThumbMoved = scrollableState.rememberDraggableScroller(
itemsAvailable = topics.size, itemsAvailable = topics.size,
), ),
) )

@ -81,7 +81,7 @@ import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle 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.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.component.scrollbar.scrollbarState
import com.google.samples.apps.nowinandroid.core.designsystem.icon.NiaIcons import com.google.samples.apps.nowinandroid.core.designsystem.icon.NiaIcons
import com.google.samples.apps.nowinandroid.core.designsystem.theme.NiaTheme import com.google.samples.apps.nowinandroid.core.designsystem.theme.NiaTheme
@ -389,7 +389,7 @@ private fun SearchResultBody(
.align(Alignment.CenterEnd), .align(Alignment.CenterEnd),
state = scrollbarState, state = scrollbarState,
orientation = Orientation.Vertical, orientation = Orientation.Vertical,
onThumbDisplaced = state.rememberFastScroller( onThumbMoved = state.rememberDraggableScroller(
itemsAvailable = itemsAvailable, itemsAvailable = itemsAvailable,
), ),
) )

@ -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.NiaFilterChip
import com.google.samples.apps.nowinandroid.core.designsystem.component.NiaLoadingWheel 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.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.component.scrollbar.scrollbarState
import com.google.samples.apps.nowinandroid.core.designsystem.icon.NiaIcons import com.google.samples.apps.nowinandroid.core.designsystem.icon.NiaIcons
import com.google.samples.apps.nowinandroid.core.designsystem.theme.NiaTheme import com.google.samples.apps.nowinandroid.core.designsystem.theme.NiaTheme
@ -159,7 +159,7 @@ internal fun TopicScreen(
.align(Alignment.CenterEnd), .align(Alignment.CenterEnd),
state = scrollbarState, state = scrollbarState,
orientation = Orientation.Vertical, orientation = Orientation.Vertical,
onThumbDisplaced = state.rememberFastScroller( onThumbMoved = state.rememberDraggableScroller(
itemsAvailable = itemsAvailable, itemsAvailable = itemsAvailable,
), ),
) )

Loading…
Cancel
Save