|
| 1 | +import { Color } from '../../../../color'; |
1 | 2 | import { Trace } from '../../../../trace'; |
2 | 3 | import { SDK_VERSION } from '../../../../utils/constants'; |
3 | 4 |
|
4 | 5 | export * from './view-helper-common'; |
| 6 | +export const IOSHelper = 0; |
5 | 7 |
|
6 | 8 | const androidxGraphics = androidx.core.graphics; |
7 | 9 |
|
8 | 10 | export class AndroidHelper { |
| 11 | + static getDrawableColor(drawable: android.graphics.drawable.Drawable): Color { |
| 12 | + if (!drawable) { |
| 13 | + return null; |
| 14 | + } |
| 15 | + |
| 16 | + let color: number; |
| 17 | + |
| 18 | + if (drawable instanceof org.nativescript.widgets.BorderDrawable) { |
| 19 | + color = drawable.getBackgroundColor(); |
| 20 | + } else if (drawable instanceof android.graphics.drawable.ColorDrawable) { |
| 21 | + color = drawable.getColor(); |
| 22 | + } else { |
| 23 | + // This is a way to retrieve drawable color when set using color filter |
| 24 | + color = (drawable as any)._backgroundColor; |
| 25 | + } |
| 26 | + |
| 27 | + return new Color(color); |
| 28 | + } |
| 29 | + |
9 | 30 | static setDrawableColor(color: number, drawable: android.graphics.drawable.Drawable, blendMode?: androidx.core.graphics.BlendModeCompat): void { |
10 | | - // ColorDrawable is an old layer that had support for setColorFilter on API 21 |
| 31 | + // ColorDrawable is an older class that had support for setColorFilter on API 21 |
11 | 32 | if (SDK_VERSION < 21 && drawable instanceof android.graphics.drawable.ColorDrawable) { |
12 | 33 | drawable.setColor(color); |
13 | 34 | } else { |
14 | 35 | drawable.setColorFilter(androidxGraphics.BlendModeColorFilterCompat.createBlendModeColorFilterCompat(color, blendMode ?? androidxGraphics.BlendModeCompat.SRC_IN)); |
| 36 | + |
| 37 | + // This is a way to retrieve drawable color when set using color filter |
| 38 | + (drawable as any)._backgroundColor = color; |
15 | 39 | } |
16 | 40 | } |
17 | 41 |
|
18 | 42 | static clearDrawableColor(drawable: android.graphics.drawable.Drawable): void { |
19 | | - // ColorDrawable is an old layer that had support for setColorFilter on API 21 |
| 43 | + // ColorDrawable is an older class that had support for setColorFilter on API 21 |
20 | 44 | if (SDK_VERSION < 21 && drawable instanceof android.graphics.drawable.ColorDrawable) { |
21 | 45 | drawable.setColor(-1); |
22 | 46 | } else { |
23 | 47 | drawable.clearColorFilter(); |
| 48 | + |
| 49 | + // This is a way to retrieve drawable color when set using color filter |
| 50 | + delete (drawable as any)._backgroundColor; |
24 | 51 | } |
25 | 52 | } |
26 | 53 |
|
|
0 commit comments