Nativescript: Why to use NativeScript color module?

Created on 18 Mar 2017  Â·  6Comments  Â·  Source: NativeScript/NativeScript

Hi, I'm confused why do we need to use color module instead of using simply the css color values? Using a module is an extra load to the app. But there might good reason for it.

question

All 6 comments

You typically don't need it unless you need to use colors valid for Android and iOS methods. It's just part of the core, and used in lots of places to make sure your css colors are valid when they're being translated into color values for Android and iOS. There is a method isValid() that determines if a string is valid so the calls to native APIs don't throw exceptions which again your css needs to be valid for a hex to actually use it's native value for the platform APIs. Hope that makes sense :)

This means all css color values are not valid for Android and iOS? Only color values that are defined in color module are valid for Android and iOS?
Thanks for your reply.

No. But let's say you use 'red' as your css color. Well to be used with
native APIs on Android you need to convert that string into a valid hex
color so the color module handles that for you among other things. So it's
an important piece for nativescript to provide css as the connecting piece
to native styling methods on Android and iOS. Since css isn't a real thing
on native platforms :)

On Sat, Mar 18, 2017, 11:11 PM Bhojendra Shah Rauniyar <
[email protected]> wrote:

This means all css color values are not valid for Android and iOS? Only
color values that are defined in color module are valid for Android and iOS?
Thanks for your reply.

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/NativeScript/NativeScript/issues/3823#issuecomment-287593074,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AFulhNfTiqpkbdDlanyEmPy10lTl8I8aks5rnKrygaJpZM4Mhg1E
.

So, if I use hex value then I don't need use color module. Right?

@bini7a - Different use cases could be:

const Color = require("color").Color;
const Label = require("ui/label").Label;
const labelView = new Label();

// When working with NativeScript view modules, a simple hex string is enough
labelView.color = "#ff0000";

// For native views, you may use the Color module
labelView.ios.textColor = new Color("#ff0000").ios;

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings