SwiftfulThinking / SwiftfulRouting

Programmatic navigation for SwiftUI applications.
https://www.swiftful-thinking.com/
MIT License
461 stars 31 forks source link

Animation moved start from top leading when applying the RouterView wrapper #67

Open deventw opened 4 months ago

deventw commented 4 months ago

RouterView Wrapper seems might affect the Animation view

import SwiftUI
import SwiftfulRouting

struct ContentView: View {
    var body: some View {
//        RouterView { _ in
            LandingView()
//        }
    }
}

struct LandingView: View {
    @State private var isSpinning = false
    var body: some View {
            VStack(){
                Rectangle()
                    .fill(.orange.opacity(0.3))
                    .frame(width: 256)
            }
            .rotationEffect(.degrees(isSpinning ? 360 : 0))
            .onAppear() {
                self.isSpinning = true
            }
            .animation(Animation.linear(duration: 3).repeatForever(autoreverses: false), value: isSpinning)

    }
}

https://github.com/user-attachments/assets/584a174b-cf27-4b39-ba88-3ac4dd5b56bf

The View is Spinning in the screen center as expected when not applying RouterView


After Apply RouterView:

import SwiftUI
import SwiftfulRouting

struct ContentView: View {
    var body: some View {
        RouterView { _ in
            LandingView()
        }
    }
}

https://github.com/user-attachments/assets/29adef30-f92c-4bb4-9550-5b49ea196d4a

SwiftfulThinking commented 4 months ago

This is weird but it seems to work with .task instead of .onAppear. I'll look into this...

.task {
     self.isSpinning = true
}
deventw commented 4 months ago

FYI:Might related to NavigationStack