The ThemeDetection API provides simple methods to detect whether the dark mode is enabled on the device or not.
ThemeDetection.isAvailable()
.then((res) => {
if(res.value) {
ThemeDetection.isDarkModeEnabled().then((res) => {
console.log(res);
})
.catch((error) => console.error(error));
}
})
.catch((error) => console.error(error));
window.ThemeDetection.isAvailable()
.then((res) => {
if (res.value) {
window.ThemeDetection.isDarkModeEnabled()
.then((res) => {
console.log(res);
})
.catch((error) => console.error(error));
}
})
.catch((error) => console.error(error));
window.ThemeDetection.isAvailable()
.then((res) => {
if (res.value) {
window.ThemeDetection.isDarkModeEnabled()
.then((res) => {
console.log(res);
})
.catch((error) => console.error(error));
}
})
.catch((error) => console.error(error));
(<any>window).ThemeDetection.isAvailable()
.then((res) => {
if (res.value) {
(<any>window).ThemeDetection.isDarkModeEnabled()
.then((res) => {
console.log(res);
})
.catch((error) => console.error(error));
}
})
.catch((error) => console.error(error));
window.ThemeDetection.isAvailable()
.then((res) => {
if (res.value) {
window.ThemeDetection.isDarkModeEnabled()
.then((res) => {
console.log(res);
})
.catch((error) => console.error(error));
}
})
.catch((error) => console.error(error));
isAvailable(): Promise <ThemeDetectionResponse>
Checks if dark mode is supported by the device and returns an ThemeDetectionResponse object with a boolean value and a message.
isDarkModeEnabled(): Promise <ThemeDetectionResponse>
Checks whether the dark mode is enabled on device and returns an ThemeDetectionResponse object with a boolean value and a message.
ThemeDetectionResponse {
value: boolean; // True is enabled/available
message: string;
}