MCPcopy Create free account
hub / github.com/NativeScript/NativeScript / computeScaleFactor

Method computeScaleFactor

packages/core/ui/image/index.ios.ts:130–158  ·  view source on GitHub ↗
(measureWidth: number, measureHeight: number, widthIsFinite: boolean, heightIsFinite: boolean, nativeWidth: number, nativeHeight: number, imageStretch: string)

Source from the content-addressed store, hash-verified

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;
132 let scaleH = 1;
133
134 if ((imageStretch === 'aspectFill' || imageStretch === 'aspectFit' || imageStretch === 'fill') && (widthIsFinite || heightIsFinite)) {
135 scaleW = nativeWidth > 0 ? measureWidth / nativeWidth : 0;
136 scaleH = nativeHeight > 0 ? measureHeight / nativeHeight : 0;
137
138 if (!widthIsFinite) {
139 scaleW = scaleH;
140 } else if (!heightIsFinite) {
141 scaleH = scaleW;
142 } else {
143 // No infinite dimensions.
144 switch (imageStretch) {
145 case 'aspectFit':
146 scaleH = scaleW < scaleH ? scaleW : scaleH;
147 scaleW = scaleH;
148 break;
149 case 'aspectFill':
150 scaleH = scaleW > scaleH ? scaleW : scaleH;
151 scaleW = scaleH;
152 break;
153 }
154 }
155 }
156
157 return { width: scaleW, height: scaleH };
158 }
159
160 [stretchProperty.setNative](value: 'none' | 'aspectFill' | 'aspectFit' | 'fill') {
161 if (this.nativeViewProtected) {

Callers 1

onMeasureMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected