diff --git a/tests/app/application/application-tests-common.ts b/tests/app/application/application-tests-common.ts index 47dc01e94..6d0179eb0 100644 --- a/tests/app/application/application-tests-common.ts +++ b/tests/app/application/application-tests-common.ts @@ -21,3 +21,7 @@ export function testDisplayedEvent() { // global.isDisplayedEventFired flag is set in app.ts application.displayedEvent handler TKUnit.assert((global).isDisplayedEventFired, "application.displayedEvent not fired"); } + +export function testOrientation() { + TKUnit.assert(app.orientation, "Orientation not initialized."); +} diff --git a/tns-core-modules/application/application.android.ts b/tns-core-modules/application/application.android.ts index b1d633c62..25e04594b 100644 --- a/tns-core-modules/application/application.android.ts +++ b/tns-core-modules/application/application.android.ts @@ -248,6 +248,10 @@ export function getNativeApplication(): android.app.Application { return nativeApp; } +export function orientation(): "portrait" | "landscape" | "unknown" { + return androidApp.orientation; +} + on(orientationChangedEvent, (args: OrientationChangedEventData) => { const rootView = getRootView(); if (rootView) { diff --git a/tns-core-modules/application/application.d.ts b/tns-core-modules/application/application.d.ts index 672e55cc5..48217c411 100644 --- a/tns-core-modules/application/application.d.ts +++ b/tns-core-modules/application/application.d.ts @@ -285,6 +285,12 @@ export function on(event: "discardedError", callback: (args: DiscardedErrorEvent */ export function on(event: "orientationChanged", callback: (args: OrientationChangedEventData) => void, thisArg?: any); +/** + * Gets the orientation of the application. + * Available values: "portrait", "landscape", "unknown". + */ +export function orientation(): "portrait" | "landscape" | "unknown"; + /** * This is the Android-specific application object instance. * Encapsulates methods and properties specific to the Android platform. diff --git a/tns-core-modules/application/application.ios.ts b/tns-core-modules/application/application.ios.ts index 37a834096..60fd1fda8 100644 --- a/tns-core-modules/application/application.ios.ts +++ b/tns-core-modules/application/application.ios.ts @@ -39,8 +39,8 @@ const Responder = (UIResponder).extend({ // NOOP } }, { - protocols: [UIApplicationDelegate] - } + protocols: [UIApplicationDelegate] +} ); class NotificationObserver extends NSObject { @@ -415,6 +415,10 @@ function setViewControllerView(view: View): void { } } +export function orientation(): "portrait" | "landscape" | "unknown" { + return iosApp.orientation; +} + on(orientationChangedEvent, (args: OrientationChangedEventData) => { const rootView = getRootView(); if (rootView) {