Skip to content

Device orientation returns 0/Unknown on init #317

@brianrclow

Description

@brianrclow

File in question: xplat/nativescript/core/src/lib/services/app.service.ts

This App Service gets the orientation on initialization and can be used for when the orientation changes. The getOrientation() function returns an empty string when it can't match landscape or portrait for UIDevice.currentDevice.orientation

At first I thought this was an issue with not being able to get the orientation on a simulator but I also tried on a few devices and got the same results. The service couldn't get the orientation so it defaulted to 0 which is Unknown, in this case it defaults to portrait.

let orientation = getOrientation();
this.orientation = orientation ? orientation : CoreTypes.DeviceOrientation.portrait;

This normally isn't an issue as many apps are portrait by default but for an app that needs to open in landscape and support landscape features properly, it doesn't quite work. The service does get landscape as the orientation but only after going from landscape (on open), to portrait then back to landscape.

I'm curious if this is a limitation of when this service gets initialized in the app lifecycle or if this is something that can be updated/improved, how that process would work?

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions