16
16
import com .bumptech .glide .load .model .Headers ;
17
17
import com .bumptech .glide .load .model .LazyHeaders ;
18
18
import com .bumptech .glide .request .RequestOptions ;
19
+ import com .bumptech .glide .signature .ApplicationVersionSignature ;
19
20
import com .facebook .react .bridge .JSApplicationIllegalArgumentException ;
20
21
import com .facebook .react .bridge .NoSuchKeyException ;
21
22
import com .facebook .react .bridge .ReadableMap ;
30
31
31
32
import javax .annotation .Nullable ;
32
33
34
+ import static com .bumptech .glide .request .RequestOptions .signatureOf ;
35
+
33
36
class FastImageViewConverter {
34
37
private static final Drawable TRANSPARENT_DRAWABLE = new ColorDrawable (Color .TRANSPARENT );
35
38
@@ -81,7 +84,7 @@ static Headers getHeaders(ReadableMap source) {
81
84
return headers ;
82
85
}
83
86
84
- static RequestOptions getOptions (ReadableMap source ) {
87
+ static RequestOptions getOptions (Context context , FastImageSource imageSource , ReadableMap source ) {
85
88
// Get priority.
86
89
final Priority priority = FastImageViewConverter .getPriority (source );
87
90
// Get cache control method.
@@ -102,12 +105,25 @@ static RequestOptions getOptions(ReadableMap source) {
102
105
// Use defaults.
103
106
break ;
104
107
}
105
- return new RequestOptions ()
106
- .diskCacheStrategy (diskCacheStrategy )
107
- .onlyRetrieveFromCache (onlyFromCache )
108
- .skipMemoryCache (skipMemoryCache )
109
- .priority (priority )
110
- .placeholder (TRANSPARENT_DRAWABLE );
108
+
109
+ RequestOptions options = new RequestOptions ()
110
+ .diskCacheStrategy (diskCacheStrategy )
111
+ .onlyRetrieveFromCache (onlyFromCache )
112
+ .skipMemoryCache (skipMemoryCache )
113
+ .priority (priority )
114
+ .placeholder (TRANSPARENT_DRAWABLE );
115
+
116
+ if (imageSource .isResource ()) {
117
+ // Every local resource (drawable) in Android has its own unique numeric id, which are
118
+ // generated at build time. Although these ids are unique, they are not guaranteed unique
119
+ // across builds. The underlying glide implementation caches these resources. To make
120
+ // sure the cache does not return the wrong image, we should clear the cache when the
121
+ // application version changes. Adding a cache signature for only these local resources
122
+ // solves this issue: https://github.com/DylanVann/react-native-fast-image/issues/402
123
+ options = options .apply (signatureOf (ApplicationVersionSignature .obtain (context )));
124
+ }
125
+
126
+ return options ;
111
127
}
112
128
113
129
private static FastImageCacheControl getCacheControl (ReadableMap source ) {
0 commit comments