Skip to content

Commit bc310c2

Browse files
authored
Update color presets when scheme changes (#1309)
1 parent db2fcfa commit bc310c2

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

generatedTypes/style/colors.d.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,14 @@ declare const colorObject: Colors & {
118118
purple20: string;
119119
purple30: string;
120120
purple40: string;
121+
/**
122+
* Add alpha to hex or rgb color
123+
* arguments:
124+
* p1 - hex color / R part of RGB
125+
* p2 - opacity / G part of RGB
126+
* p3 - B part of RGB
127+
* p4 - opacity
128+
*/
121129
purple50: string;
122130
purple60: string;
123131
purple70: string;

src/style/colors.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import {Appearance} from 'react-native';
12
import _ from 'lodash';
23
//@ts-ignore
34
import Color from 'color';
@@ -15,6 +16,10 @@ export class Colors {
1516
constructor() {
1617
const colors = Object.assign(colorsPalette, themeColors);
1718
Object.assign(this, colors);
19+
20+
Appearance.addChangeListener(({colorScheme}: Appearance.AppearancePreferences) => {
21+
Object.assign(this, this.schemes[colorScheme ?? 'light']);
22+
});
1823
}
1924
/**
2025
* Load custom set of colors
@@ -41,6 +46,8 @@ export class Colors {
4146
}
4247

4348
this.schemes = schemes;
49+
const colorScheme = Appearance.getColorScheme();
50+
Object.assign(this, this.schemes[colorScheme ?? 'light']);
4451
}
4552

4653
/**

0 commit comments

Comments
 (0)