Skip to content

Commit 5113162

Browse files
committed
Fixed the rotation effect not working properly
1 parent 67c6aee commit 5113162

2 files changed

Lines changed: 10 additions & 8 deletions

File tree

app/src/main/java/com/better/nothing/music/vizualizer/ui/MainActivity.kt

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -486,25 +486,28 @@ internal fun BetterVizApp(
486486
userScrollEnabled = true
487487
) { page ->
488488
val tab = Tab.entries[page]
489-
val pageOffset =
490-
((pagerState.currentPage - page) + pagerState.currentPageOffsetFraction).absoluteValue
491-
489+
val pageOffset = (pagerState.currentPage - page) + pagerState.currentPageOffsetFraction
492490
Box(
493491
modifier = Modifier
494492
.fillMaxSize()
495493
.graphicsLayer {
496-
val fraction = 1f - pageOffset.coerceIn(0f, 1f)
494+
// 1. Get the absolute offset so scrolling left or right yields the same fraction amount
495+
val absOffset = pageOffset.coerceIn(-1f, 1f).let { kotlin.math.abs(it) }
496+
497+
// 2. Calculate the fraction using the absolute offset (0f to 1f)
498+
val fraction = 1f - absOffset
499+
497500
val scale = 0.8f + (1f - 0.8f) * fraction
498501
scaleX = scale
499502
scaleY = scale
500503
alpha = fraction * fraction
501504

502-
// Calculate rotation: 0 deg when fully visible, 20 deg when hidden
505+
// 3. Calculate rotation: 0 deg when fully visible, 20 deg when hidden
503506
val maxRotation = 10f
504507
val rotationAmount = maxRotation * (1f - fraction)
505508

506-
// Use the sign of pageOffset to determine +20 or -20
507-
rotationZ = if (pageOffset > 0) rotationAmount else -rotationAmount
509+
// 4. Use the original pageOffset sign to choose +20 or -20
510+
rotationZ = if (pageOffset > 0) -rotationAmount else rotationAmount
508511
}
509512
) {
510513
when (tab) {

app/src/main/java/com/better/nothing/music/vizualizer/ui/MainViewModel.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,6 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
548548
return flat?.contains(ctx.packageName) == true
549549
}
550550

551-
var lastStatsSyncMs = 0L
552551

553552
val _devPassword = MutableStateFlow<String?>(null)
554553

0 commit comments

Comments
 (0)