Welcome to the repository that demonstrates an advanced and scalable method for managing multiple windows and immersive spaces in a visionOS application, using a unified setMode function!
Note: This approach ensures that transitions between different app states are smooth, scalable, and maintainable — essential for real-world spatial computing apps.
- Unified Navigation: Easily open/close windows and immersive spaces with a single operation.
- Custom Environment Key: Introduces a
setModeenvironment value available throughout the app. - Dynamic Flow Handling: Supports both simple and complex application flows.
- Full Support for Spatial Computing: Manage multiple simultaneous elements if needed.
- Concurrency Safe: Designed with Swift 6 concurrency features in mind.
-
Define a Custom Environment Key (
setMode)- Injects a function to change modes across the entire app.
-
Static Window and Space Identifiers
- Centralized in a
WindowIDsstruct for maintainability.
- Centralized in a
-
Mode Enum
- Represents all possible app states (windows or immersive spaces).
- Includes helper computed properties to manage state behavior.
-
App Scene Injection
- Injects
setModeinto every view by wrapping the windows into aGroup.
- Injects
-
Smart setMode Function
- Handles opening, closing, and overlapping windows, as well as immersive space transitions.
- Manages
@Statevalues such asmode,immersiveSpacePresented, andoverlappingWindows.
struct WelcomeView: View {
@Environment(\.setMode) private var setMode
var body: some View {
Button("Go to main screen") {
Task { await setMode(.mainScreen) }
}
}
}✅ Scalability: Add whatever new window or immerive space target, just change your algorithm!
✅ Maintainability: One centralized way to manage window/immersive transitions.
✅ VisionOS Best Practices: Designed with spatial computing's multi-window nature in mind.
✅ Concurrency Safety: Designed to also work with Swift 6 strict concurrency.
- VisionTextArc — Create beautiful 3D curved text in visionOS!
Feel free to fork this project, open issues, and make pull requests!
Let's build better spatial computing apps together.
