Skip to content
This repository has been archived by the owner on Oct 8, 2021. It is now read-only.

Commit

Permalink
fix: toHex not working (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
Esemesek authored Dec 18, 2019
1 parent 9da53ee commit 433b49e
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import Color from 'art/core/color';
import Transform from 'art/core/transform';
import {Platform} from 'react-native';
import type {
Alignment,
Brush,
Expand Down Expand Up @@ -73,12 +74,26 @@ export function extractTransform(props: TransformProps): Array<number> {
];
}

function toHex(color: Color) {
const intValues = [color.red, color.green, color.blue];
if (color.alpha < 1) {
// Android uses AARRGGBB ; iOS uses RRGGBBAA
// https://developer.android.com/reference/android/graphics/Color.html#parseColor(java.lang.String)
const position = Platform.OS === 'android' ? 0 : 3;
intValues.splice(position, 0, Math.round(color.alpha * 255));
}
const hexValues = intValues.map(iv => {
const sv = iv.toString(16);
return sv.length === 1 ? '0' + sv : sv;
});
return '#' + hexValues.join('');
}

export function extractColor(color?: ColorType) {
if (color == null) {
return null;
}
const c = new Color(color);
return c.toHEX();
return toHex(new Color(color));
}

export function extractStrokeJoin(strokeJoin?: StrokeJoin) {
Expand Down

0 comments on commit 433b49e

Please sign in to comment.