feat(visionos): ui-mobile-base supporting xros plus improvements to window handling (#10478)

This commit is contained in:
Nathan Walker
2024-04-05 17:07:16 -07:00
committed by GitHub
parent 9ca490250e
commit 01d537bf15
242 changed files with 8658 additions and 2099 deletions

View File

@@ -1,6 +1,7 @@
import { Color } from '../../color';
import { Trace } from '../../trace';
import { CORE_ANIMATION_DEFAULTS, getDurationWithDampingFromSpring } from '../common';
import { SDK_VERSION } from '../constants';
declare let UIImagePickerControllerSourceType: any;
@@ -63,6 +64,14 @@ export function getRootViewController(): UIViewController {
}
export function getWindow(): UIWindow {
let window: UIWindow;
if (SDK_VERSION >= 15) {
// UIWindowScene.keyWindow is only available 15+
window = NativeScriptViewFactory.getKeyWindow();
}
if (window) {
return window;
}
const app = UIApplication.sharedApplication;
if (!app) {
return;
@@ -70,6 +79,11 @@ export function getWindow(): UIWindow {
return app.keyWindow || (app.windows && app.windows.count > 0 && app.windows.objectAtIndex(0));
}
export function getMainScreen(): UIScreen {
const window = getWindow();
return window ? window.screen : UIScreen.mainScreen;
}
export function setWindowBackgroundColor(value: string) {
const win = getWindow();
if (win) {
@@ -158,9 +172,7 @@ export function createUIDocumentInteractionControllerDelegate(): NSObject {
public static ObjCProtocols = [UIDocumentInteractionControllerDelegate];
public getViewController(): UIViewController {
const app = UIApplication.sharedApplication;
return app.keyWindow.rootViewController;
return getWindow().rootViewController;
}
public documentInteractionControllerViewControllerForPreview(controller: UIDocumentInteractionController) {

View File

@@ -1,4 +1,5 @@
import * as layoutCommon from './layout-helper-common';
import { getMainScreen } from '../ios';
export namespace layout {
// cache the MeasureSpec constants here, to prevent extensive marshaling calls to and from Objective C
@@ -32,15 +33,15 @@ export namespace layout {
}
export function getDisplayDensity(): number {
return UIScreen.mainScreen.scale;
return getMainScreen().scale;
}
export function toDevicePixels(value: number): number {
return value * UIScreen.mainScreen.scale;
return value * getMainScreen().scale;
}
export function toDeviceIndependentPixels(value: number): number {
return value / UIScreen.mainScreen.scale;
return value / getMainScreen().scale;
}
export function round(value: number) {