I'm trying to figure out how to lock my Screen Orientation for the entire application, so when it's deployed to Android/iOS, it is only used in its portrait mode.
I see quite a few questions asked and answered using Cordova and the config.xml. But I am using Capacitor so it's not the same as I don't have an config.xml file. Instead I have a ionic.config.json
file.
This is what I have so far in my app.module.ts
and app.component.ts
:
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { RouteReuseStrategy } from '@angular/router';
import { IonicModule, IonicRouteStrategy } from '@ionic/angular';
import { AppComponent } from './app.component';
import { AppRoutingModule } from './app-routing.module';
import {ScreenOrientation} from "@ionic-native/screen-orientation/ngx";
@NgModule({
declarations: [AppComponent],
entryComponents: [],
imports: [BrowserModule, IonicModule.forRoot(), AppRoutingModule],
providers: [{ provide: RouteReuseStrategy, useClass: IonicRouteStrategy }, ScreenOrientation],
bootstrap: [AppComponent],
})
export class AppModule {
constructor() {
}
}
And
export class AppComponent {
constructor(private screenOrientation: ScreenOrientation) {
this.screenOrientation.lock(this.screenOrientation.ORIENTATIONS.PORTRAIT);
}
}
But I don't believe this will actually lock my screenOrientation for the whole app. I've tried looking at Ionic documentation but it's so incredibly bare.