@@ -75,7 +75,7 @@ fun LyricsView(
7575 val coroutineScope = rememberCoroutineScope()
7676 val visibleItemsInfo by remember { derivedStateOf { state.layoutInfo.visibleItemsInfo } }
7777
78- val scrollOffset = dpToPx(64 )
78+ val scrollOffset = dpToPx(128 )
7979
8080 // Update the current playback position every second
8181 LaunchedEffect (mediaController, lyrics) {
@@ -107,9 +107,9 @@ fun LyricsView(
107107 coroutineScope.launch {
108108 // If the next item is visible, animate smoothly to it using FastOutSlowIn Easing
109109 // else use animateScrollToItem.
110- if (visibleItemsInfo.any { it.index == targetIndex }) {
111- val currentItem = visibleItemsInfo.firstOrNull { it.index == currentLyricIndex.intValue }
110+ val currentItem = visibleItemsInfo.firstOrNull { it.index == currentLyricIndex.intValue }
112111
112+ if (visibleItemsInfo.any { it.index == targetIndex }) {
113113 val scrollBy = (currentItem?.offset ? : 0 ) + (currentItem?.size ? : 0 ) - scrollOffset
114114
115115 state.animateScrollBy(
@@ -120,7 +120,7 @@ fun LyricsView(
120120 else
121121 state.animateScrollToItem(
122122 index = targetIndex,
123- scrollOffset = - scrollOffset
123+ scrollOffset = - (currentItem?.size ? : 0 )
124124 )
125125 }
126126 }
@@ -171,7 +171,7 @@ fun LyricsView(
171171 coroutineScope.launch {
172172 state.animateScrollToItem(
173173 index = index,
174- scrollOffset = - scrollOffset
174+ scrollOffset = - scrollOffset + (visibleItemsInfo.firstOrNull { it.index == index }?.size ? : 0 )
175175 )
176176 }
177177 }
0 commit comments