Answers for "swiftui Scene change"

0

how to compose a custom scene in swiftui

import SwiftUI

@main
struct CardioBotApp: App {
    @Environment(\.scenePhase) var scenePhase
    @StateObject var store = Store(
        initialState: AppState(),
        reducer: appReducer,
        environment: .live
    )

    var body: some Scene {
        WindowGroup {
            RootView().environmentObject(store)
        }
        .onChange(of: scenePhase) { phase in    
            switch phase {
            case .background:
                store.send(.notifications(.startObservers))
            case .active:
                store.send(.fetch)
            default: break
            }
        }
    }
}
Posted by: Guest on December-11-2020

Code answers related to "Swift"

Browse Popular Code Answers by Language