Show a new View from Button press Swift UI

Possible solutions 1.if you want to present on top of current view(ex: presentation style in UIKit) struct ContentView: View { @State var showingDetail = false var body: some View { Button(action: { self.showingDetail.toggle() }) { Text(“Show Detail”) }.sheet(isPresented: $showingDetail) { DetailView() } } } 2.if you want to reset current window scene stack(ex:after login show … Read more

SwiftUI 2: the way to open view in new window

Update: Xcode 14 / macOS 13 Now we can explicitly open needed window giving it identifier and use it in openWindow environment action. class BookViewModel: ObservableObject {} class AppState: ObservableObject { @Published var selectedBook: BookViewModel? } @main struct SwiftUI2_MacApp: App { @StateObject var appState = AppState() @SceneBuilder var body: some Scene { WindowGroup { // … Read more

Accessing AppState in AppDelegate with SwiftUI’s new iOS 14 life cycle

Use shared instance for AppState class AppState: ObservableObject { static let shared = AppState() // << here !! // Singe source of truth… @Published var user = User() } so you can use it everywhere struct MyApp: App { @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate @StateObject var appState = AppState.shared // … other code } and func application(_ … Read more

SwiftUI: Translucent background for fullScreenCover

Here is a demo of possible way. Parameters of visual effect you can tune for your needs. Tested with Xcode 12 / iOS 14. // … other code .fullScreenCover(isPresented: $isLoading) { ZStack{ Color.black.opacity(0.5).edgesIgnoringSafeArea(.all) VStack { ProgressView() Button(“Stop loading”) { isLoading.toggle() } } } .background(BackgroundBlurView()) } } } } struct BackgroundBlurView: UIViewRepresentable { func makeUIView(context: Context) … Read more

Chaining animations in SwiftUI

As mentioned in the other responses, there is currently no mechanism for chaining animations in SwiftUI, but you don’t necessarily need to use a manual timer. Instead, you can use the delay function on the chained animation: withAnimation(Animation.easeIn(duration: 1.23)) { self.doSomethingFirst() } withAnimation(Animation.easeOut(duration: 4.56).delay(1.23)) { self.thenDoSomethingElse() } withAnimation(Animation.default.delay(1.23 + 4.56)) { self.andThenDoAThirdThing() } I’ve found … Read more