6

I am trying to create an animation for presenting and dismissing a group of objects. I have:

if self.showSignInButtons {
    Group {
        Button(action: {}) { ... }
        HStack { ... }
        Button(action: {}) { ... }
    }.transition(
        AnyTransition.signInButtonTransition(
        offset: geometry.size.height,
        duration: 1.4,
        delay: 50.0)
    )
}

Here is the definition of the custom AnyTransition animation

public extension AnyTransition {

    static func signInButtonTransition(offset: CGFloat, duration: Double, delay: Double) -> AnyTransition {
        let insertion = AnyTransition.offset(y: offset)
            .animation(Animation.easeOut(duration: duration).delay(delay))
        let removal = AnyTransition.offset(y: offset).animation(.default)
        return .asymmetric(insertion: insertion, removal: removal)
    }
}

My goal is to delay the insertion animation to create a sequence, but I don't want there to be a delay when the view is dismissed. The problem is the asymmetric animation is using the default animation despite the added animation modifier. Is there any reason the delay and duration animation on the insertion are being ignored?

  • I'm not 100% sure, but I think that the main `Animation` used to fire off the transition within the host view (where the transition is included) overrides this transition-specific animations. Not sure how to prevent this though. – D6mi Apr 29 '22 at 08:11

0 Answers0