Vector animation is broken with newer libraries
coinzdude opened this issue · 5 comments
EDIT - I have found the issue is not specifically drawablepainter:0.33.2, as also 0.33.1-alpha works as well, but the issue is a combination of either 0.34.0 or using any compose library 1.6.0 vs 1.5.4.
More details below
Animations using vectors do not animate with com.google.accompanist:accompanist-drawablepainter:0.33.2-alpha newer libraries
This works well in 0.32.0, 0.29.1-alpha
@Composable
fun GarageIndicatorClosing() {
val backgroundVector =
ImageVector.vectorResource(id = R.drawable.garage_door_open)
val garageBackgroundPainter = rememberVectorPainter(image = backgroundVector)
var yState by remember { mutableIntStateOf(0) }
val yOffset = animateIntAsState(
targetValue = yState,
animationSpec =
infiniteRepeatable(animation = tween(durationMillis = 1200, easing = LinearEasing))
)
Box {
Image(painter = garageBackgroundPainter, contentDescription = null)
MoveGarageArrow(yOffset = yOffset.value) {
GarageArrow(arrowID = R.drawable.garage_door_closing_arrow_anim)
}
}
yState = 150
}
@Composable
fun GarageArrow(arrowID: Int) {
Image(
painter = painterResource(id = arrowID),
contentDescription = null,
contentScale = ContentScale.Crop
)
}
@Composable
fun MoveGarageArrow(
yOffset: Int,
item: @Composable () -> Unit
) {
// outer box
Box {
// inner box
Box(
Modifier
.absoluteOffset(y = yOffset.dp)
.align(Alignment.Center)
) {
item()
}
}
}
example vector
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="200dp"
android:height="60dp"
android:viewportWidth="150"
android:viewportHeight="45">
<path
android:pathData="M30.05,3.13 L75.8,41.88 121.55,3.13h-16L76.05,27.63 45.55,3.13Z"
android:strokeLineJoin="miter"
android:strokeWidth="1"
android:fillColor="#00ff00"
android:strokeColor="#ffffff"
android:strokeLineCap="butt"/>
</vector>
Some more detail. This is the most recent set of libraries I can use and still have working vector animation.
Using any 1.6.0 compose library or drawablepainter 33.2 or higher breaks animation
dependencies {
implementation "androidx.activity:activity-compose:1.8.2"
implementation "androidx.car.app:app:1.2.0"
implementation "androidx.compose.animation:animation-graphics:1.5.4" // any 1.6.0 breaks as well
implementation "androidx.compose.foundation:foundation:1.5.4"
implementation "androidx.compose.ui:ui-tooling-preview:1.5.4"
implementation "androidx.compose.material3:material3:1.1.2"
implementation "androidx.constraintlayout:constraintlayout:2.1.4"
implementation "androidx.core:core-ktx:1.12.0"
implementation "androidx.preference:preference-ktx:1.2.1"
implementation "androidx.work:work-runtime-ktx:2.9.0"
implementation "com.android.volley:volley:1.2.1"
implementation 'com.google.accompanist:accompanist-drawablepainter:0.33.1-alpha' //33.2 breaks
implementation "com.google.android.gms:play-services-location:21.1.0"
api 'com.google.android.material:material:1.11.0'
implementation 'com.google.code.gson:gson:2.10.1'
apply plugin: 'com.google.gms.google-services'
debugImplementation 'androidx.compose.ui:ui-tooling:1.5.4'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
}
I have published a minimal project which illustrates the issue here
Sorry I missed this one. I can't actually spot where you are using DrawablePainter in that code snippet you provided? This might actually be a bug in the Compose itself.
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.
Thank you, I should have closed this. The newer libraries appear to have resolved the issue.