Skip to content

Update color presets when scheme changes #1309

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions generatedTypes/style/colors.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,14 @@ declare const colorObject: Colors & {
purple20: string;
purple30: string;
purple40: string;
/**
* Add alpha to hex or rgb color
* arguments:
* p1 - hex color / R part of RGB
* p2 - opacity / G part of RGB
* p3 - B part of RGB
* p4 - opacity
*/
purple50: string;
purple60: string;
purple70: string;
Expand Down
7 changes: 7 additions & 0 deletions src/style/colors.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {Appearance} from 'react-native';
import _ from 'lodash';
//@ts-ignore
import Color from 'color';
Expand All @@ -15,6 +16,10 @@ export class Colors {
constructor() {
const colors = Object.assign(colorsPalette, themeColors);
Object.assign(this, colors);

Appearance.addChangeListener(({colorScheme}: Appearance.AppearancePreferences) => {
Object.assign(this, this.schemes[colorScheme ?? 'light']);
});
}
/**
* Load custom set of colors
Expand All @@ -41,6 +46,8 @@ export class Colors {
}

this.schemes = schemes;
const colorScheme = Appearance.getColorScheme();
Object.assign(this, this.schemes[colorScheme ?? 'light']);
}

/**
Expand Down