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 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,
)
}

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

@ -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
}
}

@ -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 {

@ -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,
),
)

@ -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,
),
)

@ -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,
),
)

@ -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,
),
)

@ -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,
),
)

Loading…
Cancel
Save