forked from NativeScript/nativescript-sdk-examples-js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
133 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Label { | ||
color: white; | ||
margin: 8; | ||
padding: 8; | ||
text-align: center; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters