Skip to content

Commit b7d340f

Browse files
authored
fix(ios): Color.fromIosColor returns wrong value (#10059)
1 parent 0f7e4ed commit b7d340f

5 files changed

Lines changed: 29 additions & 3 deletions

File tree

File renamed without changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './color-tests-common';
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import * as android from './color-tests.android';
2+
import * as iOS from './color-tests.ios';
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// >> color-require
2+
import * as colorModule from '@nativescript/core/color';
3+
const { Color } = colorModule;
4+
// << color-require
5+
import * as TKUnit from '../tk-unit';
6+
7+
export * from './color-tests-common';
8+
9+
export function testFromIosColorWhite () {
10+
// >> color-ios-white
11+
// Creates the white color
12+
const color = Color.fromIosColor(UIColor.whiteColor);
13+
// << color-ios-white
14+
TKUnit.assertEqual(color.a, 255, 'Color.a not properly parsed');
15+
TKUnit.assertEqual(color.r, 255, 'Color.r not properly parsed');
16+
TKUnit.assertEqual(color.g, 255, 'Color.g not properly parsed');
17+
TKUnit.assertEqual(color.b, 255, 'Color.b not properly parsed');
18+
TKUnit.assertEqual(color.hex, '#FFFFFF', 'Color.hex not properly parsed');
19+
TKUnit.assertEqual(color.argb, 0xffffffff, 'Color.argb not properly parsed');
20+
};

‎packages/core/color/index.ios.ts‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@ export class Color extends common.Color {
1313
}
1414

1515
public static fromIosColor(value: UIColor): Color {
16-
const rgba = CGColorGetComponents(value.CGColor);
17-
18-
return new Color(Math.round(rgba[3] * 255), Math.round(rgba[0] * 255), Math.round(rgba[1] * 255), Math.round(rgba[2] * 255));
16+
const r = new interop.Reference<number>();
17+
const g = new interop.Reference<number>();
18+
const b = new interop.Reference<number>();
19+
const a = new interop.Reference<number>();
20+
value.getRedGreenBlueAlpha(r, g, b, a);
21+
return new Color(Math.round(a.value * 255), Math.round(r.value * 255), Math.round(g.value * 255), Math.round(b.value * 255));
1922
}
2023
}

0 commit comments

Comments
 (0)