Skip to content

Commit

Permalink
refactor: add color exmaples
Browse files Browse the repository at this point in the history
  • Loading branch information
NickIliev committed Mar 22, 2018
1 parent fd96131 commit fa9b1ed
Show file tree
Hide file tree
Showing 10 changed files with 133 additions and 1 deletion.
20 changes: 20 additions & 0 deletions app/color/basics/article.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Using `Color` class requires the `tns-core-modules/color` module.

Creating a `Color` from a hex value.
<snippet id='color-hex-full'/>

Creating a `Color` from a short hex value.
<snippet id='color-hex-short'/>

Creating a `Color` from four ARGB values.
<snippet id='color-rgba'/>

Creating a `Color` from a single ARGB value.
<snippet id='color-rgba-full'/>

Creating a `Color` from a known name.
Full list of the known color names can be found [here](https://docs.nativescript.org/api-reference/modules/_color_known_colors_).
<snippet id='olor-color-name'/>

Comparing two colors for equality.
<snippet id='color-compare'/>
6 changes: 6 additions & 0 deletions app/color/basics/basics-page.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Label {
color: white;
margin: 8;
padding: 8;
text-align: center;
}
65 changes: 65 additions & 0 deletions app/color/basics/basics-page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
const Color = require("tns-core-modules/color").Color;

exports.onNavigatedTo = function(args) {
// >> color-compare
const red = new Color("#FF0000");
const isRed = red.equals(new Color("red"));
console.log("Are both colors identical: ", isRed);
// << color-compare
};

exports.onLabel1Loaded = function(args) {
const label = args.object;

// >> color-hex-full
// Creates the red color
const color = new Color("#FF0000");
// << color-hex-full

label.backgroundColor = color;
};

exports.onLabel2Loaded = function(args) {
const label = args.object;

// >> color-hex-short
// Creates the color #FF8800
const color = new Color("#F80");
// << color-hex-short

label.backgroundColor = color;
};

exports.onLabel3Loaded = function(args) {
const label = args.object;

// >> color-rgba
// Creates the color with 100 alpha, 255 red, 100 green, 100 blue
const color = new Color(100, 255, 100, 100);
// << color-rgba

label.backgroundColor = color;
};

exports.onLabel4Loaded = function(args) {
const label = args.object;

// >> color-rgba-full
// Creates the color with 100 alpha, 100 red, 100 green, 100 blue
const color = new Color(0x64646464);
// << color-rgba-full

label.backgroundColor = color;
};

exports.onLabel5Loaded = function(args) {
const label = args.object;

// >> color-color-name
// Creates the color from thw known colors list
const color = new Color("orangered");
// << color-color-name

label.backgroundColor = color;
};

12 changes: 12 additions & 0 deletions app/color/basics/basics-page.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Page xmlns="http://www.nativescript.org/tns.xsd" navigatedTo="onNavigatedTo">
<Page.actionBar>
<ActionBar title="Basics"/>
</Page.actionBar>
<StackLayout verticalAlignment="middle">
<Label text="new Color('#FF0000')" textWrap="true" loaded="onLabel1Loaded"/>
<Label text="new Color('orangered')" textWrap="true" loaded="onLabel5Loaded"/>
<Label text="new Color('#F80')" textWrap="true" loaded="onLabel2Loaded"/>
<Label text="new Color(100, 255, 100, 100)" textWrap="true" loaded="onLabel3Loaded"/>
<Label text="new Color(0x64646464)" textWrap="true" loaded="onLabel4Loaded"/>
</StackLayout>
</Page>
13 changes: 13 additions & 0 deletions app/color/color-page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const ListViewLinksModel = require("../links-view-model");
const link = require("../link");
const navigationLinks = [
new link("Basics", "/color/basics/basics-page")
];
function onNavigatingTo(args) {
const page = args.object;
page.bindingContext = new ListViewLinksModel({
links: navigationLinks,
actionBarTitle: args.context.title
});
}
exports.onNavigatingTo = onNavigatingTo;
6 changes: 6 additions & 0 deletions app/color/color-page.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<Page xmlns="http://schemas.nativescript.org/tns.xsd" xmlns:myList="components" navigatingTo="onNavigatingTo">
<Page.actionBar>
<ActionBar title="{{ actionBarTitle == null ? '' : actionBarTitle }}" icon="" class="action-bar"/>
</Page.actionBar>
<myList:list/>
</Page>
7 changes: 7 additions & 0 deletions app/color/end.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
**API Reference for the** [Color Class](https://docs.nativescript.org/api-reference/classes/_color_.color.html)

**Native Component**

| Android | iOS |
|:----------------------|:---------|
| [android.graphics.Color](https://developer.android.com/reference/android/graphics/Color.html) | [UIColor](https://developer.apple.com/reference/uikit/uicolor) |
1 change: 1 addition & 0 deletions app/color/overview.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Represents a color object. Stores all color components (alpha (opacity), red, green, blue) in a [0..255] range.
3 changes: 2 additions & 1 deletion app/main-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const navigationLinks = [
new link("Animations", "ui/animations/animations-page"),
new link("Button", "ui/button/button-page"),
new link("Borders", "ui/borders/borders-page"),
new link("Color", "color/color-page"),
new link("DatePicker", "ui/date-picker/date-picker-page"),

new link("Dialogs", "/dialogs"),
Expand Down Expand Up @@ -37,7 +38,7 @@ const navigationLinks = [
new link("FPS Meter", "/fps-meter"),
new link("HTTP Module", "/http"),
new link("Application Settings", "/application-settings"),
new link("Color", "/color"),

new link("Connectivity", "/connectivity"),
new link("File System", "/file-system"),
new link("Modal page", "/modal-page"),
Expand Down
1 change: 1 addition & 0 deletions app/ui/action-bar/end.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

**API Reference for the** [ActionBar Class](http://docs.nativescript.org/api-reference/modules/_ui_action_bar_.html)
**API Reference for the** [Known Colors](https://docs.nativescript.org/api-reference/modules/_color_known_colors_)

**Native Component**

Expand Down

0 comments on commit fa9b1ed

Please sign in to comment.