Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/automated/src/color/color-tests.android.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './color-tests-common';
2 changes: 2 additions & 0 deletions apps/automated/src/color/color-tests.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import * as android from './color-tests.android';
import * as iOS from './color-tests.ios';
20 changes: 20 additions & 0 deletions apps/automated/src/color/color-tests.ios.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// >> color-require
import * as colorModule from '@nativescript/core/color';
const { Color } = colorModule;
// << color-require
import * as TKUnit from '../tk-unit';

export * from './color-tests-common';

export function testFromIosColorWhite () {
// >> color-ios-white
// Creates the white color
const color = Color.fromIosColor(UIColor.whiteColor);
// << color-ios-white
TKUnit.assertEqual(color.a, 255, 'Color.a not properly parsed');
TKUnit.assertEqual(color.r, 255, 'Color.r not properly parsed');
TKUnit.assertEqual(color.g, 255, 'Color.g not properly parsed');
TKUnit.assertEqual(color.b, 255, 'Color.b not properly parsed');
TKUnit.assertEqual(color.hex, '#FFFFFF', 'Color.hex not properly parsed');
TKUnit.assertEqual(color.argb, 0xffffffff, 'Color.argb not properly parsed');
};
9 changes: 6 additions & 3 deletions packages/core/color/index.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ export class Color extends common.Color {
}

public static fromIosColor(value: UIColor): Color {
const rgba = CGColorGetComponents(value.CGColor);

return new Color(Math.round(rgba[3] * 255), Math.round(rgba[0] * 255), Math.round(rgba[1] * 255), Math.round(rgba[2] * 255));
const r = new interop.Reference<number>();
const g = new interop.Reference<number>();
const b = new interop.Reference<number>();
const a = new interop.Reference<number>();
value.getRedGreenBlueAlpha(r, g, b, a);
return new Color(Math.round(a.value * 255), Math.round(r.value * 255), Math.round(g.value * 255), Math.round(b.value * 255));
}
}