@@ -52,10 +52,16 @@ function cornerTreatment(cornerFamily: CornerFamily, cornerSize: number | CoreTy
52
52
}
53
53
return corner ;
54
54
}
55
+
56
+ function getIOSColor ( value : string | Color ) {
57
+ return ( value instanceof Color ? value : new Color ( value ) ) . ios ;
58
+ }
55
59
export class Themer {
56
60
appColorScheme : MDCSemanticColorScheme ;
57
61
appTypoScheme : MDCTypographyScheme ;
58
62
primaryColor : string | Color ;
63
+ backgroundColor : string | Color ;
64
+ onBackgroundColor : string | Color ;
59
65
onPrimaryColor : string | Color ;
60
66
secondaryColor : string | Color ;
61
67
accentColor : string | Color ;
@@ -81,8 +87,7 @@ export class Themer {
81
87
setPrimaryColor ( value : string | Color ) {
82
88
this . primaryColor = value ;
83
89
const colorTheme = this . getOrcreateAppColorScheme ( ) ;
84
- const color = value instanceof Color ? value : new Color ( value ) ;
85
- colorTheme . primaryColor = color . ios ;
90
+ colorTheme . primaryColor = getIOSColor ( value ) ;
86
91
this . appColorScheme . primaryColorVariant = this . appColorScheme . primaryColor . colorWithAlphaComponent ( 0.24 ) ;
87
92
}
88
93
getPrimaryColor ( ) : string | Color {
@@ -92,17 +97,15 @@ export class Themer {
92
97
setOnPrimaryColor ( value ) {
93
98
this . onPrimaryColor = value ;
94
99
const colorTheme = this . getOrcreateAppColorScheme ( ) ;
95
- const color = value instanceof Color ? value : new Color ( value ) ;
96
- colorTheme . onPrimaryColor = color . ios ;
100
+ colorTheme . onPrimaryColor = getIOSColor ( value ) ;
97
101
}
98
102
getOnPrimaryColor ( ) {
99
103
return this . onPrimaryColor ;
100
104
}
101
105
setSecondaryColor ( value : string | Color ) {
102
106
this . secondaryColor = value ;
103
107
const colorTheme = this . getOrcreateAppColorScheme ( ) ;
104
- const color = value instanceof Color ? value : new Color ( value ) ;
105
- colorTheme . secondaryColor = color . ios ;
108
+ colorTheme . secondaryColor = getIOSColor ( value ) ;
106
109
}
107
110
getSecondaryColor ( ) : string | Color {
108
111
return this . secondaryColor ;
@@ -118,31 +121,46 @@ export class Themer {
118
121
setSurfaceColor ( value : string | Color ) {
119
122
this . surfaceColor = value ;
120
123
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 ;
124
127
}
125
128
getSurfaceColor ( ) : string | Color {
126
129
return this . surfaceColor ;
127
130
}
128
131
setOnSurfaceColor ( value : string | Color ) {
129
132
this . onSurfaceColor = value ;
130
133
const colorTheme = this . getOrcreateAppColorScheme ( ) ;
131
- const color = value instanceof Color ? value : new Color ( value ) ;
132
- colorTheme . onSurfaceColor = color . ios ;
134
+ colorTheme . onSurfaceColor = getIOSColor ( value ) ;
133
135
}
134
136
getOnSurfaceColor ( ) : string | Color {
135
137
return this . onSurfaceColor ;
136
138
}
137
139
setPrimaryColorVariant ( value : string | Color ) {
138
140
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 ) ;
141
142
}
142
143
getPrimaryColorVariant ( ) : string | Color {
143
144
return this . primaryColorVariant ;
144
145
}
145
146
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
+
146
164
getOrcreateAppTypographyScheme ( ) {
147
165
if ( ! this . appTypoScheme ) {
148
166
this . appTypoScheme = MDCTypographyScheme . new ( ) ;
@@ -207,7 +225,8 @@ export function getRippleColor(color: string | Color, alpha = 61.5): UIColor {
207
225
if ( temp . a !== 255 ) {
208
226
return temp . ios ;
209
227
}
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 ;
211
230
}
212
231
return null ;
213
232
}
0 commit comments