[0.20] IsNavigationBarVisible removed?

In 0.12, you ould use

<Android.StatusBarConfig IsVisible="true" IsNavigationBarVisible="false" />

to control whether the NavigationBar was displayed or not. Although I believe those controls should be modified at run time, and hence shouldn’t be set once and for all in this node, this was working in 0.12 (except for minor inconsistencies)

In 0.20 however, it’s gone:

MainView.ux(133): E8001: 'Android.StatusBarConfig' does not have a property called 'IsNavigationBarVisible'

Is it intentional? Temporary?

Temporary, we need to design a better API for that feature.

Here is the Uno code for it:

[Foreign(Language.Java)]
extern(Android) void SetNavigationBarVisible(bool visible)
@{
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT)
    {
        android.view.View decorView = @(Activity.Package).@(Activity.Name).GetRootActivity().getWindow().getDecorView();

        int uiOptions = decorView.getSystemUiVisibility();

        if (visible)
        {
            uiOptions &= ~(android.view.View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | android.view.View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
        }
        else
        {
            uiOptions |= android.view.View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | android.view.View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
        }

        decorView.setSystemUiVisibility(uiOptions);
    }
@}

Thank you for that! Finally a good excuse to dive into foreign code :slight_smile:

OK it works fine, but it has to be called before the UX is loaded, otherwise I get: Only the original thread that created a view hierarchy can touch its views.

Once the app is running I’m not sure how to circumvent that.

Hi!

It depends how you are invoking it - if you do it from JS through a native module you have to specify ExecutionThread.MainThread for the method

Hi Anders,

I eventually got it to work the way I want to. Here is the code for the Module, should you or someone else need it:

using Uno;
using Uno.Collections;
using Uno.Compiler.ExportTargetInterop;
using Fuse;
using Fuse.Scripting;

public class NavbarModule : NativeModule
{
    public NavbarModule()
    {
        AddMember(new NativeFunction("HideBar", (NativeCallback)HideBar));
        AddMember(new NativeFunction("ShowBar", (NativeCallback)ShowBar));
    }

    static object HideBar(Context c, object[] args)
    {
        SetNavigationBarVisible(false);

        return null;
    }

    static object ShowBar(Context c, object[] args)
    {
        SetNavigationBarVisible(true);

        return null;
    }


    [Foreign(Language.Java)]
    static extern(Android) void SetNavigationBarVisible(bool visible)
    @{
        android.app.Activity rootActivity = @(Activity.Package).@(Activity.Name).GetRootActivity();

        rootActivity.runOnUiThread(new Runnable() {
            @Override
            public void run() {                android.view.Window window = @(Activity.Package).@(Activity.Name).GetRootActivity().getWindow();
                // This code will always run on the UI thread, therefore is safe to modify UI elements.

                if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT)
                {
                    android.view.View decorView = window.getDecorView();

                    int uiOptions = decorView.getSystemUiVisibility();

                    if (visible)
                    {
                        uiOptions &= ~(android.view.View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | android.view.View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
                    }
                    else
                    {
                        uiOptions |= android.view.View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | android.view.View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
                    }

                    decorView.setSystemUiVisibility(uiOptions);
                }
            }
        });
    @}

    static extern(!Android) void SetNavigationBarVisible(bool visible)
    {
        debug_log "SetNavigationBarVisible not available on this platform";
    }
}

Implemented this but its only hiding the status bar not the nav bar. Any ideas?

<Android.StatusBarConfig IsVisible="false" IsNavigationBarVisible="false" />

Yes that was the starting point of the thread, the NavBar cannot be controlled in 0.20. However, using my code (above your post) you can toggle the navigation bar at will.

I hadn’t refreshed the page in weeks, thus totally missing your addition! That clears up a lot :slight_smile:

Cyril, Would you mind explaining how to call that in the UX page? I’m new to this.

Thanks

It’s a Native Module. Copy the code I posted to a NavbarModule.uno file, and add it in your UX like that:

<NavbarModule ux:Global="NavbarModule" />

<JavaScript>
    var NavbarModule = require('NavbarModule');
    NavbarModule.HideBar();
</JavaScript>

I did it what you told but I got an error.

What i did is
Created .uno file .
Include “*.uno:File” in .unoproj .
Added NavbarModule ux:Global=“NavbarModule” in .ux file.

Error

E3114: There is nothing named ‘NavbarModule’ accessible in this scope. Are you missing a package reference?

Any Solution ?

File is not an appropriate file type for Uno source files. Either use Source, or don’t specify the file type (since Source is the default for .uno files). See the .unoproj docs for more information.

Thanks i got it.