1616import com .bumptech .glide .load .model .Headers ;
1717import com .bumptech .glide .load .model .LazyHeaders ;
1818import com .bumptech .glide .request .RequestOptions ;
19+ import com .bumptech .glide .signature .ApplicationVersionSignature ;
1920import com .facebook .react .bridge .JSApplicationIllegalArgumentException ;
2021import com .facebook .react .bridge .NoSuchKeyException ;
2122import com .facebook .react .bridge .ReadableMap ;
3031
3132import javax .annotation .Nullable ;
3233
34+ import static com .bumptech .glide .request .RequestOptions .signatureOf ;
35+
3336class FastImageViewConverter {
3437 private static final Drawable TRANSPARENT_DRAWABLE = new ColorDrawable (Color .TRANSPARENT );
3538
@@ -81,7 +84,7 @@ static Headers getHeaders(ReadableMap source) {
8184 return headers ;
8285 }
8386
84- static RequestOptions getOptions (ReadableMap source ) {
87+ static RequestOptions getOptions (Context context , FastImageSource imageSource , ReadableMap source ) {
8588 // Get priority.
8689 final Priority priority = FastImageViewConverter .getPriority (source );
8790 // Get cache control method.
@@ -102,12 +105,25 @@ static RequestOptions getOptions(ReadableMap source) {
102105 // Use defaults.
103106 break ;
104107 }
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 ;
111127 }
112128
113129 private static FastImageCacheControl getCacheControl (ReadableMap source ) {
0 commit comments