Skip to content

Commit 0d21f52

Browse files
author
Hristo Hristov
authored
Hhristov/ios background image crash fix (NativeScript#4214)
* uiColorFromImage should return if there is no image. * added unit-test
1 parent cbbee3b commit 0d21f52

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

tests/app/ui/view/view-tests-common.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ export function test_InheritableStylePropertiesWhenUsedWithExtendedClass_AreInhe
249249
page.content = newButton;
250250

251251
TKUnit.assertEqual(newButton.style.color, redColor);
252-
};
252+
}
253253

254254
// TestView definition START
255255
const customCssProperty = new CssProperty<Style, string>({ name: "customCssProperty", cssName: "custom-css-property" });
@@ -919,3 +919,11 @@ export function test_getActualSize() {
919919
TKUnit.assertAreClose(actualSize.height, 200, delta, "actualSize.height");
920920
});
921921
};
922+
923+
export function test_background_image_doesnt_throw() {
924+
var btn = new Button();
925+
btn.style.backgroundImage = 'https://www.bodybuilding.com/images/2016/june/8-benefits-to-working-out-in-the-morning-header-v2-830x467.jpg';
926+
helper.buildUIAndRunTest(btn, function (views: Array<View>) {
927+
TKUnit.waitUntilReady(() => btn.isLayoutValid);
928+
});
929+
}

tns-core-modules/ui/styling/background.ios.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ function getDrawParams(this: void, image: UIImage, background: BackgroundDefinit
262262
function uiColorFromImage(img: UIImage, view: View, callback: (uiColor: UIColor) => void, flip?: boolean): void {
263263
if (!img) {
264264
callback(null);
265+
return;
265266
}
266267

267268
const nativeView = view.nativeView as UIView;

0 commit comments

Comments
 (0)