Skip to content

Commit 556ae04

Browse files
committed
Resolved the wrong translation colors order in RTL swipe directions,
Added a method swipeDirection.isRTL
1 parent 525179f commit 556ae04

File tree

2 files changed

+20
-17
lines changed

2 files changed

+20
-17
lines changed

fragula-common/src/main/kotlin/com/fragula2/common/SwipeDirection.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ enum class SwipeDirection(val value: Int) {
2424

2525
fun isHorizontal(): Boolean = (this == LEFT_TO_RIGHT || this == RIGHT_TO_LEFT)
2626

27+
fun isRTL(): Boolean = (this == RIGHT_TO_LEFT || this == BOTTOM_TO_TOP)
28+
2729
companion object {
2830

2931
fun of(value: Int): SwipeDirection {

fragula-compose/src/main/kotlin/com/fragula2/compose/FragulaNavHost.kt

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -212,11 +212,10 @@ private fun SwipeableBox(
212212
constraints.maxHeight.toFloat()
213213
}
214214
val parallaxFormula = {
215-
when (swipeDirection) {
216-
SwipeDirection.LEFT_TO_RIGHT -> -maxWidth.value * (1.0f - offsetProvider()) / parallaxFactor
217-
SwipeDirection.RIGHT_TO_LEFT -> maxWidth.value * (1.0f - offsetProvider()) / parallaxFactor
218-
SwipeDirection.TOP_TO_BOTTOM -> -maxHeight.value * (1.0f - offsetProvider()) / parallaxFactor
219-
SwipeDirection.BOTTOM_TO_TOP -> maxHeight.value * (1.0f - offsetProvider()) / parallaxFactor
215+
if (swipeDirection.isRTL()) {
216+
maxHeight.value * (1.0f - offsetProvider()) / parallaxFactor
217+
} else {
218+
-maxWidth.value * (1.0f - offsetProvider()) / parallaxFactor
220219
}
221220
}
222221

@@ -315,11 +314,10 @@ private fun SwipeableBox(
315314
},
316315
)
317316
.graphicsLayer {
318-
val translation = when (swipeDirection) {
319-
SwipeDirection.LEFT_TO_RIGHT -> scrollPosition
320-
SwipeDirection.RIGHT_TO_LEFT -> -scrollPosition
321-
SwipeDirection.TOP_TO_BOTTOM -> scrollPosition
322-
SwipeDirection.BOTTOM_TO_TOP -> -scrollPosition
317+
val translation = if (swipeDirection.isRTL()) {
318+
-scrollPosition
319+
} else {
320+
scrollPosition
323321
}
324322
if (swipeDirection.isHorizontal()) {
325323
translationX = if (applyParallax) parallaxFormula() else translation
@@ -386,11 +384,10 @@ private fun PageElevation(
386384
},
387385
)
388386
.graphicsLayer {
389-
val translation = when (swipeDirection) {
390-
SwipeDirection.LEFT_TO_RIGHT -> positionProvider()
391-
SwipeDirection.RIGHT_TO_LEFT -> pageEnd - positionProvider()
392-
SwipeDirection.TOP_TO_BOTTOM -> positionProvider()
393-
SwipeDirection.BOTTOM_TO_TOP -> pageEnd - positionProvider()
387+
val translation = if (swipeDirection.isRTL()) {
388+
pageEnd - positionProvider()
389+
} else {
390+
positionProvider()
394391
}
395392
if (swipeDirection.isHorizontal()) {
396393
translationX = translation - elevationAmount.toPx()
@@ -399,8 +396,12 @@ private fun PageElevation(
399396
}
400397
},
401398
) {
402-
val colors = listOf(ElevationEnd, ElevationStart)
403-
val brush = if(swipeDirection.isHorizontal()) Brush.horizontalGradient(
399+
val colors = if (swipeDirection.isRTL()) {
400+
listOf(ElevationEnd, ElevationStart)
401+
} else {
402+
listOf(ElevationStart, ElevationEnd)
403+
}
404+
val brush = if (swipeDirection.isHorizontal()) Brush.horizontalGradient(
404405
colors = colors,
405406
) else Brush.verticalGradient(
406407
colors = colors,

0 commit comments

Comments
 (0)