SwiftfulRouting icon indicating copy to clipboard operation
SwiftfulRouting copied to clipboard

Animation moved start from top leading when applying the RouterView wrapper

Open deventw opened this issue 1 year ago • 2 comments

RouterView Wrapper seems might affect the Animation view

  • Without RouterView:
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

deventw avatar Jul 20 '24 02:07 deventw

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

.task {
     self.isSpinning = true
}

SwiftfulThinking avatar Jul 20 '24 04:07 SwiftfulThinking

FYI:Might related to NavigationStack

deventw avatar Jul 20 '24 06:07 deventw

This should be fixed in Version 6 (https://github.com/SwiftfulThinking/SwiftfulRouting/releases/tag/beta-6.1)

SwiftfulThinking avatar Apr 20 '25 18:04 SwiftfulThinking