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

Flicker on animation change when dynamic layer is changing #2619

Open
atuldhanuka opened this issue Mar 13, 2025 · 0 comments
Open

Flicker on animation change when dynamic layer is changing #2619

atuldhanuka opened this issue Mar 13, 2025 · 0 comments

Comments

@atuldhanuka
Copy link

Hello Everyone,

I am adding LottieAnimationView to my layout inside ConstraintLayout. I have a one json file which is been keep in raw folder. Depending on the condition i am changing the layer index.

Like - loadData(setOf(32, 42, 44, 46, 48), binding.viewAnimation, context), loadData(setOf(0, 1, 13), binding.viewAnimation, context)

When I do this, I can see that the LottieAnimationView flickers.

`private suspend fun loadAndFilterData(
layerSet: Set,
viewAnimation: LottieAnimationView,
context: Context?
) {
withContext(Dispatchers.IO) {
try {
val inputStream: InputStream? =
context?.resources?.openRawResource(R.raw.animationjson)
val data = inputStream?.bufferedReader().use { it?.readText() }
val json = data?.let { JSONObject(it) }
// Get the layers and filter them based on the indices
val layers = json?.optJSONArray("layers") ?: JSONArray()
val newLayers = filterLayers(layers, layerSet)
// Replace the layers in the original JSON with the new filtered layers
json?.put("layers", newLayers)
// Now you would convert the modified JSON to a LottieAnimation
val animationVehicle = json.toString()
withContext(Dispatchers.Main) {
showAnimation(animationVehicle, viewAnimation)
}
} catch (e: IOException) {
DevLog.e("File Error", "Failed to read file")
} catch (e: Exception) {
DevLog.e("JSON Error", "Failed to parse or process JSON")
}
}
}

private fun showAnimation(
animationVehicle: String,
viewAnimation: LottieAnimationView
) {
viewAnimation.setAnimationFromJson(animationVehicle)
viewAnimation.speed = 1.0f
viewAnimation.playAnimation()
}`

is there a way to stop the flicker when layer is change. it should change smoothly without visible because in iOS it is happening smoothly.

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

No branches or pull requests

1 participant