@@ -340,17 +340,26 @@ export class Img extends ImageBase {
340340 // if (Trace.isEnabled()) {
341341 // CLog(CLogTypes.info, 'onMeasure', this.src, widthMeasureSpec, heightMeasureSpec, width, height, this.aspectRatio, image && image.imageOrientation);
342342 // }
343- if ( image || this . aspectRatio > 0 || ! this . noRatioEnforce ) {
343+ if ( image || this . aspectRatio > 0 ) {
344344 const nativeWidth = image ? layout . toDevicePixels ( image . size . width ) : 0 ;
345345 const nativeHeight = image ? layout . toDevicePixels ( image . size . height ) : 0 ;
346346 const imgRatio = nativeWidth / nativeHeight ;
347347 const ratio = this . aspectRatio || imgRatio ;
348348 // const scale = this.computeScaleFactor(width, height, finiteWidth, finiteHeight, nativeWidth, nativeHeight, this.aspectRatio || imgRatio );
349349
350350 if ( ! finiteWidth && finiteHeight ) {
351- widthMeasureSpec = layout . makeMeasureSpec ( height * ratio , layout . EXACTLY ) ;
352- } else if ( ! finiteHeight && finiteWidth ) {
353- heightMeasureSpec = layout . makeMeasureSpec ( width / ratio , layout . EXACTLY ) ;
351+ if ( ! this . noRatioEnforce || this . horizontalAlignment !== 'stretch' ) {
352+ widthMeasureSpec = layout . makeMeasureSpec ( height * ratio , layout . EXACTLY ) ;
353+ } else {
354+ widthMeasureSpec = layout . makeMeasureSpec ( 0 , layout . AT_MOST ) ;
355+ }
356+ }
357+ else if ( ! finiteHeight && finiteWidth ) {
358+ if ( ! this . noRatioEnforce || this . verticalAlignment !== 'stretch' ) {
359+ heightMeasureSpec = layout . makeMeasureSpec ( width / ratio , layout . EXACTLY ) ;
360+ } else {
361+ heightMeasureSpec = layout . makeMeasureSpec ( 0 , layout . AT_MOST ) ;
362+ }
354363 } else if ( ! finiteWidth && ! finiteHeight ) {
355364 const viewRatio = width / height ;
356365 if ( viewRatio < ratio ) {
@@ -366,11 +375,11 @@ export class Img extends ImageBase {
366375 CLog ( CLogTypes . info , 'onMeasure' , this . src , this . aspectRatio , finiteWidth , finiteHeight , width , height , nativeWidth , nativeHeight , widthMeasureSpec , heightMeasureSpec ) ;
367376 }
368377 } else {
369- if ( ! finiteWidth && finiteHeight ) {
370- widthMeasureSpec = layout . makeMeasureSpec ( 0 , layout . AT_MOST ) ;
371- } else if ( ! finiteHeight && finiteWidth ) {
372- heightMeasureSpec = layout . makeMeasureSpec ( 0 , layout . AT_MOST ) ;
373- }
378+ // if (!finiteWidth && finiteHeight) {
379+ // widthMeasureSpec = layout.makeMeasureSpec(0, layout.UNSPECIFIED );
380+ // } else if (!finiteHeight && finiteWidth) {
381+ // heightMeasureSpec = layout.makeMeasureSpec(0, layout.UNSPECIFIED );
382+ // }
374383 }
375384 super . onMeasure ( widthMeasureSpec , heightMeasureSpec ) ;
376385 }
0 commit comments