react-native-fast-image 8.6.7 → 8.6.8

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.
@@ -50,6 +50,13 @@ class FastImageViewConverter {
50
50
  put("center", ScaleType.CENTER_INSIDE);
51
51
  }};
52
52
 
53
+ // Whether the source has a uri to load (not null, missing or blank).
54
+ static boolean hasUri(@Nullable ReadableMap source) {
55
+ if (source == null || !source.hasKey("uri") || source.isNull("uri")) return false;
56
+ String uri = source.getString("uri");
57
+ return uri != null && !uri.trim().isEmpty();
58
+ }
59
+
53
60
  // Resolve the source uri to a file path that android understands.
54
61
  static @Nullable
55
62
  FastImageSource getImageSource(Context context, @Nullable ReadableMap source) {
@@ -79,7 +86,7 @@ class FastImageViewConverter {
79
86
  return headers;
80
87
  }
81
88
 
82
- static RequestOptions getOptions(Context context, FastImageSource imageSource, ReadableMap source) {
89
+ static RequestOptions getOptions(Context context, @Nullable FastImageSource imageSource, @Nullable ReadableMap source) {
83
90
  // Get priority.
84
91
  final Priority priority = FastImageViewConverter.getPriority(source);
85
92
  // Get cache control method.
@@ -108,7 +115,8 @@ class FastImageViewConverter {
108
115
  .priority(priority)
109
116
  .placeholder(TRANSPARENT_DRAWABLE);
110
117
 
111
- if (imageSource.isResource()) {
118
+ // imageSource is null when only a defaultSource is shown.
119
+ if (imageSource != null && imageSource.isResource()) {
112
120
  // Every local resource (drawable) in Android has its own unique numeric id, which are
113
121
  // generated at build time. Although these ids are unique, they are not guaranteed unique
114
122
  // across builds. The underlying glide implementation caches these resources. To make
@@ -37,6 +37,8 @@ class FastImageViewModule extends ReactContextBaseJavaModule {
37
37
  public void run() {
38
38
  for (int i = 0; i < sources.size(); i++) {
39
39
  final ReadableMap source = sources.getMap(i);
40
+ // Skip sources without a uri (Glide throws on an empty url).
41
+ if (!FastImageViewConverter.hasUri(source)) continue;
40
42
  final FastImageSource imageSource = FastImageViewConverter.getImageSource(activity, source);
41
43
 
42
44
  Glide
@@ -47,10 +47,6 @@ class FastImageViewWithUrl extends AppCompatImageView {
47
47
  mDefaultSource = source;
48
48
  }
49
49
 
50
- private boolean isNullOrEmpty(final String url) {
51
- return url == null || url.trim().isEmpty();
52
- }
53
-
54
50
  @SuppressLint("CheckResult")
55
51
  public void onAfterUpdate(
56
52
  @Nonnull FastImageViewManager manager,
@@ -59,10 +55,7 @@ class FastImageViewWithUrl extends AppCompatImageView {
59
55
  if (!mNeedsReload)
60
56
  return;
61
57
 
62
- if ((mSource == null ||
63
- !mSource.hasKey("uri") ||
64
- isNullOrEmpty(mSource.getString("uri"))) &&
65
- mDefaultSource == null) {
58
+ if (!FastImageViewConverter.hasUri(mSource) && mDefaultSource == null) {
66
59
 
67
60
  // Cancel existing requests.
68
61
  clearView(requestManager);
@@ -27,10 +27,15 @@ RCT_EXPORT_METHOD(preload:(nonnull NSArray<FFFastImageSource *> *)sources)
27
27
  NSMutableArray *urls = [NSMutableArray arrayWithCapacity:sources.count];
28
28
 
29
29
  [sources enumerateObjectsUsingBlock:^(FFFastImageSource * _Nonnull source, NSUInteger idx, BOOL * _Nonnull stop) {
30
+ // Skip sources without a url (an empty, missing or null uri). NSArray can't
31
+ // hold nil, so adding one throws and crashes the app.
32
+ if (!source.url) {
33
+ return;
34
+ }
30
35
  [source.headers enumerateKeysAndObjectsUsingBlock:^(NSString *key, NSString* header, BOOL *stop) {
31
36
  [[SDWebImageDownloader sharedDownloader] setValue:header forHTTPHeaderField:key];
32
37
  }];
33
- [urls setObject:source.url atIndexedSubscript:idx];
38
+ [urls addObject:source.url];
34
39
  }];
35
40
 
36
41
  [[SDWebImagePrefetcher sharedImagePrefetcher] prefetchURLs:urls];
@@ -16,7 +16,8 @@ RCT_ENUM_CONVERTER(FFFCacheControl, (@{
16
16
  }), FFFCacheControlImmutable, integerValue);
17
17
 
18
18
  + (FFFastImageSource *)FFFastImageSource:(id)json {
19
- if (!json) {
19
+ // A null source (e.g. a null entry passed to preload).
20
+ if (!json || json == (id)kCFNull) {
20
21
  return nil;
21
22
  }
22
23
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-fast-image",
3
- "version": "8.6.7",
3
+ "version": "8.6.8",
4
4
  "description": "🚩 FastImage, performant React Native image component.",
5
5
  "keywords": [
6
6
  "cache",
@@ -68,6 +68,7 @@
68
68
  "@types/react-test-renderer": "^17.0.1",
69
69
  "dv-scripts": "^1.6.0",
70
70
  "eslint-config-dv-scripts": "^1.1.1",
71
+ "maestro-runner": "1.1.27",
71
72
  "metro-react-native-babel-preset": "^0.66.1",
72
73
  "prettier": "^2.3.2",
73
74
  "react": "17.0.2",