react-native-fast-image 8.6.25 → 8.6.27

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.
@@ -86,7 +86,7 @@ class FastImageViewManager extends SimpleViewManager<FastImageViewWithUrl> imple
86
86
  @ReactProp(name = "resizeMode")
87
87
  public void setResizeMode(FastImageViewWithUrl view, String resizeMode) {
88
88
  final FastImageViewWithUrl.ScaleType scaleType = FastImageViewConverter.getScaleType(resizeMode);
89
- view.setScaleType(scaleType);
89
+ view.setResizeMode(scaleType);
90
90
  }
91
91
 
92
92
  @Override
@@ -94,15 +94,9 @@ class FastImageViewManager extends SimpleViewManager<FastImageViewWithUrl> imple
94
94
  // This will cancel existing requests.
95
95
  view.clearView(requestManager);
96
96
 
97
- if (view.glideUrl != null) {
98
- final String key = view.glideUrl.toString();
99
- FastImageOkHttpProgressGlideModule.forget(key);
100
- List<FastImageViewWithUrl> viewsForKey = VIEWS_FOR_URLS.get(key);
101
- if (viewsForKey != null) {
102
- viewsForKey.remove(view);
103
- if (viewsForKey.size() == 0) VIEWS_FOR_URLS.remove(key);
104
- }
105
- }
97
+ // Same key as when the view was tracked (toStringUrl, not toString,
98
+ // which differ for urls that need escaping).
99
+ view.untrackUrl(VIEWS_FOR_URLS);
106
100
 
107
101
  super.onDropViewInstance(view);
108
102
  }
@@ -48,6 +48,14 @@ class FastImageViewWithUrl extends AppCompatImageView {
48
48
  mDefaultSource = source;
49
49
  }
50
50
 
51
+ // Glide crops or fits the bitmap for the scale type when it loads, so a
52
+ // new resizeMode needs a reload to take effect (#762).
53
+ public void setResizeMode(ScaleType scaleType) {
54
+ if (scaleType == getScaleType()) return;
55
+ setScaleType(scaleType);
56
+ mNeedsReload = true;
57
+ }
58
+
51
59
  @SuppressLint("CheckResult")
52
60
  public void onAfterUpdate(
53
61
  @Nonnull FastImageViewManager manager,
@@ -55,15 +63,16 @@ class FastImageViewWithUrl extends AppCompatImageView {
55
63
  @Nonnull Map<String, List<FastImageViewWithUrl>> viewsForUrlsMap) {
56
64
  if (!mNeedsReload)
57
65
  return;
66
+ // Only reload for changes that affect the request (source,
67
+ // defaultSource, resizeMode), not for every prop update.
68
+ mNeedsReload = false;
58
69
 
59
70
  // Nothing to show.
60
71
  if (mSource == null && mDefaultSource == null) {
61
72
  // Cancel existing requests.
62
73
  clearView(requestManager);
63
74
 
64
- if (glideUrl != null) {
65
- FastImageOkHttpProgressGlideModule.forget(glideUrl.toStringUrl());
66
- }
75
+ untrackUrl(viewsForUrlsMap);
67
76
 
68
77
  // Clear the image.
69
78
  setImageDrawable(null);
@@ -92,9 +101,7 @@ class FastImageViewWithUrl extends AppCompatImageView {
92
101
  // Cancel existing requests.
93
102
  clearView(requestManager);
94
103
 
95
- if (glideUrl != null) {
96
- FastImageOkHttpProgressGlideModule.forget(glideUrl.toStringUrl());
97
- }
104
+ untrackUrl(viewsForUrlsMap);
98
105
  setImageDrawable(mDefaultSource);
99
106
  return;
100
107
  }
@@ -102,12 +109,17 @@ class FastImageViewWithUrl extends AppCompatImageView {
102
109
  // `imageSource` may be null and we still continue, if `defaultSource` is not null
103
110
  final GlideUrl glideUrl = imageSource == null ? null : imageSource.getGlideUrl();
104
111
 
112
+ String key = glideUrl == null ? null : glideUrl.toStringUrl();
113
+
114
+ // Loading a different url: stop tracking the old one.
115
+ if (this.glideUrl != null && !this.glideUrl.toStringUrl().equals(key)) {
116
+ untrackUrl(viewsForUrlsMap);
117
+ }
118
+
105
119
  // Cancel existing request.
106
120
  this.glideUrl = glideUrl;
107
121
  clearView(requestManager);
108
122
 
109
- String key = glideUrl == null ? null : glideUrl.toStringUrl();
110
-
111
123
  if (glideUrl != null) {
112
124
  FastImageOkHttpProgressGlideModule.expect(key, manager);
113
125
  List<FastImageViewWithUrl> viewsForKey = viewsForUrlsMap.get(key);
@@ -152,6 +164,24 @@ class FastImageViewWithUrl extends AppCompatImageView {
152
164
  }
153
165
  }
154
166
 
167
+ // Removes this view from the list of views for its current url (used to send
168
+ // progress events), which otherwise kept it, and its Activity, alive after
169
+ // its source changed (#384). The url's progress listener is only forgotten
170
+ // when no other view uses it.
171
+ void untrackUrl(@Nonnull Map<String, List<FastImageViewWithUrl>> viewsForUrlsMap) {
172
+ if (glideUrl == null) return;
173
+ String key = glideUrl.toStringUrl();
174
+ List<FastImageViewWithUrl> viewsForKey = viewsForUrlsMap.get(key);
175
+ if (viewsForKey != null) {
176
+ viewsForKey.remove(this);
177
+ if (viewsForKey.isEmpty()) viewsForUrlsMap.remove(key);
178
+ }
179
+ if (viewsForKey == null || viewsForKey.isEmpty()) {
180
+ FastImageOkHttpProgressGlideModule.forget(key);
181
+ }
182
+ glideUrl = null;
183
+ }
184
+
155
185
  public void clearView(@Nullable RequestManager requestManager) {
156
186
  if (requestManager != null && getTag() != null && getTag() instanceof Request) {
157
187
  requestManager.clear(this);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-fast-image",
3
- "version": "8.6.25",
3
+ "version": "8.6.27",
4
4
  "description": "🚩 FastImage, performant React Native image component.",
5
5
  "keywords": [
6
6
  "cache",