Animated Background with Pause
Introduction & Purpose I sometimes like to add animated background to my apps to make them a little more interesting to work on, like in this very simple example above. Unfortunately, the animation is not free. It takes up CPU time, can waste battery, and also heat up physical devices. We definitely want to avoid that. It's also great to have a way to stop animations for people who are sensitive to motion. We could just remove the animated background, but this makes things a little boring if I want to show someone what I have been working on. We can fix this! I'll keep this post quick. Full code listing linked at the end. Animated Background Let's start with a basic animated background. This is our gradient and this will be reused with our final example. @Composable private fun DrawGradient ( offset: Float, modifier: Modifier = Modifier ) { Box (modifier. fillMaxSize (). drawBehind { val shift = offset * 3000f drawRect ( brush = B...