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

Emulate toHex function of core art Color #44

Closed
wants to merge 0 commits into from
Closed

Emulate toHex function of core art Color #44

wants to merge 0 commits into from

Conversation

danielwinkler
Copy link

Summary

Test Plan

What's required for testing (prerequisites)?

What are the steps to reproduce (after prerequisites)?

Compatibility

OS Implemented
iOS
Android

Checklist

  • I have tested this on a device and a simulator
  • I added the documentation in README.md
  • I mentioned this change in CHANGELOG.md
  • I updated the typed files (TS and Flow)
  • I added a sample use of the API in the example project (example/App.js)

@danielwinkler
Copy link
Author

I added further code, as Android is using AARRGGBB hex vs iOS RRGGBBAA
see https://developer.android.com/reference/android/graphics/Color.html#parseColor(java.lang.String)

lib/helpers.js Outdated
Comment on lines 82 to 93
const intValues = [c.red, c.green, c.blue];
if (c.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(c.alpha * 255));
}
const hexValues = intValues.map(iv => {
const sv = iv.toString(16);
return sv.length === 1 ? '0' + sv : sv;
});
return '#' + hexValues.join('');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you extract this thing to a separate function called toHex?

@Esemesek Esemesek closed this Dec 18, 2019
@Esemesek
Copy link
Collaborator

It seems like I managed to mess up things by mistake. Didn't mean to push with force here. I will create another PR with those changes.

@Esemesek Esemesek mentioned this pull request Dec 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants