Device.isUsingDarkAppearance() is not working on iOS 16.3.1

I can’t change ListWidget background based on the dark mode on/off. It seems that it’s working in the App but as a Widget placed in home screen not.

function setupBackground(widget) {
let gradient = new LinearGradient()
gradient.locations = [0, 1]

let colors
if (Device.isUsingDarkAppearance()) {
colors = [new Color(“#08203E”), new Color(“#557C93”)]
} else {
colors = [new Color(“#2980B9”), new Color(“#6DD5FA”)]
}

gradient.colors = colors
widget.backgroundGradient = gradient
}

Was it working before? There are alternative ways to achieve what you’re wanting.

!(Color.dynamic(Color.white(),Color.black()).red)

The above will result in a color value for red in the color white or color black depending on which appearance is being used.

You can see an example here in this script

From the docs:

+isUsingDarkAppearance
Whether the device is using dark appearance.

static isUsingDarkAppearance(): bool

This API is not supported in widgets.

1 Like