FR: Add method to change colour of iOS/Android status bar

EDIT: changed this into a feature request.

Hi there, perhaps someone can help me with this.

My app has dark and light modes which can either change automatically according to the system or can be manually set by the user (just as in messenger, telegram, etc.)

The atomatic setting works fine by regularly polling Desktop::getInstance().isDarkModeActive() and setting the appropiate colour mode of the app.

But when the user manually sets the mode to something different from the current system mode, the status bar has obviously the wrong colour.

Any ideas? There doesnā€™t seem to be a JUCE method to change the colour of the status bar.

Ok, in the end I sorted this out with a hack to the codebase. Iā€™ll submit a feature request because it would be very easy to implement this properly in JUCE. My quick and dirty solution:

In juce_Desktop.h add a public variable:

int colourMode = 0; // 0 default, 1 light content, 2 dark content

And in juce_ios_UIViewComponentPeer.mm change this:

- (UIStatusBarStyle) preferredStatusBarStyle
{
    return UIStatusBarStyleDefault;
}

to this:

- (UIStatusBarStyle) preferredStatusBarStyle
{
    if (Desktop::getInstance().colourMode == 2)
        return UIStatusBarStyleLightContent;

    else if (Desktop::getInstance().colourMode == 1)
	
    	if (@available(iOS 13.0, *)) 
            return UIStatusBarStyleDarkContent;

    return UIStatusBarStyleDefault;	
}

Then, to change the colour mode, from the mainComponent call:

Desktop::getInstance().colourMode = newColourMode;
Desktop::getInstance().setKioskModeComponent (getParentComponent(), false);
Desktop::getInstance().setKioskModeComponent (nullptr);

Setting and unsetting the kiosk mode causes iOS to update the change.

1 Like

Iā€™ve added this functionality for iOS here:

On Android, Iā€™m not sure whether a feature like this is necessary. At least on the emulator I used for testing, the status bar always had a black background, and the content was always legible.

2 Likes

Ah, thatā€™s great, thanks a lot!

Hi there @reuk, if you have the time, would you take a look into this again and perhaps implement the feature for Android?

It turns out that the status bar on Android does not always have a black background. Itā€™s colour can be set using a theme and nowdays the most common look seems to be transparent. So being able to set the app style on Android is just as necessary as on iOS.

:slight_smile: I couldnā€™t wait:

1 Like