mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-14 10:01:08 +08:00
feat(visionos): ui-mobile-base supporting xros plus improvements to window handling (#10478)
This commit is contained in:
@ -129,7 +129,7 @@ export class iOSApplication extends ApplicationCommon implements IiOSApplication
|
||||
}
|
||||
this._rootView = rootView;
|
||||
// Attach to the existing iOS app
|
||||
const window = this.nativeApp.keyWindow || (this.nativeApp.windows.count > 0 && this.nativeApp.windows[0]);
|
||||
const window = Utils.ios.getWindow();
|
||||
|
||||
if (!window) {
|
||||
return;
|
||||
@ -197,7 +197,7 @@ export class iOSApplication extends ApplicationCommon implements IiOSApplication
|
||||
|
||||
if (minFrameRateDisabled) {
|
||||
let max = 120;
|
||||
const deviceMaxFrames = UIScreen.mainScreen?.maximumFramesPerSecond;
|
||||
const deviceMaxFrames = Utils.ios.getMainScreen().maximumFramesPerSecond;
|
||||
if (options?.max) {
|
||||
if (deviceMaxFrames) {
|
||||
// iOS 10.3
|
||||
@ -208,7 +208,7 @@ export class iOSApplication extends ApplicationCommon implements IiOSApplication
|
||||
}
|
||||
}
|
||||
|
||||
if (Utils.ios.MajorVersion >= 15) {
|
||||
if (Utils.SDK_VERSION >= 15 || __VISIONOS__) {
|
||||
const min = options?.min || max / 2;
|
||||
const preferred = options?.preferred || max;
|
||||
this.displayedLink.preferredFrameRateRange = CAFrameRateRangeMake(min, max, preferred);
|
||||
@ -239,8 +239,12 @@ export class iOSApplication extends ApplicationCommon implements IiOSApplication
|
||||
}
|
||||
|
||||
get window(): UIWindow {
|
||||
if (NativeScriptEmbedder.sharedInstance().delegate && !this._window) {
|
||||
this._window = UIApplication.sharedApplication.keyWindow;
|
||||
// TODO: consideration
|
||||
// may not want to cache this value given the potential of multiple scenes
|
||||
// particularly with SwiftUI app lifecycle based apps
|
||||
if (!this._window) {
|
||||
// Note: NativeScriptViewFactory.getKeyWindow will always be used in SwiftUI app lifecycle based apps
|
||||
this._window = Utils.ios.getWindow();
|
||||
}
|
||||
|
||||
return this._window;
|
||||
@ -316,7 +320,7 @@ export class iOSApplication extends ApplicationCommon implements IiOSApplication
|
||||
|
||||
protected getSystemAppearance(): 'light' | 'dark' {
|
||||
// userInterfaceStyle is available on UITraitCollection since iOS 12.
|
||||
if (Utils.ios.MajorVersion <= 11 || !this.rootController) {
|
||||
if ((!__VISIONOS__ && Utils.SDK_VERSION <= 11) || !this.rootController) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -335,7 +339,12 @@ export class iOSApplication extends ApplicationCommon implements IiOSApplication
|
||||
}
|
||||
|
||||
protected getOrientation() {
|
||||
const statusBarOrientation = UIApplication.sharedApplication.statusBarOrientation;
|
||||
let statusBarOrientation: UIInterfaceOrientation;
|
||||
if (__VISIONOS__) {
|
||||
statusBarOrientation = NativeScriptEmbedder.sharedInstance().windowScene.interfaceOrientation;
|
||||
} else {
|
||||
statusBarOrientation = UIApplication.sharedApplication.statusBarOrientation;
|
||||
}
|
||||
return this.getOrientationValue(statusBarOrientation);
|
||||
}
|
||||
|
||||
@ -362,7 +371,7 @@ export class iOSApplication extends ApplicationCommon implements IiOSApplication
|
||||
this.setWindowContent(root);
|
||||
}
|
||||
} else {
|
||||
this._window = UIApplication.sharedApplication.keyWindow;
|
||||
this._window = this.window; // UIApplication.sharedApplication.keyWindow;
|
||||
}
|
||||
}
|
||||
|
||||
@ -396,11 +405,13 @@ export class iOSApplication extends ApplicationCommon implements IiOSApplication
|
||||
|
||||
this.setViewControllerView(rootView);
|
||||
|
||||
const haveController = this._window.rootViewController !== null;
|
||||
this._window.rootViewController = controller;
|
||||
const win = this.window;
|
||||
|
||||
const haveController = win.rootViewController !== null;
|
||||
win.rootViewController = controller;
|
||||
|
||||
if (!haveController) {
|
||||
this._window.makeKeyAndVisible();
|
||||
win.makeKeyAndVisible();
|
||||
}
|
||||
|
||||
this.initRootView(rootView);
|
||||
@ -417,13 +428,16 @@ export class iOSApplication extends ApplicationCommon implements IiOSApplication
|
||||
@profile
|
||||
private didFinishLaunchingWithOptions(notification: NSNotification) {
|
||||
this.setMaxRefreshRate();
|
||||
// ensures window is assigned to proper window scene
|
||||
this._window = this.window;
|
||||
|
||||
this._window = UIWindow.alloc().initWithFrame(UIScreen.mainScreen.bounds);
|
||||
if (!this._window) {
|
||||
// if still no window, create one
|
||||
this._window = UIWindow.alloc().initWithFrame(UIScreen.mainScreen.bounds);
|
||||
}
|
||||
|
||||
// TODO: Expose Window module so that it can we styled from XML & CSS
|
||||
// Note: visionOS uses it's own material glass
|
||||
if (!__VISIONOS__) {
|
||||
this._window.backgroundColor = Utils.ios.MajorVersion <= 12 || !UIColor.systemBackgroundColor ? UIColor.whiteColor : UIColor.systemBackgroundColor;
|
||||
this.window.backgroundColor = Utils.SDK_VERSION <= 12 || !UIColor.systemBackgroundColor ? UIColor.whiteColor : UIColor.systemBackgroundColor;
|
||||
}
|
||||
|
||||
this.notifyAppStarted(notification);
|
||||
|
Reference in New Issue
Block a user