Skip to content

Commit

Permalink
Merge pull request #902 from Tomoyuki-TAKEZAKI/795-rename-safescroll
Browse files Browse the repository at this point in the history
[Improvement] rename scroll
  • Loading branch information
takahirom authored Oct 12, 2022
2 parents 929b193 + 377076f commit b91cf59
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ private class HoursScreen(
position: Offset,
) {
val nextPossibleY = calculatePossibleScrollY(dragAmount.y)
scrollState.safeScroll(
scrollState.scroll(
scrollX = scrollState.scrollX,
scrollY = nextPossibleY,
timeMillis = timeMillis,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ private class RoomScreen(
position: Offset,
) {
val nextPossibleX = calculatePossibleScrollX(dragAmount.x)
scrollState.safeScroll(
scrollState.scroll(
scrollX = nextPossibleX,
scrollY = scrollState.scrollY,
timeMillis = timeMillis,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ fun Timetable(
scrollBy(
action = { x: Float, y: Float ->
coroutineScope.launch {
scrollState.safeScroll(
scrollState.scroll(
scrollX = x,
scrollY = y,
timeMillis = 0,
Expand Down Expand Up @@ -403,32 +403,22 @@ class ScreenScrollState(
val maxY: Float
get() = _scrollY.lowerBound ?: 0f

private suspend fun scroll(
amount: Offset,
timeMillis: Long,
position: Offset,
) = coroutineScope {
velocityTracker.addPosition(timeMillis = timeMillis, position = position)
launch {
_scrollX.snapTo(amount.x)
}
launch {
_scrollY.snapTo(amount.y)
}
}

suspend fun safeScroll(
suspend fun scroll(
scrollX: Float,
scrollY: Float,
timeMillis: Long,
position: Offset,
) {
if (scrollX.isNaN().not() && scrollY.isNaN().not()) {
scroll(
amount = Offset(scrollX, scrollY),
timeMillis = timeMillis,
position = position,
)
coroutineScope {
velocityTracker.addPosition(timeMillis = timeMillis, position = position)
launch {
_scrollX.snapTo(scrollX)
}
launch {
_scrollY.snapTo(scrollY)
}
}
}
}

Expand Down Expand Up @@ -610,7 +600,7 @@ private class TimetableScreen(
) {
val nextPossibleX = calculatePossibleScrollX(dragAmount.x)
val nextPossibleY = calculatePossibleScrollY(dragAmount.y)
scrollState.safeScroll(
scrollState.scroll(
scrollX = nextPossibleX,
scrollY = nextPossibleY,
timeMillis = timeMillis,
Expand Down

0 comments on commit b91cf59

Please sign in to comment.