nativescript-angular icon indicating copy to clipboard operation
nativescript-angular copied to clipboard

Best practice - How to consider virtual Menu Keys (Android Implementation)

Open echap opened this issue 10 years ago • 1 comments

Hi,

We currently are developping an application using your awesome nativescript-angular framework, but some practices are still hard to determine for us.

Our issue is simple : we are targetting android devices with and without the permanent menu key. What I am missing is the way to get the information if the device has this famous permanent menu key.

With android, I would have used this : ViewConfiguration.hasPermanentMenuKey()

But with nativescript-angular, I'm not sure on how to adress this. I've been trying to get it through app.android.context, but no matter what, I'm unable to exctract this information.

Any help/Best practice to take in account the virtual menu key ?

Thanks !

echap avatar May 27 '16 15:05 echap

We don't have a concrete best practice about that. Here is how i managed to get hold of a ViewConfiguration object and call the hasPermanentMenuKey():

import * as application from "application";
import { nativeScriptBootstrap } from "nativescript-angular/application";
declare var android: any;

// ...

nativeScriptBootstrap(AppComponent).then(() => {
    if (application.android) {
        var context = application.android.context;
        var viewConfig = (<any>android).view.ViewConfiguration.get(context);
        console.log("--------  hasPermanentMenuKey: " + viewConfig.hasPermanentMenuKey());
    }
})

One thing to keep in mind is that the application.android.context is not available immediately - that's why I use the promise returned by the bootstrap and do the check there, when the application is initialized.

vakrilov avatar May 31 '16 13:05 vakrilov