How to lock interface orientation in version 10?

How to lock interface orientation in version 10?

  

Hi, 

In version 9 orientation lock (for example only portrait) was made in native apps. How to achieve that in version 10? 

Thank you

Hello Nick.

You have two options:

  1. Define a preference using the Extensibility Configuration that will influence compile time and will lock orientation for the entire application:

{
    "preferences": {
        "global": [{
            "name": "orientation",
            "value": "landscape"
        }]
}

This should be in the HomeModule of your application. It's missing some documentation, but it's already available.

  2. Use a plugin. This will allow you to dynamically lock/unlock orientation. There's a Cordova Plugin Screen Orientation.


Thanks


Hi César,

I've tried first option as it is behavior we need in application. But it seems it is braking the third-party plugin... in this case zeroconf plugin that is working ok if I do not include this preference. Is it a bug or in case of additional pluins there is another way?

Hello Nick.

Are you using just one module in your application? If so, in the home module, your Extensibility Configuration should look similar to:

{
   "plugin" : {
      "url" : "https://github.com/becvert/cordova-plugin-zeroconf#1.1.2"
   },
   "preferences": {
        "global": [{
            "name": "orientation",
            "value": "landscape"
        }]
   }
}

Let me know if it works. 

Remember that you can only have preferences in the home module of your application. Plugins can be referenced.

Thanks


I've put this code and app crashes on load.. (I've attached oml to test)

{
   "plugin" : {
      "url" : "https://github.com/becvert/cordova-plugin-zeroconf#1.1.2"
   },
   "preferences": {
        "global": [{
            "name": "orientation",
            "value": "portrait"
        }]
   }
}

I've tried to put plugin module in separate app but then my app crashes on load.

So what should be my project structure If I have multiple third-party plugins in the app? Each plugin as a home empty module in separate app, Main app with referencies to each plugin? 

Solution

Hello Nick.

Seems like you're placing the plugin URL in both your application and the referenced ZeroConf plugin. You should have it only in the ZeroConf plugin.

The structure should be like you said in your last sentence:


The HomeModule of your App will have preferences and reference other apps that are Plugins. You would have something like this in ServiceStudio:

So, in your example, PluginsTestAllInOne should have the preferences and ZeroConf should be referenced (and have the plugin URL).

Let me know if you're unable to lock orientation, I'll help.

Thanks

Solution

Hi César,

 My bad - I've tested possibility to set plugin and prefs in one module, but forgot to remove reference... 

Now all is working as it should - plugin and orientation lock:) 

Thank you very much for your help.


PS: Is there a documentation with available preferences options?