If I have clip=true for an animation like this: ``...
# compose
z
If I have clip=true for an animation like this:
Copy code
expandVertically(
    animationSpec = ..,
    expandFrom = ..,
    clip = true,
)
Is there any way I can change that externally in compose, say when Im using AnimatedContent?
j
Wouldn’t passing in the clip param work?
z
yup, that would work, but i never reference this from my code. i just have fade and various effects that makes use of this under the hood. kind of like premade animations. kind of like this: https://gist.github.com/c5inco/796edc5d88e8561872380b61e6089c04
ideally id love to be able to pass clip=true/false into say, animatedcontent and the like, so even if im using the same FadeHorizontally animation in a bunch of places, theres really just like 2 scenarios where clipping is an issue.
j
yup, that would work, but i never reference this from my code.
I don’t fully understand what you mean. If this is your code why cannot you pass in the values you want? Couldn’t you use a default value for the existing code and override the default for the situation where you don’t want clipping?
z
ultimately because theyre hard-coded, like in the gist above. i just have a bunch of these:
Copy code
internal val ExpandVertically =
    expandVertically(
        animationSpec = SizeAnimator,
        expandFrom = CenterVertically,
        clip = true,
    )
in my design system; which premade animations make use of internally.
i could copy the code, create a new premade animation just for this purpose, but im trying to avoid that. ill eventually refactor my code so that i can pass in clip dynamically though.
Copy code
data object Fade : Effect {
    override fun invoke() = FadeIn togetherWith FadeOut
}
this is what the premade animation looks like, one of many.
j
Couldn’t you create a second variable that doesn’t clip? Or use a
@Composable
lambda that returns the appropriate animation? You could still assign the existing animation to a variable and new usages that need dynamic clipping would call the lambda?
z
yup, ill probably end up doing something like that when i get to refactor my code. there are a lot of these, so i wanted to check if theres any other way to do it that just works™️