Skip to content

Change the orientation of a page #9976

Answered by vacalaw
GastonVottero asked this question in Q&A
Discussion options

You must be logged in to vote

here is a solution that I found and works for me:

I created a util.js file and put this.

import { Application,  isAndroid } from '@nativescript/core';

export function toggleOrientation(orientation, lockOrientation) {
    (global).lockOrientation = lockOrientation === true;
    console.log('toggleOrientation:', orientation, ' lock:', lockOrientation);
    const valueKey = 'orientation';
    switch (orientation) {
        case 'landscape':
            (global).shouldRotate = true;
            if (global.isAndroid) {
                (Application.android.foregroundActivity).setRequestedOrientation(android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
            } else {
           …

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
4 replies
@AdamAtri
Comment options

@vacalaw
Comment options

@rajeshjadidminc
Comment options

@carminda
Comment options

Answer selected by rigor789
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
6 participants
Converted from issue

This discussion was converted from issue #9958 on July 27, 2022 08:59.