Skip to content

Commit 6aa7f11

Browse files
authored
Scheme - add isDarkMode function (#2847)
1 parent a09b5ad commit 6aa7f11

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

src/style/__tests__/scheme.spec.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,15 @@ describe('Scheme', () => {
105105
expect(listener).toHaveBeenCalledTimes(1);
106106
});
107107
});
108+
109+
describe('isDarkMode', () => {
110+
it('should return false when app is on light mode', () => {
111+
expect(Scheme.isDarkMode()).toBe(false);
112+
});
113+
114+
it('should return true when app is on dark mode', () => {
115+
Scheme.setScheme('dark');
116+
expect(Scheme.isDarkMode()).toBe(true);
117+
});
118+
});
108119
});

src/style/colors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ export class Colors {
177177
return validColors ? undefined : results[0];
178178
}
179179

180-
shouldReverseOnDark = (avoidReverseOnDark?: boolean) => !avoidReverseOnDark && this.shouldSupportDarkMode && Scheme.getSchemeType() === 'dark';
180+
shouldReverseOnDark = (avoidReverseOnDark?: boolean) => !avoidReverseOnDark && this.shouldSupportDarkMode && Scheme.isDarkMode();
181181

182182
getColorTint(colorValue: string | OpaqueColorValue, tintKey: string | number, options: GetColorTintOptions = {}) {
183183
if (_.isUndefined(tintKey) || isNaN(tintKey as number) || _.isUndefined(colorValue)) {

src/style/scheme.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ class Scheme {
3232
return scheme ?? 'light';
3333
}
3434

35+
/**
36+
* Whether the app's scheme is 'dark', i.e. is on dark mode
37+
*/
38+
isDarkMode() {
39+
return this.getSchemeType() === 'dark';
40+
}
41+
3542
/**
3643
* Set color scheme for app
3744
* arguments:

0 commit comments

Comments
 (0)