Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix(visionos): multi-scene improvements #10653

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 24 additions & 7 deletions packages/core/platforms/ios/src/NativeScriptMainWindow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ import SwiftUI
import NativeScriptEmbedder
import UIKit

// Ensure runtime phases are called only once per app lifecycle
// In multi-scene apps, we need to ensure runtime doesn't reinit alongside main window
// For example, if @State is used to drive @Environment at the root level, we need to ensure
// a rerender of the main body doesn't cause runtime to cycle again
var hasMainInit = false
var hasMainBoot = false
var hasMainSetMainScene = false

@available(iOS 14.0, *)
struct NativeScriptMainWindow: Scene {

Expand All @@ -18,12 +26,18 @@ struct NativeScriptMainWindow: Scene {
// windowStyle is only supported on visionOS
WindowGroup {
NativeScriptAppView(found: { windowScene in
NativeScriptEmbedder.sharedInstance().setWindowScene(windowScene)
if (!hasMainSetMainScene) {
hasMainSetMainScene = true
NativeScriptEmbedder.sharedInstance().setWindowScene(windowScene)
}
}).onAppear {
// print("NativeScriptAppView onAppear")
DispatchQueue.main.async {
NativeScriptEmbedder.boot()
}
if (!hasMainBoot) {
hasMainBoot = true
DispatchQueue.main.async {
NativeScriptEmbedder.boot()
}
}
}.onReceive(NotificationCenter.default
.publisher(for: NSNotification.Name("NativeScriptWindowOpen")), perform: { obj in
let info = parseWindowInfo(obj: obj)
Expand Down Expand Up @@ -68,9 +82,12 @@ struct NativeScriptMainWindow: Scene {
}

init() {
NativeScriptViewFactory.initShared()
NativeScriptEmbedder.sharedInstance().setDelegate(NativeScriptViewFactory.shared)
NativeScriptEmbedder.setup()
if (!hasMainInit) {
hasMainInit = true
NativeScriptViewFactory.initShared()
NativeScriptEmbedder.sharedInstance().setDelegate(NativeScriptViewFactory.shared)
NativeScriptEmbedder.setup()
}
}

#if os(visionOS)
Expand Down
Loading