Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ private fun OnboardingScreen(onStartButtonClick: () -> Unit) {
HorizontalPager(
state = pagerState,
userScrollEnabled = false,
modifier = Modifier.weight(1f)
modifier = Modifier.weight(1f),
beyondViewportPageCount = 1
Comment on lines 94 to +98
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

이거 백그라운드에서 미리 돌고있을 가능성은 없나요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

val isCurrentPage = pageIndex == currentPage

onboardingPages.getOrNull(pageIndex)?.let { data ->
    PageContent(
        titleRes = data.titleRes,
        pageContentType = data.contentType,
        isPageActive = isCurrentPage
    )
}

StopAtProgressLottie(
    lottieRes = pageContentType.lottieRes,
    shouldPlay = isPageActive,
     modifier = Modifier
                .fillMaxWidth()
                .aspectRatio(375f / 433f),
)

네, isPageActive를 StopAtProgressLottie의 shouldPlay 인자로 넘겨주고 있어서, 백그라운드 페이지가 미리 로드되더라도 사용자에게 보이면 재생됩니다.

(추가)
아래의 코드로 확인해보니 현재 페이지의 lottie만 재생되는 것도 확인했습니다!

LaunchedEffect(progress) {
    if (shouldPlay && progress > 0f && progress < STOP_PROGRESS) {
        android.util.Log.v("로티 체크", "$lottieRes 재생 중... 진행도: $progress")
    }
}

) { pageIndex ->

val isCurrentPage = pageIndex == currentPage
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
package com.puzzle.onboarding.ui.components

import androidx.annotation.RawRes
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.ContentScale
import com.airbnb.lottie.compose.LottieAnimation
import com.airbnb.lottie.compose.LottieClipSpec
import com.airbnb.lottie.compose.LottieCompositionSpec
import com.airbnb.lottie.compose.animateLottieCompositionAsState
import com.airbnb.lottie.compose.rememberLottieComposition
Expand All @@ -27,37 +25,24 @@ internal fun StopAtProgressLottie(
) {
val composition by rememberLottieComposition(LottieCompositionSpec.RawRes(lottieRes))

val animProgressState by animateLottieCompositionAsState(
val progress by animateLottieCompositionAsState(
composition = composition,
iterations = 1,
isPlaying = shouldPlay,
restartOnPlay = true
restartOnPlay = false,
clipSpec = LottieClipSpec.Progress(0f, STOP_PROGRESS)
)

var isStopped by remember { mutableStateOf(false) }

val hasReachedTarget by remember {
derivedStateOf { animProgressState >= STOP_PROGRESS }
}

LaunchedEffect(shouldPlay, hasReachedTarget) {
if (shouldPlay) {
isStopped = false
}

if (hasReachedTarget && !isStopped) {
isStopped = true
Box(modifier = modifier) {
if (composition != null) {
LottieAnimation(
composition = composition,
progress = { progress },
contentScale = ContentScale.FillWidth,
modifier = Modifier.fillMaxSize()
)
}
}

val finalProgress = if (isStopped) STOP_PROGRESS else animProgressState

LottieAnimation(
composition = composition,
progress = { finalProgress },
contentScale = ContentScale.FillWidth,
modifier = modifier
)
}

private const val STOP_PROGRESS = 0.99f