Skip to content
This repository was archived by the owner on Oct 8, 2021. It is now read-only.
Merged
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
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