@nativescript-community/ui-image 4.3.21 → 4.3.23

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.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,18 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [4.3.23](https://github.com/nativescript-community/ui-image/compare/v4.3.22...v4.3.23) (2023-11-22)
7
+
8
+ ### Bug Fixes
9
+
10
+ * **ios:** updated native dep ([e6cc5f5](https://github.com/nativescript-community/ui-image/commit/e6cc5f5e0d42f048acbf37d0f8b936f138326b78))
11
+
12
+ ## [4.3.22](https://github.com/nativescript-community/ui-image/compare/v4.3.21...v4.3.22) (2023-11-17)
13
+
14
+ ### Bug Fixes
15
+
16
+ * edge cases auto measurement fix ([dff9f29](https://github.com/nativescript-community/ui-image/commit/dff9f293f22f36641bd623fd8df3a5799ad14ffa))
17
+
6
18
  ## [4.3.21](https://github.com/nativescript-community/ui-image/compare/v4.3.20...v4.3.21) (2023-11-09)
7
19
 
8
20
  **Note:** Version bump only for package @nativescript-community/ui-image
package/index-common.js CHANGED
@@ -94,7 +94,7 @@ export const srcProperty = new Property({ name: 'src' });
94
94
  export const lowerResSrcProperty = new Property({ name: 'lowerResSrc' });
95
95
  export const placeholderImageUriProperty = new Property({ name: 'placeholderImageUri' });
96
96
  export const failureImageUriProperty = new Property({ name: 'failureImageUri' });
97
- export const stretchProperty = new Property({ name: 'stretch', defaultValue: 'aspectFill' });
97
+ export const stretchProperty = new Property({ name: 'stretch' });
98
98
  export const backgroundUriProperty = new Property({ name: 'backgroundUri' });
99
99
  export const progressiveRenderingEnabledProperty = new Property({ name: 'progressiveRenderingEnabled', valueConverter: booleanConverter });
100
100
  export const localThumbnailPreviewsEnabledProperty = new Property({ name: 'localThumbnailPreviewsEnabled', valueConverter: booleanConverter });
@@ -62,17 +62,19 @@ export declare class FailureEventData extends EventData {
62
62
  get error(): ImageError;
63
63
  set error(value: ImageError);
64
64
  }
65
- export declare const needUpdateHierarchy: (target: any, propertyKey: string | Symbol, descriptor: PropertyDescriptor) => void;
65
+ export declare const needUpdateHierarchy: (targetOrNeedsLayout: any, propertyKey?: string | Symbol, descriptor?: PropertyDescriptor) => any;
66
66
  export declare class Img extends ImageBase {
67
67
  nativeViewProtected: com.nativescript.image.DraweeView;
68
68
  nativeImageViewProtected: com.nativescript.image.DraweeView;
69
69
  isLoading: boolean;
70
70
  mCanUpdateHierarchy: boolean;
71
71
  mNeedUpdateHierarchy: boolean;
72
+ mNeedUpdateLayout: boolean;
72
73
  onResumeNativeUpdates(): void;
73
74
  createNativeView(): com.nativescript.image.DraweeView;
74
75
  updateViewSize(imageInfo: any): void;
75
76
  disposeNativeView(): void;
77
+ get cacheKey(): string | globalAndroid.net.Uri;
76
78
  updateImageUri(): void;
77
79
  controllerListener: com.facebook.drawee.controller.ControllerListener<com.facebook.imagepipeline.image.ImageInfo>;
78
80
  protected initImage(): Promise<void>;
package/index.android.js CHANGED
@@ -2,6 +2,7 @@ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u;
2
2
  export * from './index-common';
3
3
  import { Application, Background, Color, ImageAsset, ImageSource, Trace, Utils, backgroundInternalProperty, knownFolders, path } from '@nativescript/core';
4
4
  import { isString } from '@nativescript/core/utils/types';
5
+ import { layout } from '@nativescript/core/utils/layout-helper';
5
6
  import { CLog, CLogTypes, EventData, ImageBase, ScaleType, aspectRatioProperty, backgroundUriProperty, blurDownSamplingProperty, blurRadiusProperty, fadeDurationProperty, failureImageUriProperty, imageRotationProperty, lowerResSrcProperty, needRequestImage, placeholderImageUriProperty, progressBarColorProperty, roundAsCircleProperty, roundBottomLeftRadiusProperty, roundBottomRightRadiusProperty, roundTopLeftRadiusProperty, roundTopRightRadiusProperty, showProgressBarProperty, srcProperty, stretchProperty, tintColorProperty } from './index-common';
6
7
  let initialized = false;
7
8
  let initializeConfig;
@@ -264,7 +265,27 @@ export class FailureEventData extends EventData {
264
265
  this._error = value;
265
266
  }
266
267
  }
267
- export const needUpdateHierarchy = function (target, propertyKey, descriptor) {
268
+ export const needUpdateHierarchy = function (targetOrNeedsLayout, propertyKey, descriptor) {
269
+ if (typeof targetOrNeedsLayout === 'boolean') {
270
+ return function (target2, propertyKey, descriptor) {
271
+ const originalMethod = descriptor.value;
272
+ descriptor.value = function (...args) {
273
+ if (!this.mCanUpdateHierarchy) {
274
+ this.mNeedUpdateHierarchy = true;
275
+ if (this.isLoaded && targetOrNeedsLayout) {
276
+ const layoutParams = this.nativeViewProtected?.getLayoutParams();
277
+ if (layoutParams) {
278
+ if (layout.getMeasureSpecMode(layoutParams.height) !== layout.EXACTLY || layout.getMeasureSpecMode(layoutParams.width) !== layout.EXACTLY) {
279
+ this.mNeedUpdateLayout = true;
280
+ }
281
+ }
282
+ }
283
+ return;
284
+ }
285
+ return originalMethod.apply(this, args);
286
+ };
287
+ };
288
+ }
268
289
  const originalMethod = descriptor.value;
269
290
  descriptor.value = function (...args) {
270
291
  if (!this.mCanUpdateHierarchy) {
@@ -280,6 +301,7 @@ export class Img extends ImageBase {
280
301
  this.isLoading = false;
281
302
  this.mCanUpdateHierarchy = true;
282
303
  this.mNeedUpdateHierarchy = false;
304
+ this.mNeedUpdateLayout = false;
283
305
  }
284
306
  onResumeNativeUpdates() {
285
307
  // {N} suspends properties update on `_suspendNativeUpdates`. So we only need to do this in onResumeNativeUpdates
@@ -290,6 +312,10 @@ export class Img extends ImageBase {
290
312
  this.mNeedUpdateHierarchy = false;
291
313
  this.updateHierarchy();
292
314
  }
315
+ if (this.mNeedUpdateLayout) {
316
+ this.mNeedUpdateLayout = false;
317
+ this.nativeViewProtected.requestLayout();
318
+ }
293
319
  }
294
320
  createNativeView() {
295
321
  if (!initialized) {
@@ -327,15 +353,22 @@ export class Img extends ImageBase {
327
353
  this.controllerListener = null;
328
354
  // this.nativeImageViewProtected.setImageURI(null, null);
329
355
  }
356
+ get cacheKey() {
357
+ const src = this.src;
358
+ if (src && !(src instanceof ImageSource)) {
359
+ return getUri(src);
360
+ }
361
+ return undefined;
362
+ }
330
363
  updateImageUri() {
331
364
  const imagePipeLine = getImagePipeline();
365
+ const cacheKey = this.cacheKey;
332
366
  const src = this.src;
333
- if (!(src instanceof ImageSource)) {
334
- const uri = getUri(src);
335
- const isInCache = imagePipeLine.isInBitmapMemoryCache(uri);
336
- if (isInCache) {
337
- imagePipeLine.evictFromCache(uri);
338
- }
367
+ if (cacheKey) {
368
+ // const isInCache = imagePipeLine.isInBitmapMemoryCache(uri);
369
+ // // if (isInCache) {
370
+ imagePipeLine.evictFromCache(cacheKey);
371
+ // }
339
372
  }
340
373
  this.src = null;
341
374
  this.src = src;
@@ -747,7 +780,7 @@ __decorate([
747
780
  needUpdateHierarchy
748
781
  ], Img.prototype, _j, null);
749
782
  __decorate([
750
- needUpdateHierarchy
783
+ needUpdateHierarchy(true)
751
784
  ], Img.prototype, _k, null);
752
785
  __decorate([
753
786
  needUpdateHierarchy
@@ -778,7 +811,7 @@ __decorate([
778
811
  ], Img.prototype, _u, null);
779
812
  class GenericDraweeHierarchyBuilder {
780
813
  constructor() {
781
- const res = Utils.ad.getApplicationContext().getResources();
814
+ const res = Utils.android.getApplicationContext().getResources();
782
815
  this.nativeBuilder = new com.facebook.drawee.generic.GenericDraweeHierarchyBuilder(res);
783
816
  }
784
817
  setPlaceholderImage(drawable, scaleType) {
package/index.d.ts CHANGED
@@ -208,6 +208,8 @@ export class Img extends View {
208
208
  * Android: custom imageRotation
209
209
  */
210
210
  imageRotation: number;
211
+
212
+ cacheKey: string;
211
213
  }
212
214
 
213
215
  /**
package/index.ios.d.ts CHANGED
@@ -17,11 +17,11 @@ export declare class ImagePipeline {
17
17
  private mIos;
18
18
  constructor();
19
19
  getCacheKey(uri: string, context: any): string;
20
- isInDiskCache(uri: string): boolean;
21
- isInBitmapMemoryCache(uri: string): boolean;
22
- evictFromMemoryCache(uri: string): void;
23
- evictFromDiskCache(uri: string): void;
24
- evictFromCache(uri: string): void;
20
+ isInDiskCache(key: string): boolean;
21
+ isInBitmapMemoryCache(key: string): boolean;
22
+ evictFromMemoryCache(key: string): void;
23
+ evictFromDiskCache(key: string): void;
24
+ evictFromCache(key: string): void;
25
25
  clearCaches(): void;
26
26
  clearMemoryCaches(): void;
27
27
  clearDiskCaches(): void;
@@ -36,6 +36,8 @@ export declare class Img extends ImageBase {
36
36
  nativeViewProtected: SDAnimatedImageView | UIImageView;
37
37
  nativeImageViewProtected: SDAnimatedImageView | UIImageView;
38
38
  isLoading: boolean;
39
+ mCacheKey: string;
40
+ get cacheKey(): string;
39
41
  protected mImageSourceAffectsLayout: boolean;
40
42
  protected mCIFilter: CIFilter;
41
43
  createNativeView(): UIImageView;
package/index.ios.js CHANGED
@@ -80,20 +80,20 @@ export class ImagePipeline {
80
80
  getCacheKey(uri, context) {
81
81
  return SDWebImageManager.sharedManager.cacheKeyForURLContext(NSURL.URLWithString(uri), context);
82
82
  }
83
- isInDiskCache(uri) {
84
- return this.mIos.diskImageDataExistsWithKey(getUri(uri).absoluteString);
83
+ isInDiskCache(key) {
84
+ return this.mIos.diskImageDataExistsWithKey(key);
85
85
  }
86
- isInBitmapMemoryCache(uri) {
87
- return this.mIos.imageFromMemoryCacheForKey(getUri(uri).absoluteString) !== null;
86
+ isInBitmapMemoryCache(key) {
87
+ return this.mIos.imageFromMemoryCacheForKey(key) !== null;
88
88
  }
89
- evictFromMemoryCache(uri) {
90
- this.mIos.removeImageFromMemoryForKey(getUri(uri).absoluteString);
89
+ evictFromMemoryCache(key) {
90
+ this.mIos.removeImageFromMemoryForKey(key);
91
91
  }
92
- evictFromDiskCache(uri) {
93
- this.mIos.removeImageFromDiskForKey(getUri(uri).absoluteString);
92
+ evictFromDiskCache(key) {
93
+ this.mIos.removeImageFromDiskForKey(key);
94
94
  }
95
- evictFromCache(uri) {
96
- const key = getUri(uri).absoluteString;
95
+ evictFromCache(key) {
96
+ // const key = getUri(uri).absoluteString;
97
97
  this.mIos.removeImageFromDiskForKey(key);
98
98
  this.mIos.removeImageFromMemoryForKey(key);
99
99
  // this.mIos.removeImageForKeyWithCompletion(getUri(uri).absoluteString, null);
@@ -221,6 +221,9 @@ export class Img extends ImageBase {
221
221
  this.handleImageProgress(totalSize > 0 ? currentSize / totalSize : -1, totalSize);
222
222
  };
223
223
  }
224
+ get cacheKey() {
225
+ return this.mCacheKey;
226
+ }
224
227
  createNativeView() {
225
228
  const result = this.animatedImageView ? SDAnimatedImageView.new() : UIImageView.new();
226
229
  result.contentMode = 1 /* UIViewContentMode.ScaleAspectFit */;
@@ -243,23 +246,34 @@ export class Img extends ImageBase {
243
246
  const finiteWidth = widthMode === layout.EXACTLY;
244
247
  const finiteHeight = heightMode === layout.EXACTLY;
245
248
  this.mImageSourceAffectsLayout = !finiteWidth || !finiteHeight;
246
- if (Trace.isEnabled()) {
247
- CLog(CLogTypes.info, 'onMeasure', this.src, widthMeasureSpec, heightMeasureSpec, width, height, this.aspectRatio, image && image.imageOrientation);
248
- }
249
+ // if (Trace.isEnabled()) {
250
+ // CLog(CLogTypes.info, 'onMeasure', this.src, widthMeasureSpec, heightMeasureSpec, width, height, this.aspectRatio, image && image.imageOrientation);
251
+ // }
249
252
  if (image || this.aspectRatio > 0) {
250
253
  const nativeWidth = image ? layout.toDevicePixels(image.size.width) : 0;
251
254
  const nativeHeight = image ? layout.toDevicePixels(image.size.height) : 0;
252
255
  const imgRatio = nativeWidth / nativeHeight;
253
256
  const ratio = this.aspectRatio || imgRatio;
254
257
  // const scale = this.computeScaleFactor(width, height, finiteWidth, finiteHeight, nativeWidth, nativeHeight, this.aspectRatio || imgRatio );
255
- if (!finiteWidth) {
258
+ if (!finiteWidth && finiteHeight) {
256
259
  widthMeasureSpec = layout.makeMeasureSpec(height * ratio, layout.EXACTLY);
257
260
  }
258
- if (!finiteHeight) {
261
+ else if (!finiteHeight && finiteWidth) {
259
262
  heightMeasureSpec = layout.makeMeasureSpec(width / ratio, layout.EXACTLY);
260
263
  }
264
+ else if (!finiteWidth && !finiteHeight) {
265
+ const viewRatio = width / height;
266
+ if (viewRatio < ratio) {
267
+ widthMeasureSpec = layout.makeMeasureSpec(width, layout.EXACTLY);
268
+ heightMeasureSpec = layout.makeMeasureSpec((width / ratio), layout.EXACTLY);
269
+ }
270
+ else {
271
+ widthMeasureSpec = layout.makeMeasureSpec((height * ratio), layout.EXACTLY);
272
+ heightMeasureSpec = layout.makeMeasureSpec(height, layout.EXACTLY);
273
+ }
274
+ }
261
275
  if (Trace.isEnabled()) {
262
- CLog(CLogTypes.info, 'onMeasure scale', this.src, this.aspectRatio, finiteWidth, finiteHeight, width, height, nativeWidth, nativeHeight, widthMeasureSpec, heightMeasureSpec);
276
+ CLog(CLogTypes.info, 'onMeasure', this.src, this.aspectRatio, finiteWidth, finiteHeight, width, height, nativeWidth, nativeHeight, widthMeasureSpec, heightMeasureSpec);
263
277
  }
264
278
  }
265
279
  super.onMeasure(widthMeasureSpec, heightMeasureSpec);
@@ -268,13 +282,15 @@ export class Img extends ImageBase {
268
282
  const imagePipeLine = getImagePipeline();
269
283
  const src = this.src;
270
284
  if (!(src instanceof ImageSource)) {
271
- const uri = getUri(src).absoluteString;
272
- const isInCache = imagePipeLine.isInBitmapMemoryCache(uri);
273
- if (isInCache) {
274
- imagePipeLine.evictFromCache(uri);
275
- }
285
+ const cachekKey = this.mCacheKey || getUri(src).absoluteString;
286
+ // const isInCache = imagePipeLine.isInBitmapMemoryCache(cachekKey);
287
+ // if (isInCache) {
288
+ imagePipeLine.evictFromCache(cachekKey);
289
+ // }
276
290
  }
277
291
  this.src = null;
292
+ // ensure we clear the image as
293
+ this._setNativeImage(null, false);
278
294
  this.src = src;
279
295
  }
280
296
  _setNativeImage(nativeImage, animated = true) {
@@ -306,7 +322,7 @@ export class Img extends ImageBase {
306
322
  this.nativeImageViewProtected.image = nativeImage;
307
323
  }
308
324
  if (this.mImageSourceAffectsLayout) {
309
- this.mImageSourceAffectsLayout = false;
325
+ // this.mImageSourceAffectsLayout = false;
310
326
  this.requestLayout();
311
327
  }
312
328
  }
@@ -408,6 +424,7 @@ export class Img extends ImageBase {
408
424
  }
409
425
  context.setValueForKey(SDImagePipelineTransformer.transformerWithTransformers(transformers), SDWebImageContextImageTransformer);
410
426
  }
427
+ this.mCacheKey = SDWebImageManager.sharedManager.cacheKeyForURLContext(uri, context);
411
428
  this.nativeImageViewProtected.sd_setImageWithURLPlaceholderImageOptionsContextProgressCompleted(uri, this.placeholderImage, options, context, this.onLoadProgress, this.handleImageLoaded);
412
429
  }
413
430
  else if (this.placeholderImage) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nativescript-community/ui-image",
3
- "version": "4.3.21",
3
+ "version": "4.3.23",
4
4
  "description": "Advanced and efficient image display plugin which uses Fresco (Android) and SDWebImage (iOS) to implement caching, placeholders, image effects, and much more.",
5
5
  "main": "./index",
6
6
  "sideEffects": false,
@@ -44,5 +44,5 @@
44
44
  },
45
45
  "license": "Apache-2.0",
46
46
  "readmeFilename": "README.md",
47
- "gitHead": "c8d5da96305841a97fce835b01fd2f41f8125257"
47
+ "gitHead": "2a74cda73128571c05d0e636aefe40be63c8d3eb"
48
48
  }
@@ -26,6 +26,7 @@ import android.graphics.PorterDuffXfermode;
26
26
  import android.view.ViewOutlineProvider;
27
27
 
28
28
  import org.nativescript.widgets.BorderDrawable;
29
+ import com.nativescript.image.ScalingUtils.AbstractScaleType;
29
30
 
30
31
  import org.json.JSONArray;
31
32
  import org.json.JSONObject;
@@ -159,18 +160,33 @@ public class DraweeView extends SimpleDraweeView {
159
160
  int width = MeasureSpec.getSize(widthMeasureSpec);
160
161
  int heightMode = MeasureSpec.getMode(heightMeasureSpec);
161
162
  int height = MeasureSpec.getSize(heightMeasureSpec);
162
- final float aspectRatio = this.getAspectRatio();
163
+ float aspectRatio = this.getAspectRatio();
163
164
  if (aspectRatio > 0) {
164
165
  boolean finiteWidth = widthMode == android.view.View.MeasureSpec.EXACTLY;
165
166
  boolean finiteHeight = heightMode == android.view.View.MeasureSpec.EXACTLY;
167
+ Object scaleType = getHierarchy().getActualImageScaleType();
168
+ if (scaleType instanceof AbstractScaleType) {
169
+ final float rotation = ((AbstractScaleType)scaleType).getImageRotation();
170
+ if (Math.abs(rotation) % 180 != 0) {
171
+ aspectRatio = 1.0f / aspectRatio;
172
+ }
173
+ }
166
174
  if (imageWidth != 0 && imageHeight != 0) {
167
- if (!finiteWidth) {
175
+ if (!finiteWidth && finiteHeight) {
168
176
  widthMeasureSpec = android.view.View.MeasureSpec.makeMeasureSpec((int) (height * aspectRatio),
169
177
  android.view.View.MeasureSpec.EXACTLY);
170
- }
171
- if (!finiteHeight) {
178
+ } else if (!finiteHeight && finiteWidth) {
172
179
  heightMeasureSpec = android.view.View.MeasureSpec.makeMeasureSpec((int) (width / aspectRatio),
173
180
  android.view.View.MeasureSpec.EXACTLY);
181
+ } else if (!finiteWidth && !finiteHeight ) {
182
+ float viewRatio = width / (float)height;
183
+ if (viewRatio < aspectRatio) {
184
+ widthMeasureSpec = android.view.View.MeasureSpec.makeMeasureSpec((int) width, android.view.View.MeasureSpec.EXACTLY);
185
+ heightMeasureSpec = android.view.View.MeasureSpec.makeMeasureSpec((int) (width / aspectRatio), android.view.View.MeasureSpec.EXACTLY);
186
+ } else {
187
+ widthMeasureSpec = android.view.View.MeasureSpec.makeMeasureSpec((int) (height * aspectRatio), android.view.View.MeasureSpec.EXACTLY);
188
+ heightMeasureSpec = android.view.View.MeasureSpec.makeMeasureSpec((int) height, android.view.View.MeasureSpec.EXACTLY);
189
+ }
174
190
  }
175
191
  }
176
192
  }
@@ -123,6 +123,10 @@ public class ScalingUtils {
123
123
  public void setImageMatrix(Matrix matrix) {
124
124
  _imageMatrix = matrix;
125
125
  }
126
+
127
+ public float getImageRotation() {
128
+ return _imageRotation;
129
+ }
126
130
  public void setImageRotation(float rotation) {
127
131
  _imageRotation = rotation;
128
132
  }
Binary file
@@ -1,2 +1,2 @@
1
- pod 'SDWebImage', '>= 5.13.0'
1
+ pod 'SDWebImage', '>= 5.18.5.0'
2
2
  pod 'SDWebImagePhotosPlugin'
package/vue/index.mjs ADDED
@@ -0,0 +1,8 @@
1
+ import { Img } from '../image';
2
+ const ImagePlugin = {
3
+ install(Vue) {
4
+ Vue.registerElement('NSImg', () => Img);
5
+ }
6
+ };
7
+ export default ImagePlugin;
8
+ //# sourceMappingURL=index.mjs.map