1 package expo.modules.blur
2 
3 import expo.modules.kotlin.types.Enumerable
4 
5 enum class TintStyle(val value: String) : Enumerable {
6   DEFAULT("default"),
7   EXTRA_LIGHT("extraLight"),
8   LIGHT("light"),
9   DARK("dark"),
10   REGULAR("regular"),
11   PROMINENT("prominent"),
12   SYSTEM_ULTRA_THIN_MATERIAL("systemUltraThinMaterial"),
13   SYSTEM_THIN_MATERIAL("systemThinMaterial"),
14   SYSTEM_MATERIAL("systemMaterial"),
15   SYSTEM_THICK_MATERIAL("systemThickMaterial"),
16   SYSTEM_CHROME_MATERIAL("systemChromeMaterial"),
17   SYSTEM_ULTRA_THIN_MATERIAL_LIGHT("systemUltraThinMaterialLight"),
18   SYSTEM_THICK_MATERIAL_LIGHT("systemThickMaterialLight"),
19   SYSTEM_THIN_MATERIAL_LIGHT("systemThinMaterialLight"),
20   SYSTEM_MATERIAL_LIGHT("systemMaterialLight"),
21   SYSTEM_CHROME_MATERIAL_LIGHT("systemChromeMaterialLight"),
22   SYSTEM_ULTRA_THIN_MATERIAL_DARK("systemUltraThinMaterialDark"),
23   SYSTEM_THIN_MATERIAL_DARK("systemThinMaterialDark"),
24   SYSTEM_MATERIAL_DARK("systemMaterialDark"),
25   SYSTEM_THICK_MATERIAL_DARK("systemThickMaterialDark"),
26   SYSTEM_CHROME_MATERIAL_DARK("systemChromeMaterialDark");
27 
toBlurEffectnull28   fun toBlurEffect(blurRadius: Float): Int {
29     return when (this) {
30       EXTRA_LIGHT,
31       LIGHT,
32       SYSTEM_MATERIAL_LIGHT,
33       SYSTEM_ULTRA_THIN_MATERIAL_LIGHT,
34       SYSTEM_THICK_MATERIAL_LIGHT -> LIGHT.toColorInt(blurRadius)
35 
36       PROMINENT,
37       DEFAULT,
38       SYSTEM_MATERIAL,
39       -> DEFAULT.toColorInt(blurRadius)
40 
41       DARK,
42       SYSTEM_MATERIAL_DARK -> DARK.toColorInt(blurRadius)
43 
44       REGULAR,
45       SYSTEM_ULTRA_THIN_MATERIAL,
46       SYSTEM_THICK_MATERIAL,
47       SYSTEM_CHROME_MATERIAL,
48       SYSTEM_CHROME_MATERIAL_LIGHT,
49       SYSTEM_THICK_MATERIAL_DARK,
50       SYSTEM_THIN_MATERIAL_LIGHT,
51       SYSTEM_THIN_MATERIAL_DARK,
52       SYSTEM_ULTRA_THIN_MATERIAL_DARK,
53       SYSTEM_CHROME_MATERIAL_DARK,
54       SYSTEM_THIN_MATERIAL -> this.toColorInt(blurRadius)
55     }
56   }
57 
toColorIntnull58   private fun toColorInt(blurRadius: Float): Int {
59     val intensity = blurRadius / 100
60     return when (this) {
61       // Color int represented by: a >> 24 + r >> 16 + g >> 8 + b
62       DARK -> ((255 * intensity * 0.69).toInt() shl 24) + (25 shl 16) + (25 shl 8) + 25
63       // From Apple iOS 14 Sketch Kit - https://developer.apple.com/design/resources/
64       LIGHT -> ((255 * intensity * 0.78).toInt() shl 24) + (249 shl 16) + (249 shl 8) + 249
65       REGULAR -> ((255 * intensity * 0.82).toInt() shl 24) + (179 shl 16) + (179 shl 8) + 179
66       SYSTEM_THIN_MATERIAL_LIGHT -> ((255 * intensity * 0.78).toInt() shl 24) + (199 shl 16) + (199 shl 8) + 199
67       SYSTEM_THIN_MATERIAL -> ((255 * intensity * 0.97).toInt() shl 24) + (199 shl 16) + (199 shl 8) + 199
68       SYSTEM_CHROME_MATERIAL -> ((255 * intensity * 0.75).toInt() shl 24) + (255 shl 16) + (255 shl 8) + 255
69       SYSTEM_CHROME_MATERIAL_LIGHT -> ((255 * intensity * 0.97).toInt() shl 24) + (255 shl 16) + (255 shl 8) + 255
70       SYSTEM_ULTRA_THIN_MATERIAL -> ((255 * intensity * 0.44).toInt() shl 24) + (191 shl 16) + (191 shl 8) + 191
71       SYSTEM_THICK_MATERIAL -> ((255 * intensity * 0.97).toInt() shl 24) + (153 shl 16) + (153 shl 8) + 153
72       SYSTEM_THICK_MATERIAL_DARK -> ((255 * intensity * 0.9).toInt() shl 24) + (37 shl 16) + (37 shl 8) + 37
73       SYSTEM_THIN_MATERIAL_DARK -> ((255 * intensity * 0.7).toInt() shl 24) + (37 shl 16) + (37 shl 8) + 37
74       SYSTEM_ULTRA_THIN_MATERIAL_DARK -> ((255 * intensity * 0.55).toInt() shl 24) + (37 shl 16) + (37 shl 8) + 37
75       SYSTEM_CHROME_MATERIAL_DARK -> ((255 * intensity * 0.75).toInt() shl 24) + (0 shl 16) + (0 shl 8) + 0
76       else -> ((255 * intensity * 0.44).toInt() shl 24) + (255 shl 16) + (255 shl 8) + 255
77     }
78   }
79 }
80