Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong size of animation in Compose HorizontalPager #48

Open
valery-mat opened this issue Jan 17, 2025 · 0 comments
Open

Wrong size of animation in Compose HorizontalPager #48

valery-mat opened this issue Jan 17, 2025 · 0 comments

Comments

@valery-mat
Copy link

lottie_issue_json_size.mp4

Hi team! Recently I've noticed the issue in your library of versions 0.6.1 and 0.6.2.
The problem is in the wrong size of animation, when it's running in the compose HorizontalPager (for example, from compose bom 2024.12.01). On the video I've attached it's clearly visible that the size of animation sometimes gets smaller than the other ones. But they all should be of the same size. In the example app, I've attached the exact same json lottie animation (simply with different names) four times in HorizontalPager.
Device is Pixel 7A, Android API 35.

composeBom = "2024.12.01"
dotLottie = "0.6.1"

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.pager.HorizontalPager
import androidx.compose.foundation.pager.rememberPagerState
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.Scaffold
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import com.lottiefiles.dotlottie.core.compose.ui.DotLottieAnimation
import com.lottiefiles.dotlottie.core.util.DotLottieSource
import com.sms.myapplication.ui.theme.MyApplicationTheme

class MainActivity : ComponentActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContent {
            MyApplicationTheme {
                Scaffold(modifier = Modifier.fillMaxSize()) { paddings ->
                    Box(modifier = Modifier
                        .padding(paddings)
                        .fillMaxSize()) {
                        TutorialScreen(
                            listOf(
                                "free_animation.json",
                                "free_animation_0.json",
                                "free_animation_1.json",
                                "free_animation_2.json"
                            )
                        )
                    }
                }
            }
        }
    }
}

@Composable
fun TutorialScreen(
    tutorialSteps: List<String>,
) {
    val pagerState = rememberPagerState(pageCount = { tutorialSteps.size })
    val tutorials = remember { tutorialSteps }

    HorizontalPager(
        state = pagerState,
        verticalAlignment = Alignment.Top,
        modifier = Modifier
            .fillMaxSize()
            .background(Color.Cyan),
        key = { page -> page }
    ) { page ->
        Column(
            modifier = Modifier
                .verticalScroll(rememberScrollState())
                .padding(horizontal = 38.dp)
                .fillMaxWidth(),
            horizontalAlignment = Alignment.CenterHorizontally,
        ) {
            Spacer(modifier = Modifier.height(36.dp))

            Box(modifier = Modifier.background(Color.Green)) {
                DotLottieAnimation(
                    source = DotLottieSource.Asset(tutorials[page]),
                    autoplay = true,
                    loop = true,
                    modifier = Modifier.width(320.dp).height(240.dp),
                )
            }
        }
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant