Skip to content

Commit d72a2fd

Browse files
committed
fix(ios): color theming fix
1 parent 7bc0953 commit d72a2fd

File tree

1 file changed

+33
-14
lines changed

1 file changed

+33
-14
lines changed

src/core/index.ios.ts

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,16 @@ function cornerTreatment(cornerFamily: CornerFamily, cornerSize: number | CoreTy
5252
}
5353
return corner;
5454
}
55+
56+
function getIOSColor(value: string | Color) {
57+
return (value instanceof Color ? value : new Color(value)).ios;
58+
}
5559
export class Themer {
5660
appColorScheme: MDCSemanticColorScheme;
5761
appTypoScheme: MDCTypographyScheme;
5862
primaryColor: string | Color;
63+
backgroundColor: string | Color;
64+
onBackgroundColor: string | Color;
5965
onPrimaryColor: string | Color;
6066
secondaryColor: string | Color;
6167
accentColor: string | Color;
@@ -81,8 +87,7 @@ export class Themer {
8187
setPrimaryColor(value: string | Color) {
8288
this.primaryColor = value;
8389
const colorTheme = this.getOrcreateAppColorScheme();
84-
const color = value instanceof Color ? value : new Color(value);
85-
colorTheme.primaryColor = color.ios;
90+
colorTheme.primaryColor = getIOSColor(value);
8691
this.appColorScheme.primaryColorVariant = this.appColorScheme.primaryColor.colorWithAlphaComponent(0.24);
8792
}
8893
getPrimaryColor(): string | Color {
@@ -92,17 +97,15 @@ export class Themer {
9297
setOnPrimaryColor(value) {
9398
this.onPrimaryColor = value;
9499
const colorTheme = this.getOrcreateAppColorScheme();
95-
const color = value instanceof Color ? value : new Color(value);
96-
colorTheme.onPrimaryColor = color.ios;
100+
colorTheme.onPrimaryColor = getIOSColor(value);
97101
}
98102
getOnPrimaryColor() {
99103
return this.onPrimaryColor;
100104
}
101105
setSecondaryColor(value: string | Color) {
102106
this.secondaryColor = value;
103107
const colorTheme = this.getOrcreateAppColorScheme();
104-
const color = value instanceof Color ? value : new Color(value);
105-
colorTheme.secondaryColor = color.ios;
108+
colorTheme.secondaryColor = getIOSColor(value);
106109
}
107110
getSecondaryColor(): string | Color {
108111
return this.secondaryColor;
@@ -118,31 +121,46 @@ export class Themer {
118121
setSurfaceColor(value: string | Color) {
119122
this.surfaceColor = value;
120123
const colorTheme = this.getOrcreateAppColorScheme();
121-
const color = value instanceof Color ? value : new Color(value);
122-
colorTheme.surfaceColor = color.ios;
123-
colorTheme.onSurfaceColor = color.ios;
124+
const color = getIOSColor(value);
125+
colorTheme.surfaceColor = color;
126+
colorTheme.onSurfaceColor = color;
124127
}
125128
getSurfaceColor(): string | Color {
126129
return this.surfaceColor;
127130
}
128131
setOnSurfaceColor(value: string | Color) {
129132
this.onSurfaceColor = value;
130133
const colorTheme = this.getOrcreateAppColorScheme();
131-
const color = value instanceof Color ? value : new Color(value);
132-
colorTheme.onSurfaceColor = color.ios;
134+
colorTheme.onSurfaceColor = getIOSColor(value);
133135
}
134136
getOnSurfaceColor(): string | Color {
135137
return this.onSurfaceColor;
136138
}
137139
setPrimaryColorVariant(value: string | Color) {
138140
this.primaryColorVariant = value;
139-
const color = value instanceof Color ? value : new Color(value);
140-
this.getOrcreateAppColorScheme().primaryColorVariant = color.ios;
141+
this.getOrcreateAppColorScheme().primaryColorVariant = getIOSColor(value);
141142
}
142143
getPrimaryColorVariant(): string | Color {
143144
return this.primaryColorVariant;
144145
}
145146

147+
setBackgroundColor(value: string | Color) {
148+
this.backgroundColor = value;
149+
const colorTheme = this.getOrcreateAppColorScheme();
150+
colorTheme.backgroundColor = getIOSColor(value);
151+
}
152+
getBackgroundColor(): string | Color {
153+
return this.backgroundColor;
154+
}
155+
setOnBackgroundColor(value: string | Color) {
156+
this.onBackgroundColor = value;
157+
const colorTheme = this.getOrcreateAppColorScheme();
158+
colorTheme.onBackgroundColor = getIOSColor(value);
159+
}
160+
getOnBackgroundColor(): string | Color {
161+
return this.onBackgroundColor;
162+
}
163+
146164
getOrcreateAppTypographyScheme() {
147165
if (!this.appTypoScheme) {
148166
this.appTypoScheme = MDCTypographyScheme.new();
@@ -207,7 +225,8 @@ export function getRippleColor(color: string | Color, alpha = 61.5): UIColor {
207225
if (temp.a !== 255) {
208226
return temp.ios;
209227
}
210-
return temp.setAlpha(alpha).ios;
228+
// TODO: we cant use setAlpha until it is fixed in Nativescript or ios will be undefined
229+
return new Color(alpha || 61.5, temp.r, temp.g, temp.b).ios;
211230
}
212231
return null;
213232
}

0 commit comments

Comments
 (0)