mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-15 02:54:11 +08:00
fix(ios): Color.fromIosColor returns wrong value (#10059)
This commit is contained in:
1
apps/automated/src/color/color-tests.android.ts
Normal file
1
apps/automated/src/color/color-tests.android.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
export * from './color-tests-common';
|
2
apps/automated/src/color/color-tests.d.ts
vendored
Normal file
2
apps/automated/src/color/color-tests.d.ts
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
import * as android from './color-tests.android';
|
||||||
|
import * as iOS from './color-tests.ios';
|
20
apps/automated/src/color/color-tests.ios.ts
Normal file
20
apps/automated/src/color/color-tests.ios.ts
Normal file
@ -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');
|
||||||
|
};
|
@ -13,8 +13,11 @@ export class Color extends common.Color {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static fromIosColor(value: UIColor): Color {
|
public static fromIosColor(value: UIColor): Color {
|
||||||
const rgba = CGColorGetComponents(value.CGColor);
|
const r = new interop.Reference<number>();
|
||||||
|
const g = new interop.Reference<number>();
|
||||||
return new Color(Math.round(rgba[3] * 255), Math.round(rgba[0] * 255), Math.round(rgba[1] * 255), Math.round(rgba[2] * 255));
|
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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user