@nativescript-community/ui-image 4.3.14 → 4.3.16

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.16](https://github.com/nativescript-community/ui-image/compare/v4.3.15...v4.3.16) (2023-09-29)
7
+
8
+ ### Bug Fixes
9
+
10
+ * **android:** fix for image disappearing on fragment/ativity transitions. See https://github.com/facebook/fresco/issues/1446 ([b36d001](https://github.com/nativescript-community/ui-image/commit/b36d0012af443fadcdb969e901f7f0e69f4e0c80))
11
+
12
+ ## [4.3.15](https://github.com/nativescript-community/ui-image/compare/v4.3.14...v4.3.15) (2023-09-28)
13
+
14
+ ### Bug Fixes
15
+
16
+ * **android:** most stretch values are now working correctly with imageRotation ([323d42e](https://github.com/nativescript-community/ui-image/commit/323d42edc85e57145cb4e7e6158b72e256437d0d))
17
+
6
18
  ## [4.3.14](https://github.com/nativescript-community/ui-image/compare/v4.3.13...v4.3.14) (2023-09-27)
7
19
 
8
20
  **Note:** Version bump only for package @nativescript-community/ui-image
package/index-common.js CHANGED
@@ -103,7 +103,7 @@ export const progressBarColorProperty = new Property({ name: 'progressBarColor',
103
103
  export const roundAsCircleProperty = new Property({ name: 'roundAsCircle', valueConverter: booleanConverter, affectsLayout: isAndroid });
104
104
  export const blurRadiusProperty = new Property({ name: 'blurRadius', valueConverter: (v) => parseFloat(v) });
105
105
  export const blurDownSamplingProperty = new Property({ name: 'blurDownSampling', valueConverter: (v) => parseFloat(v) });
106
- export const imageRotationProperty = new Property({ name: 'imageRotation', valueConverter: (v) => parseFloat(v) });
106
+ export const imageRotationProperty = new Property({ name: 'imageRotation', valueConverter: (v) => parseFloat(v), defaultValue: 0 });
107
107
  export const autoPlayAnimationsProperty = new Property({ name: 'autoPlayAnimations', valueConverter: booleanConverter });
108
108
  export const tapToRetryEnabledProperty = new Property({ name: 'tapToRetryEnabled', valueConverter: booleanConverter });
109
109
  export const aspectRatioProperty = new Property({ name: 'aspectRatio', affectsLayout: true, valueConverter: (v) => parseFloat(v) });
package/index.android.js CHANGED
@@ -1,4 +1,4 @@
1
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
1
+ 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';
@@ -384,36 +384,36 @@ export class Img extends ImageBase {
384
384
  [_j = roundTopLeftRadiusProperty.setNative]() {
385
385
  this.updateHierarchy();
386
386
  }
387
- [imageRotationProperty.setNative](value) {
387
+ [_k = imageRotationProperty.setNative](value) {
388
388
  const scaleType = this.nativeImageViewProtected.getHierarchy().getActualImageScaleType();
389
389
  scaleType['setImageRotation']?.(value);
390
390
  this.nativeImageViewProtected.invalidate();
391
391
  }
392
- [_k = roundTopRightRadiusProperty.setNative]() {
392
+ [_l = roundTopRightRadiusProperty.setNative]() {
393
393
  this.updateHierarchy();
394
394
  }
395
- [_l = roundBottomLeftRadiusProperty.setNative]() {
395
+ [_m = roundBottomLeftRadiusProperty.setNative]() {
396
396
  this.updateHierarchy();
397
397
  }
398
- [_m = roundBottomRightRadiusProperty.setNative]() {
398
+ [_o = roundBottomRightRadiusProperty.setNative]() {
399
399
  this.updateHierarchy();
400
400
  }
401
- [_o = tintColorProperty.setNative](value) {
401
+ [_p = tintColorProperty.setNative](value) {
402
402
  this.updateHierarchy();
403
403
  }
404
- [_p = blurRadiusProperty.setNative]() {
404
+ [_q = blurRadiusProperty.setNative]() {
405
405
  this.initImage();
406
406
  }
407
- [_q = srcProperty.setNative]() {
407
+ [_r = srcProperty.setNative]() {
408
408
  this.initImage();
409
409
  }
410
- [_r = lowerResSrcProperty.setNative]() {
410
+ [_s = lowerResSrcProperty.setNative]() {
411
411
  this.initImage();
412
412
  }
413
- [_s = blurDownSamplingProperty.setNative]() {
413
+ [_t = blurDownSamplingProperty.setNative]() {
414
414
  this.initImage();
415
415
  }
416
- [_t = aspectRatioProperty.setNative]() {
416
+ [_u = aspectRatioProperty.setNative]() {
417
417
  this.initImage();
418
418
  }
419
419
  [backgroundInternalProperty.setNative](value) {
@@ -669,6 +669,9 @@ export class Img extends ImageBase {
669
669
  builder.setCornersRadii(topLeftRadius, topRightRadius, bottomRightRadius, bottomLeftRadius);
670
670
  }
671
671
  this.nativeImageViewProtected.setHierarchy(builder.build());
672
+ if (!this._needRequestImage) {
673
+ this.nativeImageViewProtected.setController(this.nativeImageViewProtected.getController());
674
+ }
672
675
  }
673
676
  }
674
677
  getDrawable(path) {
@@ -773,7 +776,7 @@ __decorate([
773
776
  needUpdateHierarchy
774
777
  ], Img.prototype, _o, null);
775
778
  __decorate([
776
- needRequestImage
779
+ needUpdateHierarchy
777
780
  ], Img.prototype, _p, null);
778
781
  __decorate([
779
782
  needRequestImage
@@ -787,6 +790,9 @@ __decorate([
787
790
  __decorate([
788
791
  needRequestImage
789
792
  ], Img.prototype, _t, null);
793
+ __decorate([
794
+ needRequestImage
795
+ ], Img.prototype, _u, null);
790
796
  class GenericDraweeHierarchyBuilder {
791
797
  constructor() {
792
798
  const res = Utils.ad.getApplicationContext().getResources();
@@ -823,12 +829,12 @@ class GenericDraweeHierarchyBuilder {
823
829
  }
824
830
  return this;
825
831
  }
826
- setActualImageScaleType(scaleType, imageRotation) {
832
+ setActualImageScaleType(scaleType, imageRotation = 0) {
827
833
  if (!this.nativeBuilder) {
828
834
  return this;
829
835
  }
830
836
  const nativeScaleType = getScaleType(scaleType);
831
- if (nativeScaleType['setImageRotation']) {
837
+ if (imageRotation !== 0 && nativeScaleType['setImageRotation']) {
832
838
  nativeScaleType['setImageRotation'](imageRotation);
833
839
  }
834
840
  this.nativeBuilder.setActualImageScaleType(nativeScaleType);
package/index.d.ts CHANGED
@@ -198,6 +198,12 @@ export class Img extends View {
198
198
  * IOS: if you want to show animated images you need to set this to true
199
199
  */
200
200
  animatedImageView: boolean;
201
+
202
+ loadMode: 'sync' | 'async';
203
+ alwaysFade: boolean;
204
+ noCache: boolean;
205
+ tintColor: Color;
206
+ imageRotation: number;
201
207
  }
202
208
 
203
209
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nativescript-community/ui-image",
3
- "version": "4.3.14",
3
+ "version": "4.3.16",
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": "cc57cff80b69dd3bcce84f27ee5e66c46b858874"
47
+ "gitHead": "7d5be4ee8fb3fcef33da045af7151873cd084b4b"
48
48
  }
@@ -39,12 +39,24 @@ public class DraweeView extends SimpleDraweeView {
39
39
  public boolean isUsingOutlineProvider = false;
40
40
  private static Paint clipPaint;
41
41
 
42
+ private boolean mLegacyVisibilityHandlingEnabled = false;
43
+
44
+ private static boolean sGlobalLegacyVisibilityHandlingEnabled = true;
45
+
46
+ public static void setGlobalLegacyVisibilityHandlingEnabled(
47
+ boolean legacyVisibilityHandlingEnabled) {
48
+ sGlobalLegacyVisibilityHandlingEnabled = legacyVisibilityHandlingEnabled;
49
+ }
50
+
42
51
  public DraweeView(Context context, GenericDraweeHierarchy hierarchy) {
43
52
  super(context);
44
53
  }
45
54
 
46
55
  public DraweeView(Context context) {
47
56
  super(context);
57
+ // In Android N and above, visibility handling for Drawables has been changed, which breaks
58
+ // activity transitions with DraweeViews.
59
+ mLegacyVisibilityHandlingEnabled = sGlobalLegacyVisibilityHandlingEnabled && context.getApplicationInfo().targetSdkVersion >= 24; //Build.VERSION_CODES.N
48
60
  }
49
61
 
50
62
  public DraweeView(Context context, AttributeSet attrs) {
@@ -55,6 +67,61 @@ public class DraweeView extends SimpleDraweeView {
55
67
  super(context, attrs, defStyle);
56
68
  }
57
69
 
70
+ @Override
71
+ protected void onAttachedToWindow() {
72
+ super.onAttachedToWindow();
73
+ maybeOverrideVisibilityHandling();
74
+ onAttach();
75
+ }
76
+
77
+ @Override
78
+ protected void onDetachedFromWindow() {
79
+ super.onDetachedFromWindow();
80
+ maybeOverrideVisibilityHandling();
81
+ onDetach();
82
+ }
83
+
84
+ @Override
85
+ public void onStartTemporaryDetach() {
86
+ super.onStartTemporaryDetach();
87
+ maybeOverrideVisibilityHandling();
88
+ onDetach();
89
+ }
90
+
91
+ @Override
92
+ public void onFinishTemporaryDetach() {
93
+ super.onFinishTemporaryDetach();
94
+ maybeOverrideVisibilityHandling();
95
+ onAttach();
96
+ }
97
+
98
+ @Override
99
+ protected void onVisibilityChanged(
100
+ View changedView,
101
+ int visibility) {
102
+ super.onVisibilityChanged(changedView, visibility);
103
+ maybeOverrideVisibilityHandling();
104
+ }
105
+
106
+ @Override
107
+ public void onVisibilityAggregated (boolean isVisible) {
108
+ super.onVisibilityAggregated(isVisible);
109
+ maybeOverrideVisibilityHandling();
110
+ }
111
+
112
+ private void maybeOverrideVisibilityHandling() {
113
+ if (mLegacyVisibilityHandlingEnabled) {
114
+ Drawable drawable = getDrawable();
115
+ if (drawable != null) {
116
+ drawable.setVisible(getVisibility() == VISIBLE, false);
117
+ }
118
+ }
119
+ }
120
+
121
+ public void setLegacyVisibilityHandlingEnabled(boolean legacyVisibilityHandlingEnabled) {
122
+ mLegacyVisibilityHandlingEnabled = legacyVisibilityHandlingEnabled;
123
+ }
124
+
58
125
  // private final Rect outlineRect = new RectF();
59
126
  public void updateOutlineProvider() {
60
127
  Drawable drawable = getBackground();
@@ -136,33 +136,33 @@ public class ScalingUtils {
136
136
  }
137
137
  @Override
138
138
  public Matrix getTransform(
139
- Matrix outTransform,
140
- Rect parentRect,
141
- int childWidth,
142
- int childHeight,
143
- float focusX,
144
- float focusY) {
145
- float sX = (float) parentRect.width() / (float) childWidth;
146
- float sY = (float) parentRect.height() / (float) childHeight;
147
- float rotationDelta = (90 - (_imageRotation % 180))/90.0f;
148
- if (rotationDelta != 1) {
149
- float destSX = (float) parentRect.width() / (float) childHeight;
150
- float destSY = (float) parentRect.height() / (float) childWidth;
151
- if (rotationDelta < 0) {
152
- sX = destSX + rotationDelta * (destSX - sX);
153
- sY = destSY + rotationDelta * (destSY - sY);
154
- } else {
155
- sX = sX + (1 - rotationDelta) * (destSX - sX);
156
- sY = sY + (1 - rotationDelta) * (destSY - sY);
157
- }
158
-
159
- }
160
- getTransformImpl(outTransform, parentRect, childWidth, childHeight, focusX, focusY, sX, sY);
161
- if (_imageMatrix != null) {
162
- outTransform.preConcat(_imageMatrix);
163
- } else if (_imageRotation != 0) {
164
- outTransform.preRotate(_imageRotation, childWidth / 2.0f, childHeight / 2.0f);
139
+ Matrix outTransform,
140
+ Rect parentRect,
141
+ int childWidth,
142
+ int childHeight,
143
+ float focusX,
144
+ float focusY) {
145
+ float sX = (float) parentRect.width() / (float) childWidth;
146
+ float sY = (float) parentRect.height() / (float) childHeight;
147
+ float rotationDelta = (90 - (_imageRotation % 180))/90.0f;
148
+ if (rotationDelta != 1) {
149
+ float destSX = (float) parentRect.width() / (float) childHeight;
150
+ float destSY = (float) parentRect.height() / (float) childWidth;
151
+ if (rotationDelta < 0) {
152
+ sX = destSX + rotationDelta * (destSX - sX);
153
+ sY = destSY + rotationDelta * (destSY - sY);
154
+ } else {
155
+ sX = sX + (1 - rotationDelta) * (destSX - sX);
156
+ sY = sY + (1 - rotationDelta) * (destSY - sY);
165
157
  }
158
+
159
+ }
160
+ getTransformImpl(outTransform, parentRect, childWidth, childHeight, focusX, focusY, sX, sY, rotationDelta);
161
+ if (_imageMatrix != null) {
162
+ outTransform.preConcat(_imageMatrix);
163
+ } else if (_imageRotation != 0) {
164
+ outTransform.preRotate(_imageRotation, childWidth / 2.0f, childHeight / 2.0f);
165
+ }
166
166
 
167
167
  return outTransform;
168
168
  }
@@ -175,7 +175,8 @@ public class ScalingUtils {
175
175
  float focusX,
176
176
  float focusY,
177
177
  float scaleX,
178
- float scaleY);
178
+ float scaleY,
179
+ float rotationDelta);
179
180
  }
180
181
 
181
182
  public static class ScaleTypeFitXY extends AbstractScaleType {
@@ -191,10 +192,14 @@ public class ScalingUtils {
191
192
  float focusX,
192
193
  float focusY,
193
194
  float scaleX,
194
- float scaleY) {
195
- float dx = parentRect.left;
196
- float dy = parentRect.top;
195
+ float scaleY,
196
+ float rotationDelta) {
197
+ float deltaX = ((rotationDelta != 1) ? (childWidth - childHeight) * scaleX/ 2.0f : 0.0f);
198
+ float deltaY = ((rotationDelta != 1) ? (childWidth - childHeight) * scaleY/ 2.0f : 0.0f);
199
+ float dx = parentRect.left - deltaX;
200
+ float dy = parentRect.top + deltaY;
197
201
  outTransform.setScale(scaleX, scaleY);
202
+
198
203
  outTransform.postTranslate((int) (dx + 0.5f), (int) (dy + 0.5f));
199
204
  }
200
205
 
@@ -217,10 +222,13 @@ public class ScalingUtils {
217
222
  float focusX,
218
223
  float focusY,
219
224
  float scaleX,
220
- float scaleY) {
225
+ float scaleY,
226
+ float rotationDelta) {
221
227
  float scale = Math.min(scaleX, scaleY);
222
- float dx = parentRect.left;
223
- float dy = parentRect.top;
228
+ float delta = ((rotationDelta != 1) ? (childWidth - childHeight) * scale/ 2.0f : 0.0f);
229
+
230
+ float dx = parentRect.left - delta;
231
+ float dy = parentRect.top + delta;
224
232
  outTransform.setScale(scale, scale);
225
233
  outTransform.postTranslate((int) (dx + 0.5f), (int) (dy + 0.5f));
226
234
  }
@@ -244,7 +252,8 @@ public class ScalingUtils {
244
252
  float focusX,
245
253
  float focusY,
246
254
  float scaleX,
247
- float scaleY) {
255
+ float scaleY,
256
+ float rotationDelta) {
248
257
  float scale = Math.min(scaleX, scaleY);
249
258
  float dx = parentRect.left;
250
259
  float dy = parentRect.top + (parentRect.height() - childHeight * scale);
@@ -271,7 +280,8 @@ public class ScalingUtils {
271
280
  float focusX,
272
281
  float focusY,
273
282
  float scaleX,
274
- float scaleY) {
283
+ float scaleY,
284
+ float rotationDelta) {
275
285
  float scale = Math.min(scaleX, scaleY);
276
286
  float dx = parentRect.left + (parentRect.width() - childWidth * scale) * 0.5f;
277
287
  float dy = parentRect.top + (parentRect.height() - childHeight * scale) * 0.5f;
@@ -298,10 +308,12 @@ public class ScalingUtils {
298
308
  float focusX,
299
309
  float focusY,
300
310
  float scaleX,
301
- float scaleY) {
311
+ float scaleY,
312
+ float rotationDelta) {
302
313
  float scale = Math.min(scaleX, scaleY);
303
- float dx = parentRect.left + (parentRect.width() - childWidth * scale);
304
- float dy = parentRect.top + (parentRect.height() - childHeight * scale);
314
+ float delta = ((rotationDelta != 1) ? (childWidth - childHeight) * scale/ 2.0f : 0.0f);
315
+ float dx = parentRect.left + (parentRect.width() - childWidth * scale) + delta;
316
+ float dy = parentRect.top + (parentRect.height() - childHeight * scale) - delta;
305
317
  outTransform.setScale(scale, scale);
306
318
  outTransform.postTranslate((int) (dx + 0.5f), (int) (dy + 0.5f));
307
319
  }
@@ -325,7 +337,8 @@ public class ScalingUtils {
325
337
  float focusX,
326
338
  float focusY,
327
339
  float scaleX,
328
- float scaleY) {
340
+ float scaleY,
341
+ float rotationDelta) {
329
342
  float dx = parentRect.left + (parentRect.width() - childWidth) * 0.5f;
330
343
  float dy = parentRect.top + (parentRect.height() - childHeight) * 0.5f;
331
344
  outTransform.setTranslate((int) (dx + 0.5f), (int) (dy + 0.5f));
@@ -350,7 +363,8 @@ public class ScalingUtils {
350
363
  float focusX,
351
364
  float focusY,
352
365
  float scaleX,
353
- float scaleY) {
366
+ float scaleY,
367
+ float rotationDelta) {
354
368
  float scale = Math.min(Math.min(scaleX, scaleY), 1.0f);
355
369
  float dx = parentRect.left + (parentRect.width() - childWidth * scale) * 0.5f;
356
370
  float dy = parentRect.top + (parentRect.height() - childHeight * scale) * 0.5f;
@@ -377,15 +391,16 @@ public class ScalingUtils {
377
391
  float focusX,
378
392
  float focusY,
379
393
  float scaleX,
380
- float scaleY) {
394
+ float scaleY,
395
+ float rotationDelta) {
381
396
  float scale, dx, dy;
382
397
  if (scaleY > scaleX) {
383
398
  scale = scaleY;
384
399
  dx = parentRect.left + (parentRect.width() - childWidth * scale) * 0.5f;
385
- dy = parentRect.top;
400
+ dy = parentRect.top + (parentRect.height() - childHeight * scale) * 0.5f;
386
401
  } else {
387
402
  scale = scaleX;
388
- dx = parentRect.left;
403
+ dx = parentRect.left + (parentRect.width() - childWidth * scale) * 0.5f;
389
404
  dy = parentRect.top + (parentRect.height() - childHeight * scale) * 0.5f;
390
405
  }
391
406
  outTransform.setScale(scale, scale);
@@ -411,16 +426,21 @@ public class ScalingUtils {
411
426
  float focusX,
412
427
  float focusY,
413
428
  float scaleX,
414
- float scaleY) {
415
- float scale, dx, dy;
429
+ float scaleY,
430
+ float rotationDelta) {
431
+ float scale, dx, dy, delta;
416
432
  if (scaleY > scaleX) {
417
433
  scale = scaleY;
434
+ delta = ((rotationDelta != 1) ? (childWidth - childHeight) * scale/ 2.0f : 0.0f);
418
435
  dx = parentRect.width() * 0.5f - childWidth * scale * focusX;
419
436
  dx = parentRect.left + Math.max(Math.min(dx, 0), parentRect.width() - childWidth * scale);
420
- dy = parentRect.top;
437
+ dy = parentRect.height() * 0.5f - childHeight * scale * focusY;
438
+ dy = parentRect.top + Math.max(Math.min(dy, 0), parentRect.height() - childHeight * scale) - delta;
421
439
  } else {
422
440
  scale = scaleX;
423
- dx = parentRect.left;
441
+ delta = ((rotationDelta != 1) ? (childWidth - childHeight) * scale: 0.0f);
442
+ dx = parentRect.width() * 0.5f - childWidth * scale * focusX;
443
+ dx = parentRect.left + Math.max(Math.min(dx, 0), parentRect.width() - childWidth * scale) + Math.min(delta / 2.0f, 0.0f);
424
444
  dy = parentRect.height() * 0.5f - childHeight * scale * focusY;
425
445
  dy = parentRect.top + Math.max(Math.min(dy, 0), parentRect.height() - childHeight * scale);
426
446
  }
@@ -447,7 +467,8 @@ public class ScalingUtils {
447
467
  float focusX,
448
468
  float focusY,
449
469
  float scaleX,
450
- float scaleY) {
470
+ float scaleY,
471
+ float rotationDelta) {
451
472
  float scale, dx, dy;
452
473
  scale = scaleX;
453
474
  dx = parentRect.left;
@@ -475,7 +496,8 @@ public class ScalingUtils {
475
496
  float focusX,
476
497
  float focusY,
477
498
  float scaleX,
478
- float scaleY) {
499
+ float scaleY,
500
+ float rotationDelta) {
479
501
  float scale, dx, dy;
480
502
  scale = scaleY;
481
503
  dx = parentRect.left + (parentRect.width() - childWidth * scale) * 0.5f;
Binary file