Minor API change Cleanup Improved documentation
Minor API change
Cleanup Improved documentation
Access the current UIWindowScene from SwiftUI
UIWindowScene
Read the current UIWindowScene with WindowSceneReader
WindowSceneReader
@main struct MyApp: App { var body: some Scene { WindowGroup { WindowSceneReader { windowScene in ContentView() } } } }
@main struct MyApp: App { var body: some Scene { WindowGroup { ContentView() .windowScene() } } }
On child views the UIWindowScene will be available in the Environment
Environment
class SceneDelegate: UIResponder, UIWindowSceneDelegate { var window: UIWindow? func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { if let windowScene = scene as? UIWindowScene { let rootView = ContentView() .windowScene(windowScene) let window = UIWindow(windowScene: windowScene) window.rootViewController = UIHostingController(rootView: rootView) self.window = window window.makeKeyAndVisible() } }
@Environment(\.windowScene) var windowScene
The @Environment(\.windowScene) var windowScene defaults to the first connected UIWindowScene or nil if no UIWindowScene is connected.
nil
See LICENSE
©Copyright 2023 CCF 开源发展委员会 Powered by Trustie& IntelliDE 京ICP备13000930号
WindowSceneReader
Access the current
UIWindowScene
from SwiftUIUsage
SwiftUI Lifecycle
Read the current
UIWindowScene
withWindowSceneReader
On child views the
UIWindowScene
will be available in theEnvironment
UIKit Lifecycle
Environment
The
@Environment(\.windowScene) var windowScene
defaults to the first connectedUIWindowScene
ornil
if noUIWindowScene
is connected.License
See LICENSE