Skip to content

Commit 4166e2d

Browse files
vchimevmanoldonev
authored andcommitted
fix: expose orientation to application module (#7832)
1 parent 25046c7 commit 4166e2d

4 files changed

Lines changed: 20 additions & 2 deletions

File tree

‎tests/app/application/application-tests-common.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,7 @@ export function testDisplayedEvent() {
2121
// global.isDisplayedEventFired flag is set in app.ts application.displayedEvent handler
2222
TKUnit.assert((<any>global).isDisplayedEventFired, "application.displayedEvent not fired");
2323
}
24+
25+
export function testOrientation() {
26+
TKUnit.assert(app.orientation, "Orientation not initialized.");
27+
}

‎tns-core-modules/application/application.android.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,10 @@ export function getNativeApplication(): android.app.Application {
248248
return nativeApp;
249249
}
250250

251+
export function orientation(): "portrait" | "landscape" | "unknown" {
252+
return androidApp.orientation;
253+
}
254+
251255
on(orientationChangedEvent, (args: OrientationChangedEventData) => {
252256
const rootView = getRootView();
253257
if (rootView) {

‎tns-core-modules/application/application.d.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,12 @@ export function on(event: "discardedError", callback: (args: DiscardedErrorEvent
285285
*/
286286
export function on(event: "orientationChanged", callback: (args: OrientationChangedEventData) => void, thisArg?: any);
287287

288+
/**
289+
* Gets the orientation of the application.
290+
* Available values: "portrait", "landscape", "unknown".
291+
*/
292+
export function orientation(): "portrait" | "landscape" | "unknown";
293+
288294
/**
289295
* This is the Android-specific application object instance.
290296
* Encapsulates methods and properties specific to the Android platform.

‎tns-core-modules/application/application.ios.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ const Responder = (<any>UIResponder).extend({
3939
// NOOP
4040
}
4141
}, {
42-
protocols: [UIApplicationDelegate]
43-
}
42+
protocols: [UIApplicationDelegate]
43+
}
4444
);
4545

4646
class NotificationObserver extends NSObject {
@@ -415,6 +415,10 @@ function setViewControllerView(view: View): void {
415415
}
416416
}
417417

418+
export function orientation(): "portrait" | "landscape" | "unknown" {
419+
return iosApp.orientation;
420+
}
421+
418422
on(orientationChangedEvent, (args: OrientationChangedEventData) => {
419423
const rootView = getRootView();
420424
if (rootView) {

0 commit comments

Comments
 (0)