From 4e678a06fffae855116216b9d10e36d5e6bf0472 Mon Sep 17 00:00:00 2001 From: Rossen Hristov Date: Tue, 14 Jun 2016 10:39:44 +0300 Subject: [PATCH] Fix: Images have margin when added to Layout Resolves #1425 --- .gitignore | 2 ++ tests/app/ui/image/700x50.png | Bin 0 -> 808 bytes tests/app/ui/image/image-tests.ts | 21 +++++++++++++++++++++ tns-core-modules/ui/image/image.ios.ts | 4 ++-- 4 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 tests/app/ui/image/700x50.png diff --git a/.gitignore b/.gitignore index 47283ca42..23f3bc4ef 100644 --- a/.gitignore +++ b/.gitignore @@ -42,3 +42,5 @@ tns-core-modules.es6.d.ts tests/platforms/ tests/lib/ *.log + +.DS_Store \ No newline at end of file diff --git a/tests/app/ui/image/700x50.png b/tests/app/ui/image/700x50.png new file mode 100644 index 0000000000000000000000000000000000000000..50d6362055be174ae98d77b1431c947416d61370 GIT binary patch literal 808 zcmeAS@N?(olHy`uVBq!ia0y~yVA=y@8*wlJNyESMrvfR);vjb?hIQv;UIIBR>5jgR z3=A9lx&I`x0{NT;9+AZi419+{nDKc2iWHy`dp%toLn`9l-q{=a#6W^IV3*<|MlOZr ztV~5kT{BvY6qc}OEszkK@MfdUw;zQcs=mv_&y{ZYA)$HsGJj0Xo;{2VIzmzm4ILL4 z7+hM|7!;ID7#IW>GBR{<@G>~KWH2x&IWaQ`2qKh}J^fiwX?Q;`zWt~_|Mji^ci)xi zvwx*(x|#3$*Xy^+ektykVofl0V%|Net?m2n)wj%Zrt`l)-rtpVuFL80dUwW%-U|%* z^8MS-dfj>Z=DqyxrghJMy{o)Zye`d=llSe%V<)&4GpupTXsG&gLI2EpbK%uRcR!XN zR9YFiNk;0L1jJ}_tF#r8k6wK+S@APu`;XM#_;oX5Zrv8xAR#qrCPR*UM#B43PIWf_ z=f|G*u8%x4c~(_Jp^dsm_g_P|DUX)%F1si`N1ipo+KKsh*{Ha`H?{pW;HsALcD=WjRHm zai%6Ew)b@_cHL-^0E(Um>Itvsx$sS0pR?}Mtpzq)Vyx0MZfX8a5oy@(pOLWr*|d8z zYil;Y_s{Aw^2$7Yx~95&Vn5Rc)`g98XIZBGF#34m;S#%*KSNHvlRwXE9`N31(SM1J z9|9R(3rpQtUd3?XUuW|2-2oQ=zL?v7)jX^rP~*G6mwD@g%3l+Dm^O$mY>dsC_L(!a z+dl8@v$~bfp8Q(8?)%fI#EM+QoX4j-Qq&l33rO8q_)+)3k}B>CTTebRHl1wFZOV8> yb-#7gi`zaT9%)P)81cnE5ebB7C5_X!+t)r}+qE&zwGNoN89ZJ6T-G@yGywo)hDTcf literal 0 HcmV?d00001 diff --git a/tests/app/ui/image/image-tests.ts b/tests/app/ui/image/image-tests.ts index e638b441f..f21d5bf18 100644 --- a/tests/app/ui/image/image-tests.ts +++ b/tests/app/ui/image/image-tests.ts @@ -3,6 +3,7 @@ import {StackLayout} from "ui/layouts/stack-layout"; import {GridLayout} from "ui/layouts/grid-layout"; import {isIOS} from "platform"; import {PropertyChangeData} from "data/observable"; +import utils = require("utils/utils"); // import {target} from "../../TKUnit"; @@ -334,3 +335,23 @@ export var test_SettingImageSourceWhenSizedToContentShouldInvalidate = ios(() => TKUnit.assertTrue(called, "image.requestLayout should be called."); }); +export var test_DimensionsAreRoundedAfterScale = function() { + let host = new StackLayout(); + let image = new Image(); + image.src = "~/ui/image/700x50.png"; + + let density = utils.layout.getDisplayDensity(); + let limit = 414; + host.width = limit / density; + host.height = limit / density; + host.addChild(image); + let mainPage = helper.getCurrentPage(); + mainPage.content = host; + TKUnit.waitUntilReady(() => host.isLoaded); + TKUnit.waitUntilReady(() => image.isLayoutValid); + + let scale = limit / 700; + let expectedHeight = Math.round(50 * scale); + TKUnit.assertEqual(image.getMeasuredWidth(), limit, "Actual width is different from expected width."); + TKUnit.assertEqual(image.getMeasuredHeight(), expectedHeight, "Actual height is different from expected height."); +}; \ No newline at end of file diff --git a/tns-core-modules/ui/image/image.ios.ts b/tns-core-modules/ui/image/image.ios.ts index bd05df790..cf82e25aa 100644 --- a/tns-core-modules/ui/image/image.ios.ts +++ b/tns-core-modules/ui/image/image.ios.ts @@ -83,8 +83,8 @@ export class Image extends imageCommon.Image { if (nativeWidth !== 0 && nativeHeight !== 0 && (finiteWidth || finiteHeight)) { var scale = Image.computeScaleFactor(width, height, finiteWidth, finiteHeight, nativeWidth, nativeHeight, this.stretch); - var resultW = Math.floor(nativeWidth * scale.width); - var resultH = Math.floor(nativeHeight * scale.height); + var resultW = Math.round(nativeWidth * scale.width); + var resultH = Math.round(nativeHeight * scale.height); measureWidth = finiteWidth ? Math.min(resultW, width) : resultW; measureHeight = finiteHeight ? Math.min(resultH, height) : resultH;