Created
June 27, 2022 22:17
-
-
Save arriolac/f76041a8493b7032b63d83ff21baec42 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright 2022 Google LLC. | |
// SPDX-License-Identifier: Apache-2.0 | |
class ComposeItemRow @JvmOverloads constructor( | |
context: Context, | |
attrs: AttributeSet? = null, | |
defStyle: Int = 0 | |
) : AbstractComposeView(context, attrs, defStyle) { | |
// … | |
// State hoist animatable object so that it can be explicitly stopped | |
val animatable = Animatable(Color.Gray) | |
@Composable | |
override fun Content() { | |
key(index) { | |
ItemRow(index, animatable) | |
} | |
} | |
} | |
class MainAdapter : RecyclerView.Adapter<MainAdapter.ViewHolder>() { | |
// … | |
override fun onViewDetachedFromWindow(holder: ViewHolder) { | |
super.onViewDetachedFromWindow(holder) | |
// Stop the animation when the view gets detached | |
viewLifecycleOwner.lifecycleScope.launch { | |
holder.itemRow.animatable.stop() | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment