Bladeren bron

[RN] Make react-native-img-cache optional at bundle time

master
Lyubo Marinov 7 jaren geleden
bovenliggende
commit
2818520c8f

+ 29
- 18
react/features/base/participants/components/Avatar.native.js Bestand weergeven

74
         // uri
74
         // uri
75
         const prevURI = this.props && this.props.uri;
75
         const prevURI = this.props && this.props.uri;
76
         const nextURI = nextProps && nextProps.uri;
76
         const nextURI = nextProps && nextProps.uri;
77
+        const assignState = !this.state;
77
 
78
 
78
-        if (prevURI !== nextURI || !this.state) {
79
+        if (prevURI !== nextURI || assignState) {
79
             const nextState = {
80
             const nextState = {
80
                 backgroundColor: this._getBackgroundColor(nextProps),
81
                 backgroundColor: this._getBackgroundColor(nextProps),
81
 
82
 
92
                 source: _DEFAULT_SOURCE
93
                 source: _DEFAULT_SOURCE
93
             };
94
             };
94
 
95
 
95
-            if (this.state) {
96
-                this.setState(nextState);
97
-            } else {
96
+            if (assignState) {
98
                 this.state = nextState;
97
                 this.state = nextState;
98
+            } else {
99
+                this.setState(nextState);
99
             }
100
             }
100
 
101
 
101
             // XXX @lyubomir: My logic for the character # bellow is as follows:
102
             // XXX @lyubomir: My logic for the character # bellow is as follows:
113
             // an image retrieval action.
114
             // an image retrieval action.
114
             if (nextURI && !nextURI.startsWith('#')) {
115
             if (nextURI && !nextURI.startsWith('#')) {
115
                 const nextSource = { uri: nextURI };
116
                 const nextSource = { uri: nextURI };
117
+                const observer = () => {
118
+                    this._unmounted || this.setState((prevState, props) => {
119
+                        if (props.uri === nextURI
120
+                                && (!prevState.source
121
+                                    || prevState.source.uri !== nextURI)) {
122
+                            return { source: nextSource };
123
+                        }
124
+
125
+                        return {};
126
+                    });
127
+                };
116
 
128
 
117
                 // Wait for the source/URI to load.
129
                 // Wait for the source/URI to load.
118
-                ImageCache.get().on(
119
-                    nextSource,
120
-                    /* observer */ () => {
121
-                        this._unmounted || this.setState((prevState, props) => {
122
-                            if (props.uri === nextURI
123
-                                    && (!prevState.source
124
-                                        || prevState.source.uri !== nextURI)) {
125
-                                return { source: nextSource };
126
-                            }
127
-
128
-                            return {};
129
-                        });
130
-                    },
131
-                    /* immutable */ true);
130
+                if (ImageCache) {
131
+                    ImageCache.get().on(
132
+                        nextSource,
133
+                        observer,
134
+                        /* immutable */ true);
135
+                } else if (assignState) {
136
+                    this.state = {
137
+                        ...this.state,
138
+                        source: nextSource
139
+                    };
140
+                } else {
141
+                    observer();
142
+                }
132
             }
143
             }
133
         }
144
         }
134
     }
145
     }

+ 1
- 1
react/features/mobile/image-cache/functions.js Bestand weergeven

27
  * @returns {void}
27
  * @returns {void}
28
  */
28
  */
29
 export function prefetch(source) {
29
 export function prefetch(source) {
30
-    ImageCache.get().on(source, /* observer */ _onLoad, /* immutable */ true);
30
+    ImageCache && ImageCache.get().on(source, _onLoad, /* immutable */ true);
31
 }
31
 }

+ 1
- 1
react/features/mobile/image-cache/middleware.js Bestand weergeven

39
     case APP_WILL_MOUNT:
39
     case APP_WILL_MOUNT:
40
     case CONFERENCE_FAILED:
40
     case CONFERENCE_FAILED:
41
     case CONFERENCE_LEFT:
41
     case CONFERENCE_LEFT:
42
-        ImageCache.get().clear();
42
+        ImageCache && ImageCache.get().clear();
43
         break;
43
         break;
44
 
44
 
45
     case PARTICIPANT_ID_CHANGED:
45
     case PARTICIPANT_ID_CHANGED:

+ 16
- 0
react/features/mobile/image-cache/react-native-img-cache.no.js Bestand weergeven

1
+// XXX The third-party react-native modules react-native-fetch-blob utilizes the
2
+// same HTTP library as react-native i.e. okhttp. Unfortunately, that means that
3
+// the versions of okhttp on which react-native and react-native-fetch-blob
4
+// depend may have incompatible APIs. Such an incompatibility will be made
5
+// apparent at compile time and the developer doing the compilation may choose
6
+// to not compile react-native-fetch-blob's source code.
7
+
8
+// XXX The choice between the use of react-native-img-cache could've been done
9
+// at runtime based on whether NativeModules.RNFetchBlob is defined if only
10
+// react-native-fetch-blob would've completely protected itself. At the time of
11
+// this writing its source code appears to be attempting to protect itself from
12
+// missing native binaries but that protection is incomplete and there's a
13
+// TypeError.
14
+
15
+import { Image } from 'react-native';
16
+export { Image as CachedImage, undefined as ImageCache };

Laden…
Annuleren
Opslaan