Repository navigation
Jetpack Compose #3362
Answered
by
islam-engineer
alinimbuzzer
asked this question in
General
|
Does PAG support jetpack compose ? We are looking to implement transparent video animation in our project, please let me know if libpag support jetpack compose |
Answered by
islam-engineer
Nov 4, 2026
Replies: 1 comment
|
Yes. libpag doesn't ship a Compose-native composable, but its Android views ( @Composable
fun PagAnimation(
assetPath: String,
modifier: Modifier = Modifier,
repeatCount: Int = 0, // 0 = loop forever
) {
val context = LocalContext.current
val pagFile = remember(assetPath) { PAGFile.Load(context.assets, assetPath) }
AndroidView(
modifier = modifier,
factory = { ctx ->
PAGView(ctx).apply {
composition = pagFile
setRepeatCount(repeatCount)
play()
}
},
update = { view ->
if (view.composition !== pagFile) {
view.composition = pagFile
view.play()
}
},
onRelease = { view ->
view.stop()
view.freeCache()
},
)
}
// Usage
PagAnimation(
assetPath = "anim/confetti.pag",
modifier = Modifier.size(240.dp),
)A few notes:
If this helps, please mark it as the answer so others can find it. 🙂 |
0 replies
Answer selected by
CodeJhF
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yes. libpag doesn't ship a Compose-native composable, but its Android views (
PAGView/PAGImageView) are regularViews, so you can embed them in Compose withAndroidView. That works fine for transparent animations.