(widthMeasureSpec: number, heightMeasureSpec: number)
| 90 | } |
| 91 | |
| 92 | public onMeasure(widthMeasureSpec: number, heightMeasureSpec: number): void { |
| 93 | // We don't call super because we measure native view with specific size. |
| 94 | const width = layout.getMeasureSpecSize(widthMeasureSpec); |
| 95 | const widthMode = layout.getMeasureSpecMode(widthMeasureSpec); |
| 96 | |
| 97 | const height = layout.getMeasureSpecSize(heightMeasureSpec); |
| 98 | const heightMode = layout.getMeasureSpecMode(heightMeasureSpec); |
| 99 | |
| 100 | const nativeWidth = this.imageSource ? layout.toDevicePixels(this.imageSource.width) : 0; |
| 101 | const nativeHeight = this.imageSource ? layout.toDevicePixels(this.imageSource.height) : 0; |
| 102 | |
| 103 | let measureWidth = Math.max(nativeWidth, this.effectiveMinWidth); |
| 104 | let measureHeight = Math.max(nativeHeight, this.effectiveMinHeight); |
| 105 | |
| 106 | const finiteWidth: boolean = widthMode !== layout.UNSPECIFIED; |
| 107 | const finiteHeight: boolean = heightMode !== layout.UNSPECIFIED; |
| 108 | |
| 109 | this._imageSourceAffectsLayout = widthMode !== layout.EXACTLY || heightMode !== layout.EXACTLY; |
| 110 | |
| 111 | if (nativeWidth !== 0 && nativeHeight !== 0 && (finiteWidth || finiteHeight)) { |
| 112 | const scale = Image.computeScaleFactor(width, height, finiteWidth, finiteHeight, nativeWidth, nativeHeight, this.stretch); |
| 113 | const resultW = Math.round(nativeWidth * scale.width); |
| 114 | const resultH = Math.round(nativeHeight * scale.height); |
| 115 | |
| 116 | measureWidth = finiteWidth ? Math.min(resultW, width) : resultW; |
| 117 | measureHeight = finiteHeight ? Math.min(resultH, height) : resultH; |
| 118 | |
| 119 | if (Trace.isEnabled()) { |
| 120 | Trace.write('Image stretch: ' + this.stretch + ', nativeWidth: ' + nativeWidth + ', nativeHeight: ' + nativeHeight, Trace.categories.Layout); |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | const widthAndState = Image.resolveSizeAndState(measureWidth, width, widthMode, 0); |
| 125 | const heightAndState = Image.resolveSizeAndState(measureHeight, height, heightMode, 0); |
| 126 | |
| 127 | this.setMeasuredDimension(widthAndState, heightAndState); |
| 128 | } |
| 129 | |
| 130 | private static computeScaleFactor(measureWidth: number, measureHeight: number, widthIsFinite: boolean, heightIsFinite: boolean, nativeWidth: number, nativeHeight: number, imageStretch: string): { width: number; height: number } { |
| 131 | let scaleW = 1; |
nothing calls this directly
no test coverage detected