How to make Rainbow border animation for box in compose, all the examples that I saw are for Circle and they use rotate with drawbehind, but what I really need is to make the same for a Box in compose.
Thanks
With rotate but it didn´t work
How to make Rainbow border animation for box in compose, all the examples that I saw are for Circle and they use rotate with drawbehind, but what I really need is to make the same for a Box in compose.
Thanks
With rotate but it didn´t work
Copyright © 2021 Jogjafile Inc.
This can be accomplished using BlendModes. If you are not familiar with BlendModes you can check out answers below.
Jetpack Compose Applying PorterDuffMode to Image
How to clip or cut a Composable?
Result
You need to create a Brush.sweepGradient with rainbow colors first
Then need draw this sweep gradient as circle that overflows from our composable then we will draw a rectangle for borders with some color and apply BlendMode.SrcIn on circle to get rectangle shape with circle brush we rotate with infinite animation
Edit
If you wish to draw with
Shapeyou can use function below. This function needs to use Modifier.clip because drawing aOutlinethat is smaller than original shape size withcreates very small but noticeable blank space near corners with RoundedCornerShape and probably with other custom shapes depending how they are aligned. I checked out how Modifier.border prevents this, it checks for 3 shape types
When it's generic type it creates mask
Pathwhich i don't intend to do for this example but if you don't want to clip content you can implement similar approach.Usage
Extra bubble shape
Full sample available in this tutorial with resources and everything else