frzi / swiftui-router

Path-based routing in SwiftUI
MIT License
900 stars 43 forks source link

`.opacity` transition not working #61

Open jeanbaptistebeau opened 1 year ago

jeanbaptistebeau commented 1 year ago

I followed the doc Animating Routes and tried to replace the transition with .opacity, but it doesn't work. When using .move(edge: .bottom).combined(with: .opacity), only the move transition is executed.

jeanbaptistebeau commented 1 year ago

That could actually be a general bug in SwiftUI, according to this SO answer. I'm currently investigating this.

frzi commented 1 year ago

Opacity transition (which should be default) has always been finicky. IIRC it only works if the .animation is applied directly to a top-level view which is rendered conditionally. I.e.:

Group {
    if showText {
        Text("Hello world")
            .animation(.linear)
    }
}

This is most likely due to Route views always being rendered. It's only the content (the child views) which are rendered conditionally. Or something along those lines 😛

Fair warning: the Animating Routes documentation no longer works as expected since iOS 16.