feat(ios): Utils.getRootViewController

This commit is contained in:
Nathan Walker
2022-05-19 15:11:11 -07:00
parent 50fd3c06f8
commit 29004d9048
2 changed files with 15 additions and 0 deletions

View File

@ -132,6 +132,11 @@ export namespace iOSNativeHelper {
export function nsArrayToJSArray<T>(a: NSArray<T>): T[];
}
/**
* Get the root UIViewController of the app
*/
export function getRootViewController(): any; /* UIViewController */
/**
* Data serialize and deserialize helpers
*/

View File

@ -136,6 +136,16 @@ export namespace iOSNativeHelper {
}
}
export function getRootViewController(): UIViewController {
const app = UIApplication.sharedApplication;
const win = app.keyWindow || (app.windows && app.windows.count > 0 && app.windows.objectAtIndex(0));
let vc = win.rootViewController;
while (vc && vc.presentedViewController) {
vc = vc.presentedViewController;
}
return vc;
}
export function isLandscape(): boolean {
console.log('utils.ios.isLandscape() is deprecated; use application.orientation instead');