react-native-fast-image 8.6.39 → 8.6.41

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.
@@ -16,6 +16,9 @@ Pod::Spec.new do |s|
16
16
  s.source_files = "ios/**/*.{h,m}"
17
17
 
18
18
  s.dependency 'React-Core'
19
- s.dependency 'SDWebImage', '~> 5.11.1'
20
- s.dependency 'SDWebImageWebPCoder', '~> 0.8.4'
19
+ # Any 5.x from 5.11.1, so apps can use newer versions (and share them with
20
+ # other libraries) without having to update. 5.18.7+ has the privacy
21
+ # manifest Apple requires.
22
+ s.dependency 'SDWebImage', '>= 5.11.1', '< 6.0'
23
+ s.dependency 'SDWebImageWebPCoder', '>= 0.8.4', '< 1.0'
21
24
  end
@@ -0,0 +1,84 @@
1
+ package com.dylanvann.fastimage;
2
+
3
+ import android.content.Context;
4
+ import android.os.Build;
5
+ import android.text.TextUtils;
6
+ import android.webkit.CookieManager;
7
+ import android.webkit.CookieSyncManager;
8
+
9
+ import androidx.annotation.Nullable;
10
+
11
+ import java.net.CookieHandler;
12
+ import java.net.URI;
13
+ import java.util.Collections;
14
+ import java.util.List;
15
+ import java.util.Map;
16
+
17
+ // Reads and stores cookies in Android's cookie store (the WebView's
18
+ // CookieManager), which React Native's networking (fetch) and its Image
19
+ // component use. Image requests then send the cookies the app's other requests
20
+ // got, as on iOS. Does what React Native's ForwardingCookieHandler does,
21
+ // without the ReactContext that one needs (up to at least 0.77). Used through
22
+ // OkHttp's JavaNetCookieJar, which parses the cookies.
23
+ final class FastImageCookieHandler extends CookieHandler {
24
+ private final Context context;
25
+ @Nullable
26
+ private CookieManager cookieManager;
27
+
28
+ FastImageCookieHandler(Context context) {
29
+ this.context = context.getApplicationContext();
30
+ }
31
+
32
+ @Override
33
+ public Map<String, List<String>> get(URI uri, Map<String, List<String>> requestHeaders) {
34
+ CookieManager cookieManager = cookieManager();
35
+ if (cookieManager == null) return Collections.emptyMap();
36
+ String cookies = cookieManager.getCookie(uri.toString());
37
+ if (TextUtils.isEmpty(cookies)) return Collections.emptyMap();
38
+ return Collections.singletonMap("Cookie", Collections.singletonList(cookies));
39
+ }
40
+
41
+ @Override
42
+ public void put(URI uri, Map<String, List<String>> responseHeaders) {
43
+ CookieManager cookieManager = cookieManager();
44
+ if (cookieManager == null) return;
45
+ String url = uri.toString();
46
+ boolean added = false;
47
+ for (Map.Entry<String, List<String>> header : responseHeaders.entrySet()) {
48
+ String name = header.getKey();
49
+ if (!"Set-Cookie".equalsIgnoreCase(name) && !"Set-Cookie2".equalsIgnoreCase(name)) continue;
50
+ for (String cookie : header.getValue()) {
51
+ cookieManager.setCookie(url, cookie);
52
+ added = true;
53
+ }
54
+ }
55
+ if (added) flush(cookieManager);
56
+ }
57
+
58
+ @SuppressWarnings("deprecation")
59
+ private static void flush(CookieManager cookieManager) {
60
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
61
+ cookieManager.flush();
62
+ } else {
63
+ CookieSyncManager.getInstance().sync();
64
+ }
65
+ }
66
+
67
+ // null while the WebView isn't available (not installed, or being
68
+ // updated): requests go without cookies then, instead of failing.
69
+ @Nullable
70
+ @SuppressWarnings("deprecation")
71
+ private synchronized CookieManager cookieManager() {
72
+ if (cookieManager == null) {
73
+ try {
74
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
75
+ CookieSyncManager.createInstance(context);
76
+ }
77
+ cookieManager = CookieManager.getInstance();
78
+ } catch (Exception e) {
79
+ return null;
80
+ }
81
+ }
82
+ return cookieManager;
83
+ }
84
+ }
@@ -13,6 +13,7 @@ import com.bumptech.glide.load.model.ModelLoader;
13
13
  import com.bumptech.glide.load.model.ModelLoaderFactory;
14
14
  import com.bumptech.glide.load.model.MultiModelLoaderFactory;
15
15
  import com.bumptech.glide.module.LibraryGlideModule;
16
+ import com.facebook.react.modules.network.CookieJarContainer;
16
17
  import com.facebook.react.modules.network.OkHttpClientProvider;
17
18
 
18
19
  import java.io.File;
@@ -24,6 +25,7 @@ import java.util.WeakHashMap;
24
25
 
25
26
  import okhttp3.Cache;
26
27
  import okhttp3.Interceptor;
28
+ import okhttp3.JavaNetCookieJar;
27
29
  import okhttp3.MediaType;
28
30
  import okhttp3.OkHttpClient;
29
31
  import okhttp3.Request;
@@ -47,11 +49,18 @@ public class FastImageOkHttpProgressGlideModule extends LibraryGlideModule {
47
49
  @NonNull Glide glide,
48
50
  @NonNull Registry registry
49
51
  ) {
50
- OkHttpClient client = OkHttpClientProvider
51
- .getOkHttpClient()
52
+ OkHttpClient sharedClient = OkHttpClientProvider.getOkHttpClient();
53
+ OkHttpClient.Builder builder = sharedClient
52
54
  .newBuilder()
53
- .addInterceptor(createInterceptor(progressListener))
54
- .build();
55
+ .addInterceptor(createInterceptor(progressListener));
56
+ // React Native's shared client comes with an empty cookie jar (React
57
+ // Native only fills it in for its networking and Image clients), so
58
+ // images were loaded without the app's cookies, unlike on iOS. Use the
59
+ // same cookie store. A cookie jar the app set up itself is kept.
60
+ if (sharedClient.cookieJar() instanceof CookieJarContainer) {
61
+ builder.cookieJar(new JavaNetCookieJar(new FastImageCookieHandler(context)));
62
+ }
63
+ OkHttpClient client = builder.build();
55
64
  OkHttpUrlLoader.Factory factory = new OkHttpUrlLoader.Factory(client);
56
65
  registry.replace(GlideUrl.class, InputStream.class, factory);
57
66
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-fast-image",
3
- "version": "8.6.39",
3
+ "version": "8.6.41",
4
4
  "description": "🚩 FastImage, performant React Native image component.",
5
5
  "keywords": [
6
6
  "cache",