expo-image 1.10.1 → 1.10.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -10,6 +10,23 @@
10
10
 
11
11
  ### 💡 Others
12
12
 
13
+ ## 1.10.3 — 2024-01-12
14
+
15
+ _This version does not introduce any user-facing changes._
16
+
17
+ ## 1.10.2 — 2024-01-10
18
+
19
+ ### 🐛 Bug fixes
20
+
21
+ - [Android] Fixed the issue with the application of tint color when an element does not have a style assigned to it. ([#26251](https://github.com/expo/expo/pull/26251) by [@lukmccall](https://github.com/lukmccall))
22
+ - [Android] Fixed the tint color was applied to the mask element. ([#26323](https://github.com/expo/expo/pull/26323) by [@lukmccall](https://github.com/lukmccall))
23
+ - [Android] Fixed the tint color wasn't applied to the root element. ([#26339](https://github.com/expo/expo/pull/26339) by [@lukmccall](https://github.com/lukmccall))
24
+ - [Android] Fixed that the tint color on SVGs can't be changed dynamically. ([#26350](https://github.com/expo/expo/pull/26350) by [@lukmccall](https://github.com/lukmccall))
25
+
26
+ ### 💡 Others
27
+
28
+ - Replace deprecated `com.facebook.react:react-native:+` Android dependency with `com.facebook.react:react-android`. ([#26237](https://github.com/expo/expo/pull/26237) by [@kudo](https://github.com/kudo))
29
+
13
30
  ## 1.10.1 — 2023-12-19
14
31
 
15
32
  _This version does not introduce any user-facing changes._
@@ -67,7 +67,7 @@ android {
67
67
  namespace "expo.modules.image"
68
68
  defaultConfig {
69
69
  versionCode 1
70
- versionName "1.10.1"
70
+ versionName "1.10.3"
71
71
  consumerProguardFiles("proguard-rules.pro")
72
72
 
73
73
  buildConfigField("boolean", "ALLOW_GLIDE_LOGS", project.properties.get("EXPO_ALLOW_GLIDE_LOGS", "false"))
@@ -108,8 +108,7 @@ dependencies {
108
108
  implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${getKotlinVersion()}"
109
109
  }
110
110
 
111
- //noinspection GradleDynamicVersion
112
- implementation 'com.facebook.react:react-native:+' // From node_modules
111
+ implementation 'com.facebook.react:react-android'
113
112
 
114
113
  api "com.github.bumptech.glide:glide:${GLIDE_VERSION}"
115
114
  kapt "com.github.bumptech.glide:compiler:${GLIDE_VERSION}"
@@ -1,5 +1,9 @@
1
1
  package com.caverock.androidsvg
2
2
 
3
+ import com.caverock.androidsvg.SVG.SPECIFIED_COLOR
4
+ import com.caverock.androidsvg.SVG.SPECIFIED_FILL
5
+ import com.caverock.androidsvg.SVG.SvgElementBase
6
+
3
7
  internal fun replaceColor(paint: SVG.SvgPaint?, newColor: Int) {
4
8
  if (paint is SVG.Colour && paint !== SVG.Colour.TRANSPARENT) {
5
9
  paint.colour = newColor
@@ -19,15 +23,88 @@ internal fun replaceStyles(style: SVG.Style?, newColor: Int) {
19
23
  replaceColor(style.viewportFill, newColor)
20
24
  }
21
25
 
22
- internal fun applyTintColor(element: SVG.SvgObject, newColor: Int) {
23
- if (element is SVG.SvgElementBase) {
26
+ internal fun hasStyle(element: SvgElementBase): Boolean {
27
+ if (element.style == null && element.baseStyle == null) {
28
+ return false
29
+ }
30
+
31
+ val style = element.style
32
+ val hasColorInStyle = style != null &&
33
+ (
34
+ style.color != null || style.fill != null || style.stroke != null ||
35
+ style.stroke != null || style.stopColor != null || style.solidColor != null
36
+ )
37
+
38
+ if (hasColorInStyle) {
39
+ return true
40
+ }
41
+
42
+ val baseStyle = element.baseStyle ?: return false
43
+ return baseStyle.color != null || baseStyle.fill != null || baseStyle.stroke != null ||
44
+ baseStyle.viewportFill != null || baseStyle.stopColor != null || baseStyle.solidColor != null
45
+ }
46
+
47
+ internal fun defineStyles(element: SvgElementBase, newColor: Int, hasStyle: Boolean) {
48
+ if (hasStyle) {
49
+ return
50
+ }
51
+
52
+ val style = if (element.style != null) {
53
+ element.style
54
+ } else {
55
+ SVG.Style().also {
56
+ element.style = it
57
+ }
58
+ }
59
+
60
+ val color = SVG.Colour(newColor)
61
+ when (element) {
62
+ is SVG.Path,
63
+ is SVG.Circle,
64
+ is SVG.Ellipse,
65
+ is SVG.Rect,
66
+ is SVG.SolidColor,
67
+ is SVG.Line,
68
+ is SVG.Polygon,
69
+ is SVG.PolyLine -> {
70
+ style.apply {
71
+ fill = color
72
+
73
+ specifiedFlags = SPECIFIED_FILL
74
+ }
75
+ }
76
+
77
+ is SVG.TextPath -> {
78
+ style.apply {
79
+ this.color = color
80
+
81
+ specifiedFlags = SPECIFIED_COLOR
82
+ }
83
+ }
84
+ }
85
+ }
86
+
87
+ internal fun applyTintColor(element: SVG.SvgObject, newColor: Int, parentDefinesStyle: Boolean) {
88
+ // We want to keep the colors in the mask as they control the visibility of the element to which the mask is applied.
89
+ if (element is SVG.Mask) {
90
+ return
91
+ }
92
+
93
+ val definesStyle = if (element is SvgElementBase) {
94
+ val hasStyle = parentDefinesStyle || hasStyle(element)
95
+
24
96
  replaceStyles(element.baseStyle, newColor)
25
97
  replaceStyles(element.style, newColor)
98
+ defineStyles(element, newColor, hasStyle)
99
+
100
+ hasStyle
101
+ } else {
102
+ parentDefinesStyle
26
103
  }
27
104
 
28
105
  if (element is SVG.SvgContainer) {
29
106
  for (child in element.children) {
30
- applyTintColor(child, newColor)
107
+ applyTintColor(child, newColor, definesStyle)
31
108
  }
32
109
  }
33
110
  }
@@ -35,9 +112,14 @@ internal fun applyTintColor(element: SVG.SvgObject, newColor: Int) {
35
112
  fun applyTintColor(svg: SVG, newColor: Int) {
36
113
  val root = svg.rootElement
37
114
 
115
+ svg.cssRules?.forEach { rule ->
116
+ replaceStyles(rule.style, newColor)
117
+ }
118
+ replaceStyles(root.baseStyle, newColor)
38
119
  replaceStyles(root.style, newColor)
120
+ val hasStyle = hasStyle(root)
39
121
 
40
122
  for (child in root.children) {
41
- applyTintColor(child, newColor)
123
+ applyTintColor(child, newColor, hasStyle)
42
124
  }
43
125
  }
@@ -31,6 +31,7 @@ import expo.modules.image.records.ImageLoadEvent
31
31
  import expo.modules.image.records.ImageProgressEvent
32
32
  import expo.modules.image.records.ImageTransition
33
33
  import expo.modules.image.records.SourceMap
34
+ import expo.modules.image.svg.SVGPictureDrawable
34
35
  import expo.modules.kotlin.AppContext
35
36
  import expo.modules.kotlin.tracing.beginAsyncTraceBlock
36
37
  import expo.modules.kotlin.tracing.trace
@@ -127,7 +128,12 @@ class ExpoImageViewWrapper(context: Context, appContext: AppContext) : ExpoView(
127
128
  internal var tintColor: Int? = null
128
129
  set(value) {
129
130
  field = value
130
- activeView.setTintColor(value)
131
+ // To apply the tint color to the SVG, we need to recreate the drawable.
132
+ if (activeView.drawable is SVGPictureDrawable) {
133
+ shouldRerender = true
134
+ } else {
135
+ activeView.setTintColor(value)
136
+ }
131
137
  }
132
138
 
133
139
  internal var isFocusableProp: Boolean = false
@@ -1,5 +1,5 @@
1
1
  {
2
- "platforms": ["ios", "android"],
2
+ "platforms": ["ios", "android", "tvos"],
3
3
  "ios": {
4
4
  "modules": ["ImageModule"]
5
5
  },
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "expo-image",
3
3
  "title": "Expo Image",
4
- "version": "1.10.1",
4
+ "version": "1.10.3",
5
5
  "description": "A cross-platform, performant image component for React Native and Expo with Web support",
6
6
  "main": "build/index.js",
7
7
  "types": "build/index.d.ts",
@@ -35,5 +35,5 @@
35
35
  "peerDependencies": {
36
36
  "expo": "*"
37
37
  },
38
- "gitHead": "43f1b4f8a5a9bca649e4e7ca6e4155482a162431"
38
+ "gitHead": "f9100f83a5d971dbdef83336a8f055046566fa83"
39
39
  }