Skip to content

Commit 8ac3003

Browse files
committed
fix: simplify ratio computation
1 parent fa5d8fb commit 8ac3003

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

src/image-common.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ export class ImageBase extends View {
133133
public static lowerResSrcProperty = new Property<ImageBase, string>({ name: 'lowerResSrc' });
134134
public static placeholderImageUriProperty = new Property<ImageBase, string>({ name: 'placeholderImageUri' });
135135
public static failureImageUriProperty = new Property<ImageBase, string>({ name: 'failureImageUri' });
136-
public static stretchProperty = new Property<ImageBase, string>({ name: 'stretch', defaultValue:'aspectFit' });
136+
public static stretchProperty = new Property<ImageBase, string>({ name: 'stretch', defaultValue: 'aspectFit' });
137137
public static backgroundUriProperty = new Property<ImageBase, string>({ name: 'backgroundUri' });
138138
public static progressiveRenderingEnabledProperty = new Property<ImageBase, boolean>({ name: 'progressiveRenderingEnabled', valueConverter: booleanConverter });
139139
public static localThumbnailPreviewsEnabledProperty = new Property<ImageBase, boolean>({ name: 'localThumbnailPreviewsEnabled', valueConverter: booleanConverter });
@@ -157,8 +157,7 @@ export class ImageBase extends View {
157157
public static fadeDurationProperty = new Property<ImageBase, number>({ name: 'fadeDuration', valueConverter: (v) => parseFloat(v) });
158158
public static noCacheProperty = new Property<ImageBase, boolean>({ name: 'noCache', defaultValue: false, valueConverter: booleanConverter });
159159

160-
protected handleImageProgress(value: number, totalSize?: number) {
161-
}
160+
protected handleImageProgress(value: number, totalSize?: number) {}
162161
private static needsSizeAdjustment(scaleType: ScaleType) {
163162
if (scaleType === undefined) {
164163
return true;
@@ -193,13 +192,14 @@ export class ImageBase extends View {
193192
scaleW = nativeWidth > 0 ? measureWidth / nativeWidth : 1;
194193
scaleH = nativeHeight > 0 ? measureHeight / nativeHeight : 1;
195194

195+
CLog(CLogTypes.info, 'computeScaleFactor', measureWidth, measureHeight, nativeWidth, nativeHeight, widthIsFinite, heightIsFinite, aspectRatio, nativeScale, measureScale);
196196
if (aspectRatio > 0) {
197197
if (!widthIsFinite) {
198198
scaleH = 1;
199199
scaleW = aspectRatio;
200200
} else if (!heightIsFinite) {
201201
scaleW = 1;
202-
scaleH = aspectRatio;
202+
scaleH = 1 / aspectRatio;
203203
}
204204
} else {
205205
if (!widthIsFinite) {

src/image.android.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -355,18 +355,17 @@ function initializeDraweeView() {
355355
if (aspectRatio > 0) {
356356
const finiteWidth: boolean = widthMode === Utils.layout.EXACTLY;
357357
const finiteHeight: boolean = heightMode === Utils.layout.EXACTLY;
358-
let scale: { width; height };
358+
// let scale: { width; height };
359359
if ((this as any).imageWidth && (this as any).imageHeight) {
360-
scale = this.owner.computeScaleFactor(width, height, finiteWidth, finiteHeight, (this as any).imageWidth, (this as any).imageHeight, aspectRatio);
360+
// scale = this.owner.computeScaleFactor(width, height, finiteWidth, finiteHeight, (this as any).imageWidth, (this as any).imageHeight, aspectRatio);
361361
if (!finiteWidth) {
362-
widthMeasureSpec = Utils.layout.makeMeasureSpec(height / scale.width, Utils.layout.EXACTLY);
362+
widthMeasureSpec = Utils.layout.makeMeasureSpec(height * aspectRatio, Utils.layout.EXACTLY);
363363
}
364364
if (!finiteHeight) {
365-
heightMeasureSpec = Utils.layout.makeMeasureSpec(width * scale.height, Utils.layout.EXACTLY);
365+
heightMeasureSpec = Utils.layout.makeMeasureSpec(width / aspectRatio, Utils.layout.EXACTLY);
366366
}
367-
} else {
368367
}
369-
CLog(CLogTypes.info, 'onMeasure scale', this.owner.src, aspectRatio, finiteWidth, finiteHeight, width, height, (this as any).imageWidth, (this as any).imageHeight, scale);
368+
CLog(CLogTypes.info, 'onMeasure scale', this.owner.src, aspectRatio, finiteWidth, finiteHeight, width, height, (this as any).imageWidth, (this as any).imageHeight);
370369
}
371370
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
372371
}

src/image.ios.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -298,21 +298,22 @@ export class Img extends ImageBase {
298298
const finiteWidth: boolean = widthMode === layout.EXACTLY;
299299
const finiteHeight: boolean = heightMode === layout.EXACTLY;
300300
this._imageSourceAffectsLayout = !finiteWidth || !finiteHeight;
301-
const imgRatio = finiteHeight ? nativeWidth/nativeHeight : nativeHeight/nativeWidth;
301+
const imgRatio = nativeWidth / nativeHeight;
302302
CLog(CLogTypes.info, 'onMeasure', this.src, widthMeasureSpec, heightMeasureSpec, width, height, this.aspectRatio, image && image.imageOrientation);
303303
if (image || this.aspectRatio > 0) {
304-
const scale = this.computeScaleFactor(width, height, finiteWidth, finiteHeight, nativeWidth, nativeHeight, this.aspectRatio || imgRatio );
304+
const ratio = this.aspectRatio || imgRatio;
305+
// const scale = this.computeScaleFactor(width, height, finiteWidth, finiteHeight, nativeWidth, nativeHeight, this.aspectRatio || imgRatio );
305306

306307
if (!finiteWidth) {
307-
measureWidth = Math.round(height * scale.width);
308+
measureWidth = Math.round(height * ratio);
308309
} else {
309310

310311
}
311312
if (!finiteHeight) {
312-
measureHeight = Math.round(width * scale.height);
313+
measureHeight = Math.round(width / ratio);
313314
}
314315

315-
CLog(CLogTypes.info, 'onMeasure scale', this.src, this.aspectRatio, finiteWidth, finiteHeight, width, height, nativeWidth, nativeHeight, scale);
316+
CLog(CLogTypes.info, 'onMeasure scale', this.src, this.aspectRatio, finiteWidth, finiteHeight, width, height, nativeWidth, nativeHeight);
316317
}
317318
const widthAndState = Img.resolveSizeAndState(measureWidth, width, widthMode, 0);
318319
const heightAndState = Img.resolveSizeAndState(measureHeight, height, heightMode, 0);

0 commit comments

Comments
 (0)