@nativescript-community/ui-image 4.3.21 → 4.3.22
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 +6 -0
- package/index.android.d.ts +2 -1
- package/index.android.js +29 -3
- package/index.ios.js +13 -2
- package/package.json +2 -2
- package/platforms/android/java/com/nativescript/image/DraweeView.java +20 -4
- package/platforms/android/java/com/nativescript/image/ScalingUtils.java +4 -0
- package/platforms/android/ui_image.aar +0 -0
package/CHANGELOG.md
CHANGED
@@ -3,6 +3,12 @@
|
|
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.22](https://github.com/nativescript-community/ui-image/compare/v4.3.21...v4.3.22) (2023-11-17)
|
7
|
+
|
8
|
+
### Bug Fixes
|
9
|
+
|
10
|
+
* edge cases auto measurement fix ([dff9f29](https://github.com/nativescript-community/ui-image/commit/dff9f293f22f36641bd623fd8df3a5799ad14ffa))
|
11
|
+
|
6
12
|
## [4.3.21](https://github.com/nativescript-community/ui-image/compare/v4.3.20...v4.3.21) (2023-11-09)
|
7
13
|
|
8
14
|
**Note:** Version bump only for package @nativescript-community/ui-image
|
package/index.android.d.ts
CHANGED
@@ -62,13 +62,14 @@ export declare class FailureEventData extends EventData {
|
|
62
62
|
get error(): ImageError;
|
63
63
|
set error(value: ImageError);
|
64
64
|
}
|
65
|
-
export declare const needUpdateHierarchy: (
|
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;
|
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 (
|
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) {
|
@@ -747,7 +773,7 @@ __decorate([
|
|
747
773
|
needUpdateHierarchy
|
748
774
|
], Img.prototype, _j, null);
|
749
775
|
__decorate([
|
750
|
-
needUpdateHierarchy
|
776
|
+
needUpdateHierarchy(true)
|
751
777
|
], Img.prototype, _k, null);
|
752
778
|
__decorate([
|
753
779
|
needUpdateHierarchy
|
@@ -778,7 +804,7 @@ __decorate([
|
|
778
804
|
], Img.prototype, _u, null);
|
779
805
|
class GenericDraweeHierarchyBuilder {
|
780
806
|
constructor() {
|
781
|
-
const res = Utils.
|
807
|
+
const res = Utils.android.getApplicationContext().getResources();
|
782
808
|
this.nativeBuilder = new com.facebook.drawee.generic.GenericDraweeHierarchyBuilder(res);
|
783
809
|
}
|
784
810
|
setPlaceholderImage(drawable, scaleType) {
|
package/index.ios.js
CHANGED
@@ -252,12 +252,23 @@ export class Img extends ImageBase {
|
|
252
252
|
const imgRatio = nativeWidth / nativeHeight;
|
253
253
|
const ratio = this.aspectRatio || imgRatio;
|
254
254
|
// const scale = this.computeScaleFactor(width, height, finiteWidth, finiteHeight, nativeWidth, nativeHeight, this.aspectRatio || imgRatio );
|
255
|
-
if (!finiteWidth) {
|
255
|
+
if (!finiteWidth && finiteHeight) {
|
256
256
|
widthMeasureSpec = layout.makeMeasureSpec(height * ratio, layout.EXACTLY);
|
257
257
|
}
|
258
|
-
if (!finiteHeight) {
|
258
|
+
else if (!finiteHeight && finiteWidth) {
|
259
259
|
heightMeasureSpec = layout.makeMeasureSpec(width / ratio, layout.EXACTLY);
|
260
260
|
}
|
261
|
+
else if (!finiteWidth && !finiteHeight) {
|
262
|
+
const viewRatio = width / height;
|
263
|
+
if (viewRatio < ratio) {
|
264
|
+
widthMeasureSpec = layout.makeMeasureSpec(width, layout.EXACTLY);
|
265
|
+
heightMeasureSpec = layout.makeMeasureSpec((width / ratio), layout.EXACTLY);
|
266
|
+
}
|
267
|
+
else {
|
268
|
+
widthMeasureSpec = layout.makeMeasureSpec((height * ratio), layout.EXACTLY);
|
269
|
+
heightMeasureSpec = layout.makeMeasureSpec(height, layout.EXACTLY);
|
270
|
+
}
|
271
|
+
}
|
261
272
|
if (Trace.isEnabled()) {
|
262
273
|
CLog(CLogTypes.info, 'onMeasure scale', this.src, this.aspectRatio, finiteWidth, finiteHeight, width, height, nativeWidth, nativeHeight, widthMeasureSpec, heightMeasureSpec);
|
263
274
|
}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@nativescript-community/ui-image",
|
3
|
-
"version": "4.3.
|
3
|
+
"version": "4.3.22",
|
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": "
|
47
|
+
"gitHead": "3fe49515ffcfabf813d3be28cd679a6c1acba778"
|
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
|
-
|
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
|