diff --git a/apps/tests/ui/list-picker/list-picker-tests.ts b/apps/tests/ui/list-picker/list-picker-tests.ts index 4795ea7b3..2bf605312 100644 --- a/apps/tests/ui/list-picker/list-picker-tests.ts +++ b/apps/tests/ui/list-picker/list-picker-tests.ts @@ -4,21 +4,14 @@ import viewModule = require("ui/core/view"); import listPickerTestsNative = require("./list-picker-tests-native"); import application = require("application"); -// -// # ListPicker -// Using a ListPicker requires the "ui/list-picker" module. -// ``` JavaScript +// >> article-require-module import listPickerModule = require("ui/list-picker"); -// ``` -// +// << article-require-module function _createListPicker(): listPickerModule.ListPicker { - // - // ## Creating a ListPicker - // ``` JavaScript + // >> article-create-listpicker var listPicker = new listPickerModule.ListPicker(); - // ``` - // + // << article-create-listpicker listPicker.id = "ListPicker"; return listPicker; } @@ -72,12 +65,9 @@ export var testWhenSettingItemsToEmptyArrayZeroNativeItemsAreCreated = function export var testSelectedIndexBecomesZeroWhenItemsBoundToNonEmptyArray = function () { helper.buildUIAndRunTest(_createListPicker(), function (views: Array) { var listPicker = views[0]; - // - // ## Binding listPicker.items - // ``` JavaScript + // >> article-binding-listpickeritems listPicker.items = [1, 2, 3]; - // ``` - // + // << article-binding-listpickeritems var expectedValue = 0; var actualValue = listPicker.selectedIndex; TKUnit.assert(actualValue === expectedValue, "Actual: " + actualValue + "; Expected: " + expectedValue); @@ -88,12 +78,9 @@ export var testSelectedIndexBecomesUndefinedWhenItemsBoundToEmptyArray = functio helper.buildUIAndRunTest(_createListPicker(), function (views: Array) { var listPicker = views[0]; listPicker.items = _createItems(10); - // - // ## Selecting an item programmatically - // ``` JavaScript + // >> article-selecting-item listPicker.selectedIndex = 9; - // ``` - // + // << article-selecting-item listPicker.items = []; var expectedValue = undefined; var actualValue = listPicker.selectedIndex; diff --git a/apps/tests/ui/list-picker/list-picker.md b/apps/tests/ui/list-picker/list-picker.md new file mode 100644 index 000000000..92a4ee1ad --- /dev/null +++ b/apps/tests/ui/list-picker/list-picker.md @@ -0,0 +1,14 @@ +--- +nav-title: "ListPicker How-To" +title: "How-To" +description: "Examples for using ListPicker" +--- +# ListPicker +Using a ListPicker requires the "ui/list-picker" module. + +## Creating a ListPicker + +## Binding listPicker.items + +## Selecting an item programmatically + diff --git a/apps/tests/ui/list-view/list-view-tests.ts b/apps/tests/ui/list-view/list-view-tests.ts index 7e09becbc..08ddc1623 100644 --- a/apps/tests/ui/list-view/list-view-tests.ts +++ b/apps/tests/ui/list-view/list-view-tests.ts @@ -7,76 +7,34 @@ import platform = require("platform"); import utils = require("utils/utils"); import { Label } from "ui/label"; -//  -// # ListView -// Using a ListView requires the ListView module. -// ``` JavaScript +// >> article-require-module import listViewModule = require("ui/list-view"); -// ``` -// Other modules which will be used in the code samples in this article: -// ``` JavaScript +// << article-require-module + +// >> article-require-modules import observableArray = require("data/observable-array"); import labelModule = require("ui/label"); -// ``` +// << article-require-modules -// ### Binding the ListView items property to collection in the view-model. -//``` XML -// -// {%raw%}{%endraw%} -// -//``` -// ### Attaching event handler for the ListView itemTap event. -//``` XML -// -// {%raw%}{%endraw%} -// -//``` -//``` JavaScript -// function listViewItemTap(args) { -// var itemIndex = args.index; -// } -// exports.listViewItemTap = listViewItemTap; -//``` +// >> article-item-tap +function listViewItemTap(args) { + var itemIndex = args.index; +} +exports.listViewItemTap = listViewItemTap; +// << article-item-tap -// ### Attaching event handler for the ListView loadMoreItems event. -//``` XML -// -// {%raw%}{%endraw%} -// -//``` -//``` JavaScript -// function listViewLoadMoreItems(args) { -// // Expand your collection bound to the ListView with more items here! -// } -// exports.listViewLoadMoreItems = listViewLoadMoreItems; -//``` +// >> article-load-items +function listViewLoadMoreItems(args) { + // Expand your collection bound to the ListView with more items here! +} +// << article-load-items -// ### Define the ListView itemTemplate property. -//``` XML -// -// {%raw%} -// -// -// {%endraw%} -// -//``` - -// ### Define the ListView separatorColor property. -//``` XML -// -// {%raw%}{%endraw%} -// -//``` -//``` JavaScript // function loaded(args) { // args.object.bindingContext = { items: [1,2,3,4,5] }; // } // exports.loaded = loaded; -//``` -//  var ASYNC = 0.2; var FEW_ITEMS = [0, 1, 2]; @@ -92,12 +50,9 @@ export class ListViewTest extends testModule.UITest { } public test_default_TNS_values() { - // - // ### Creating a ListView - // ``` JavaScript + // >> article-create-listview var listView = new listViewModule.ListView(); - // ``` - // + // << article-create-listview TKUnit.assertEqual(listView.isScrolling, false, "Default listView.isScrolling"); TKUnit.assert(types.isUndefined(listView.items), "Default listView.items should be undefined"); @@ -107,10 +62,7 @@ export class ListViewTest extends testModule.UITest { var listView = this.testView; var indexes = {}; - // - // ### Using ListView with Array - // The itemLoading event is used to create the UI for each item that is shown in the ListView. - // ``` JavaScript + // >> article-listview-array var colors = ["red", "green", "blue"]; listView.items = colors; listView.on(listViewModule.ListView.itemLoadingEvent, function (args: listViewModule.ItemEventData) { @@ -120,7 +72,7 @@ export class ListViewTest extends testModule.UITest { } (args.view).text = colors[args.index]; - // + // >> (hide) indexes[args.index] = true; if (args.index === (colors.length - 1)) { try { @@ -140,10 +92,9 @@ export class ListViewTest extends testModule.UITest { done(e); } } - // + // << (hide) }); - // ``` - // + // << article-listview-array } public test_set_native_item_exposed() { @@ -210,15 +161,11 @@ export class ListViewTest extends testModule.UITest { TKUnit.waitUntilReady(() => { return this.getNativeViewCount(listView) === listView.items.length; }, ASYNC); TKUnit.assertEqual(this.getNativeViewCount(listView), colors.length, "Native views count."); - // - // > Note, that changing the array after the list view is shown will not update the UI. - // You can force-update the UI using the refresh() method. - // ``` JavaScript + // >> article-change-refresh-listview colors.push("yellow"); //// Manually trigger the update so that the new color is shown. listView.refresh(); - // ``` - // + // << article-change-refresh-listview TKUnit.waitUntilReady(() => { return this.getNativeViewCount(listView) === listView.items.length; }, ASYNC); TKUnit.assertEqual(this.getNativeViewCount(listView), colors.length, "Native views count."); } @@ -300,9 +247,7 @@ export class ListViewTest extends testModule.UITest { var listView = this.testView; var indexes = {}; - // - // ### Using ListView with ObservableArray - // ``` JavaScript + // >> article-listview-observablearray var colors = new observableArray.ObservableArray(["red", "green", "blue"]); listView.items = colors; listView.on(listViewModule.ListView.itemLoadingEvent, function (args: listViewModule.ItemEventData) { @@ -314,8 +259,7 @@ export class ListViewTest extends testModule.UITest { indexes[args.index] = true; }); - // ``` - // + // << article-listview-observablearray TKUnit.waitUntilReady(() => { return this.getNativeViewCount(listView) === listView.items.length; }, ASYNC); TKUnit.assert(indexes[0], "itemLoading not called for index 0"); @@ -333,13 +277,10 @@ export class ListViewTest extends testModule.UITest { TKUnit.waitUntilReady(() => { return this.getNativeViewCount(listView) === listView.items.length; }, ASYNC); TKUnit.assertEqual(this.getNativeViewCount(listView), 3, "getNativeViewCount"); - // - // > When using ObservableArray the list view will be automatically updated when items are added or removed form the array. - // ``` JavaScript + // >> article-push-in-observablearray colors.push("yellow"); //// The ListView will be updated automatically. - // ``` - // + // << article-push-in-observablearray TKUnit.waitUntilReady(() => { return this.getNativeViewCount(listView) === listView.items.length; }, ASYNC); TKUnit.assertEqual(this.getNativeViewCount(listView), 4, "getNativeViewCount"); } @@ -383,22 +324,17 @@ export class ListViewTest extends testModule.UITest { var nativeTapRaised = false; var itemIndex = -1; /* tslint:disable:no-unused-variable */ - // - // ## Responding to other events - // ### ItemTap event - // The event will be raise when an item inside the ListView is tapped. - // ``` JavaScript + // >> article-itemtap-event listView.on(listViewModule.ListView.itemTapEvent, function (args: listViewModule.ItemEventData) { var tappedItemIndex = args.index; var tappedItemView = args.view; //// Do someting - // + // >> (hide) nativeTapRaised = true; itemIndex = args.index; - // + // << (hide) }); - // ``` - // + // << article-itemtap-event /* tslint:enable:no-unused-variable */ TKUnit.waitUntilReady(() => { return this.getNativeViewCount(listView) === listView.items.length; }, ASYNC); this.performNativeItemTap(listView, 1); @@ -413,19 +349,15 @@ export class ListViewTest extends testModule.UITest { var loadMoreItemsCount = 0; listView.items = FEW_ITEMS; listView.on(listViewModule.ListView.itemLoadingEvent, this.loadViewWithItemNumber); - // - // ### LoadMoreItems event - // The event will be raised when the ListView is scrolled so that the last item is visible. - // This even is intended to be used to add additional data in the ListView. - // ``` JavaScript + // >> article-loadmoreitems-event listView.on(listViewModule.ListView.loadMoreItemsEvent, function (data: observable.EventData) { //// Do something. - // + // >> (hide) loadMoreItemsCount++; - // + // << (hide) }); // ``` - // + // << article-loadmoreitems-event TKUnit.waitUntilReady(() => { return this.getNativeViewCount(listView) === listView.items.length; }, ASYNC); TKUnit.assertEqual(loadMoreItemsCount, 1, "loadMoreItemsCount"); } diff --git a/apps/tests/ui/list-view/list-view.md b/apps/tests/ui/list-view/list-view.md new file mode 100644 index 000000000..7cd7f1fea --- /dev/null +++ b/apps/tests/ui/list-view/list-view.md @@ -0,0 +1,64 @@ +--- +nav-title: "list-view How-To" +title: "How-To" +description: "Examples for using list-view" +--- +# ListView +Using a ListView requires the ListView module. + +Other modules which will be used in the code samples in this article: + +### Binding the ListView items property to collection in the view-model. +``` XML + + {%raw%}{%endraw%} + +``` +### Attaching event handler for the ListView itemTap event. +``` XML + + {%raw%}{%endraw%} + +``` + +### Attaching event handler for the ListView loadMoreItems event. +``` XML + + {%raw%}{%endraw%} + +``` + +### Define the ListView itemTemplate property. +``` XML + + {%raw%} + + + {%endraw%} + +``` +### Creating a ListView + +### Using ListView with Array +The itemLoading event is used to create the UI for each item that is shown in the ListView. + + +> Note, that changing the array after the list view is shown will not update the UI. +You can force-update the UI using the refresh() method. + + +### Using ListView with ObservableArray + + +> When using ObservableArray the list view will be automatically updated when items are added or removed form the array. + + +## Responding to other events +### ItemTap event +The event will be raise when an item inside the ListView is tapped. + +### LoadMoreItems event +The event will be raised when the ListView is scrolled so that the last item is visible. +This even is intended to be used to add additional data in the ListView. + diff --git a/apps/tests/ui/page/page-tests-common.ts b/apps/tests/ui/page/page-tests-common.ts index 37405011f..7573729cf 100644 --- a/apps/tests/ui/page/page-tests-common.ts +++ b/apps/tests/ui/page/page-tests-common.ts @@ -1,27 +1,16 @@ -// -// # Page -// Using a page requires the Page module. -// ``` JavaScript +// >> article-require-module import pageModule = require("ui/page"); //// FrameModule is needed in order to have an option to navigate to the new page. import frameModule = require("ui/frame"); -// ``` +// << article-require-module -// ### Attaching event handler for the Page loaded event to set bindingContext. -//``` XML -// -// {%raw%} -//``` -//``` JavaScript -// function pageLoaded(args) { -// var page = args.object; -// page.bindingContext = { name : "Some name" }; -// } -// exports.pageLoaded = pageLoaded; -//``` - -// +// >> article-set-bindingcontext +function pageLoaded(args) { + var page = args.object; + page.bindingContext = { name : "Some name" }; +} +exports.pageLoaded = pageLoaded; +// << article-set-bindingcontext import TKUnit = require("../../TKUnit"); import labelModule = require("ui/label"); import {StackLayout} from "ui/layouts/stack-layout"; @@ -99,13 +88,12 @@ export function test_PageLoaded_is_called_once() { } export function test_NavigateToNewPage() { + // >> artivle-create-navigate-to-page var currentPage; var topFrame = frameModule.topmost(); currentPage = topFrame.currentPage; - // - // ### Creating and navigating to the created page. - // ``` JavaScript + var testPage: Page; var pageFactory = function (): Page { testPage = new pageModule.Page(); @@ -119,17 +107,13 @@ export function test_NavigateToNewPage() { animated: false }; topFrame.navigate(navEntry); - // ``` - // + // << artivle-create-navigate-to-page TKUnit.waitUntilReady(() => { return testPage.isLayoutValid }); - // - // ### Navigating backward is as simple as calling a single method. - // ``` JavaScript + // >> article-navigating-backward topFrame.goBack(); - // ``` - // + // << article-navigating-backward TKUnit.waitUntilReady(() => { return topFrame.currentPage !== null && topFrame.currentPage === currentPage }); TKUnit.assert(testPage.parent === undefined, "Page.parent should become undefined after navigating back"); @@ -221,9 +205,7 @@ function _test_PageNavigation_EventSequence(withTransition: boolean) { export function test_NavigateTo_WithContext() { let currentPage = frameModule.topmost().currentPage; - // - // ### Pass data to the new page. - // ``` JavaScript + // >> article-pass-data var testPage: pageModule.Page; var pageFactory = function (): pageModule.Page { testPage = new pageModule.Page(); @@ -239,8 +221,7 @@ export function test_NavigateTo_WithContext() { }; let topFrame = frameModule.topmost(); topFrame.navigate(navEntry); - // ``` - // + // << article-pass-data TKUnit.waitUntilReady(() => topFrame.currentPage !== null && topFrame.currentPage !== currentPage && testPage.isLayoutValid); var actualContextValue = testPage.navigationContext; diff --git a/apps/tests/ui/page/page.md b/apps/tests/ui/page/page.md new file mode 100644 index 000000000..f64449557 --- /dev/null +++ b/apps/tests/ui/page/page.md @@ -0,0 +1,21 @@ +--- +nav-title: "Page How-To" +title: "How-To" +description: "Examples for using Page" +--- +# Page +Using a page requires the Page module. + +### Attaching event handler for the Page loaded event to set bindingContext. +``` XML + + {%raw%} +``` + +### Creating and navigating to the created page. + +### Navigating backward is as simple as calling a single method. + +### Pass data to the new page. + diff --git a/apps/tests/ui/placeholder/placeholder-tests.ts b/apps/tests/ui/placeholder/placeholder-tests.ts index 0f367ca8d..4eba7930b 100644 --- a/apps/tests/ui/placeholder/placeholder-tests.ts +++ b/apps/tests/ui/placeholder/placeholder-tests.ts @@ -4,39 +4,29 @@ import utils = require("utils/utils"); import helper = require("../helper"); import viewModule = require("ui/core/view"); -//  -// # Placeholder -// Using the placeholder requires the Placeholder module. -// ``` JavaScript +// >> article-require-module import placeholderModule = require("ui/placeholder"); -// ``` +// << article-require-module -// Creating native view for the Placeholder using creatingView event. -//``` XML -// -// {%raw%}{%endraw%} -// -//``` -//``` JavaScript -//var platform = require("platform"); -//var utils = require("utils/utils"); -// -//function creatingView(args) { -// var nativeView; -// if (platform.device.os === platform.platformNames.ios) { -// nativeView = new UITextView(); -// nativeView.text = "Native"; -// } else if (platform.device.os === platform.platformNames.android) { -// nativeView = new android.widget.TextView(utils.ad.getApplicationContext()); -// nativeView.setText("Native"); -// } -// -// args.view = nativeView; -//} -// -//exports.creatingView = creatingView; -//``` -//  +// >> article-creating-view +var platform = require("platform"); +var utils = require("utils/utils"); + +function creatingView(args) { + var nativeView; + if (platform.device.os === platform.platformNames.ios) { + nativeView = new UITextView(); + nativeView.text = "Native"; + } else if (platform.device.os === platform.platformNames.android) { + nativeView = new android.widget.TextView(utils.ad.getApplicationContext()); + nativeView.setText("Native"); + } + + args.view = nativeView; +} + +exports.creatingView = creatingView; +// << article-creating-view export function test_placeholder_creatingView() { var nativeView; diff --git a/apps/tests/ui/placeholder/placeholder.md b/apps/tests/ui/placeholder/placeholder.md new file mode 100644 index 000000000..6f678a624 --- /dev/null +++ b/apps/tests/ui/placeholder/placeholder.md @@ -0,0 +1,15 @@ +--- +nav-title: "placeholder How-To" +title: "How-To" +description: "Examples for using placeholder" +--- +# Placeholder +Using the placeholder requires the Placeholder module. + +Creating native view for the Placeholder using creatingView event. +``` XML + + {%raw%}{%endraw%} + +``` + diff --git a/apps/tests/ui/progress/progress-tests.ts b/apps/tests/ui/progress/progress-tests.ts index b75af2fef..ad1f916a2 100644 --- a/apps/tests/ui/progress/progress-tests.ts +++ b/apps/tests/ui/progress/progress-tests.ts @@ -5,35 +5,16 @@ import observable = require("data/observable"); import color = require("color"); import platform = require("platform"); -//  -// # Progress -// Using the progress view requires the Progress module. -// ``` JavaScript +// >> article-require-module import progressModule = require("ui/progress"); -// ``` +// << article-require-module + -// Binding the Progress value property to a view-model property. -//``` XML -// -// {%raw%}{%endraw%} -// -//``` -//``` JavaScript -// function pageLoaded(args) { -// var page = args.object; -// page.bindingContext = { someProperty : 42 }; -// } -// exports.pageLoaded = pageLoaded; -//``` -//  export function test_default_TNS_values() { - // - // ### Creating a progress view - // ``` JavaScript + // >> article-create-progress-view var progress = new progressModule.Progress(); - // ``` - // + // << article-create-progress-view TKUnit.assertEqual(progress.value, 0, "Default progress.value"); TKUnit.assertEqual(progress.maxValue, 100, "Default progress.maxValue"); @@ -101,13 +82,10 @@ if (platform.device.os === platform.platformNames.ios) { export function test_set_maxValue_should_adjust_value() { var progress = new progressModule.Progress(); - // - // ### Setting up the progress view - // ``` JavaScript + // >> article-set-value progress.maxValue = 255; progress.value = 16; - // ``` - // + // << article-set-value function testAction(views: Array) { progress.maxValue = 10; diff --git a/apps/tests/ui/progress/progress.md b/apps/tests/ui/progress/progress.md new file mode 100644 index 000000000..10cad91ba --- /dev/null +++ b/apps/tests/ui/progress/progress.md @@ -0,0 +1,25 @@ +--- +nav-title: "progress How-To" +title: "How-To" +description: "Examples for using progress" +--- +# Progress +Using the progress view requires the Progress module. + +Binding the Progress value property to a view-model property. +``` XML + + {%raw%}{%endraw%} + +``` +``` JavaScript +function pageLoaded(args) { + var page = args.object; + page.bindingContext = { someProperty : 42 }; +} +exports.pageLoaded = pageLoaded; +``` +### Creating a progress view + +### Setting up the progress view + diff --git a/apps/tests/ui/repeater/repeater-tests.ts b/apps/tests/ui/repeater/repeater-tests.ts index 36c2a2f6e..fafd11e7e 100644 --- a/apps/tests/ui/repeater/repeater-tests.ts +++ b/apps/tests/ui/repeater/repeater-tests.ts @@ -10,64 +10,16 @@ import pageModule = require("ui/page"); import gestureModule = require("ui/gestures"); import { Label } from "ui/label"; -//  -// # Repeater -// Using a Repeater requires the repeater module. -// ``` JavaScript +// >> article-require-module import repeaterModule = require("ui/repeater"); -// ``` -// Other modules which will be used in the code samples in this article: -// ``` JavaScript +// << article-require-module + +// >> article-require-modules import observableArray = require("data/observable-array"); import labelModule = require("ui/label"); -// ``` +// << article-require-modules -// ### Binding the Repeater items property to collection in the view-model. -//``` XML -// -// {%raw%}{%endraw%} -// -//``` -// ### Define the Repeater itemTemplate property. -//``` XML -// -// {%raw%} -// -// -// {%endraw%} -// -//``` - -// ### Define the Repeater itemsLayout property. Default is StackLayout with orientation="vertical". -//``` XML -// -// {%raw%} -// -// -// -// {%endraw%} -// -//``` - -// ### Repeater with WrapLayout inside ScrollView. -//``` XML -// -// {%raw%} -// -// -// -// -// -// -// -// {%endraw%} -// -//``` - -//  var ASYNC = 0.2; var FEW_ITEMS = [0, 1, 2]; @@ -80,13 +32,10 @@ export function test_set_items_to_array_loads_all_items() { var repeater = new repeaterModule.Repeater(); function testAction(views: Array) { - // - // ### Using Repeater with Array - // ``` JavaScript + // >> article-repeater-with-array var colors = ["red", "green", "blue"]; repeater.items = colors; - // ``` - // + // << article-repeater-with-array TKUnit.wait(ASYNC); @@ -121,15 +70,11 @@ export function test_refresh_after_adding_items_to_array_loads_new_items() { TKUnit.wait(ASYNC); TKUnit.assertEqual(getChildrenCount(repeater), colors.length, "views count."); - // - // > Note, that changing the array after the repeater is shown will not update the UI. - // You can force-update the UI using the refresh() method. - // ``` JavaScript + // >> artcle-array-push-element colors.push("yellow"); //// Manually trigger the update so that the new color is shown. repeater.refresh(); - // ``` - // + // << artcle-array-push-element TKUnit.wait(ASYNC); TKUnit.assertEqual(getChildrenCount(repeater), colors.length, "views count."); }; @@ -183,15 +128,12 @@ export function test_set_itmes_to_null_clears_items() { } export function test_set_itemsLayout_accepted() { - // - // ### Using Repeater with different layout. - // ``` JavaScript + // >> article-repeater-layout var repeater = new repeaterModule.Repeater(); var stackLayout = new stackLayoutModule.StackLayout(); stackLayout.orientation = "horizontal"; repeater.itemsLayout = stackLayout; - // ``` - // + // << article-repeater-layout function testAction(views: Array) { @@ -240,13 +182,10 @@ export function test_set_items_to_observable_array_loads_all_items() { var repeater = new repeaterModule.Repeater(); function testAction(views: Array) { - // - // ### Using Repeater with ObservableArray - // ``` JavaScript + // >> article-repeater-observablearray var colors = new observableArray.ObservableArray(["red", "green", "blue"]); repeater.items = colors; - // ``` - // + // << article-repeater-observablearray TKUnit.assert(getChildAtText(repeater, 0) === "red", "Item not created for index 0"); TKUnit.assert(getChildAtText(repeater, 1) === "green", "Item not created for index 1"); @@ -266,13 +205,10 @@ export function test_add_to_observable_array_refreshes_the_Repeater() { TKUnit.wait(ASYNC); TKUnit.assertEqual(getChildrenCount(repeater), 3, "getChildrenCount"); - // - // > When using ObservableArray the repeater will be automatically updated when items are added or removed form the array. - // ``` JavaScript + // >> article-push-to-observablearray colors.push("yellow"); //// The Repeater will be updated automatically. - // ``` - // + // << article-push-to-observablearray TKUnit.wait(ASYNC); TKUnit.assertEqual(getChildrenCount(repeater), 4, "getChildrenCount"); diff --git a/apps/tests/ui/repeater/repeater.md b/apps/tests/ui/repeater/repeater.md new file mode 100644 index 000000000..b123dbf70 --- /dev/null +++ b/apps/tests/ui/repeater/repeater.md @@ -0,0 +1,62 @@ +--- +nav-title: "repeater How-To" +title: "How-To" +description: "Examples for using repeater" +--- +# Repeater +Using a Repeater requires the repeater module. + +Other modules which will be used in the code samples in this article: + +### Binding the Repeater items property to collection in the view-model. +``` XML + + {%raw%}{%endraw%} + +``` +### Define the Repeater itemTemplate property. +``` XML + + {%raw%} + + + {%endraw%} + +``` +### Define the Repeater itemsLayout property. Default is StackLayout with orientation="vertical". +``` XML + + {%raw%} + + + + {%endraw%} + +``` +### Repeater with WrapLayout inside ScrollView. +``` XML + +{%raw%} + + + + + + + + {%endraw%} + +``` +### Using Repeater with Array + +> Note, that changing the array after the repeater is shown will not update the UI. +You can force-update the UI using the refresh() method. + +### Using Repeater with different layout. + +### Using Repeater with ObservableArray + +> When using ObservableArray the repeater will be automatically updated when items are added or removed form the array. + diff --git a/apps/tests/ui/scroll-view/scroll-view-tests.ts b/apps/tests/ui/scroll-view/scroll-view-tests.ts index 2cb6e1200..dacb25f25 100644 --- a/apps/tests/ui/scroll-view/scroll-view-tests.ts +++ b/apps/tests/ui/scroll-view/scroll-view-tests.ts @@ -7,23 +7,9 @@ import layoutHelper = require("../../layouts/layout-helper"); import {Page} from "ui/page"; import * as frame from "ui/frame"; -//  -// # ScrollView -// Using a ScrollView requires the ScrollView module. -// ``` JavaScript +// >> article-require-module import scrollViewModule = require("ui/scroll-view"); -// ``` - -// ### Declaring the ScrollView. -//``` XML -// -// -// {%raw%}{%endraw%} -// -// -//``` - -//  +// << article-require-module class ScrollLayoutTest extends testModule.UITest { @@ -44,13 +30,9 @@ class ScrollLayoutTest extends testModule.UITest { } public test_snippets() { - /* tslint:disable:no-unused-variable */ - // - // ### Creating a ScrollView - // ``` JavaScript + // >> article-creating-scrollview var scrollView = new scrollViewModule.ScrollView(); - // ``` - // + // << article-creating-scrollview } public test_default_TNS_values() { diff --git a/apps/tests/ui/scroll-view/scroll-view.md b/apps/tests/ui/scroll-view/scroll-view.md new file mode 100644 index 000000000..cc7bbbd11 --- /dev/null +++ b/apps/tests/ui/scroll-view/scroll-view.md @@ -0,0 +1,18 @@ +--- +nav-title: "scroll-view How-To" +title: "How-To" +description: "Examples for using scroll-view" +--- +# ScrollView +Using a ScrollView requires the ScrollView module. + +### Declaring the ScrollView. +``` XML + + + {%raw%}{%endraw%} + + +``` +### Creating a ScrollView + diff --git a/apps/tests/ui/search-bar/search-bar-tests.ts b/apps/tests/ui/search-bar/search-bar-tests.ts index 93f340ad6..9f459311c 100644 --- a/apps/tests/ui/search-bar/search-bar-tests.ts +++ b/apps/tests/ui/search-bar/search-bar-tests.ts @@ -4,13 +4,9 @@ import viewModule = require("ui/core/view"); import searchBarTestsNative = require("./search-bar-tests-native"); import colorModule = require("color"); import observable = require("data/observable"); -//  -// # SearchBar -// Using the SearchBar requires the "ui/search-bar" module. -// ``` JavaScript +// >> article-require-module import searchBarModule = require("ui/search-bar"); -// ``` -// +// << article-require-module // ### Declaring a SearchBar. //``` XML @@ -21,12 +17,9 @@ import searchBarModule = require("ui/search-bar"); //  var _createSearchBarFunc = function (): searchBarModule.SearchBar { - // - // ### Creating a SearchBar - // ``` JavaScript + // >> article-creating-searchbar var searchBar = new searchBarModule.SearchBar(); - // ``` - // + // << article-creating-searchbar searchBar.text = "searchBar"; return searchBar; }; @@ -75,9 +68,7 @@ export var testSearchBarFontSize = function () { }; export function test_DummyTestForSnippetOnly() { - // - // ### Searching - // ``` JavaScript + // >> article-searching var searchBar = new searchBarModule.SearchBar(); searchBar.on(searchBarModule.SearchBar.submitEvent, function (args: observable.EventData) { console.log("Search for " + (args.object).text); @@ -85,6 +76,5 @@ export function test_DummyTestForSnippetOnly() { searchBar.on(searchBarModule.SearchBar.clearEvent, function (args: observable.EventData) { console.log("Clear"); }); - // ``` - // + // << article-searching } diff --git a/apps/tests/ui/search-bar/search-bar.md b/apps/tests/ui/search-bar/search-bar.md new file mode 100644 index 000000000..c8faf26de --- /dev/null +++ b/apps/tests/ui/search-bar/search-bar.md @@ -0,0 +1,12 @@ +--- +nav-title: "search-bar How-To" +title: "How-To" +description: "Examples for using search-bar" +--- +# SearchBar +Using the SearchBar requires the "ui/search-bar" module. + +### Creating a SearchBar + +### Searching + diff --git a/apps/tests/ui/segmented-bar/segmented-bar-tests.ts b/apps/tests/ui/segmented-bar/segmented-bar-tests.ts index 97cf85267..0dab24831 100644 --- a/apps/tests/ui/segmented-bar/segmented-bar-tests.ts +++ b/apps/tests/ui/segmented-bar/segmented-bar-tests.ts @@ -6,31 +6,14 @@ import bindable = require("ui/core/bindable"); import observable = require("data/observable"); import color = require("color"); -// -// # SegmentedBar - -// Using a SegmentedBar requires the "ui/segmented-bar" module. -// ``` JavaScript +// >> article-require-module import segmentedBarModule = require("ui/segmented-bar"); -// ``` -// +// << article-require-module function _createSegmentedBar(): segmentedBarModule.SegmentedBar { - // - // ## Creating a SegmentedBar - // ``` JavaScript + // >> article-create-segmentedbar var segmentedBar = new segmentedBarModule.SegmentedBar(); - // ``` - // ``` XML - // - // - // - // - // - // - // - // ``` - // + // << article-create-segmentedbar segmentedBar.id = "SegmentedBar"; return segmentedBar; } @@ -102,11 +85,7 @@ export var testWhenSettingItemsToEmptyArrayZeroNativeItemsAreCreated = function export var testSelectedIndexBecomesZeroWhenItemsBoundToNonEmptyArray = function () { helper.buildUIAndRunTest(_createSegmentedBar(), function (views: Array) { var segmentedBar = views[0]; - // - // ### Creating segmentedBar.items - // It is important that an items array gets created and filled with - // items first and then assigned to the segmented bar. - // ``` JavaScript + // >> article-creating-segmentedbar-items var items = []; var item1 = new segmentedBarModule.SegmentedBarItem(); item1.title = "Item1"; @@ -118,8 +97,7 @@ export var testSelectedIndexBecomesZeroWhenItemsBoundToNonEmptyArray = function item3.title = "Item3"; items.push(item3); segmentedBar.items = items; - // ``` - // + // << article-creating-segmentedbar-items var expectedValue = 0; var actualValue = segmentedBar.selectedIndex; TKUnit.assert(actualValue === expectedValue, "Actual: " + actualValue + "; Expected: " + expectedValue); @@ -130,12 +108,9 @@ export var testSelectedIndexBecomesUndefinedWhenItemsBoundToEmptyArray = functio helper.buildUIAndRunTest(_createSegmentedBar(), function (views: Array) { var segmentedBar = views[0]; segmentedBar.items = _createItems(10); - // - // ### Selecting an item programmatically - // ``` JavaScript + // >> artcile-selecting-item segmentedBar.selectedIndex = 9; - // ``` - // + // << artcile-selecting-item segmentedBar.items = []; var expectedValue = undefined; var actualValue = segmentedBar.selectedIndex; diff --git a/apps/tests/ui/segmented-bar/segmented-bar.md b/apps/tests/ui/segmented-bar/segmented-bar.md new file mode 100644 index 000000000..7fad59685 --- /dev/null +++ b/apps/tests/ui/segmented-bar/segmented-bar.md @@ -0,0 +1,25 @@ +--- +nav-title: "SegmentedBar How-To" +title: "How-To" +description: "Examples for using SegmentedBar" +--- +# SegmentedBar +Using a SegmentedBar requires the "ui/segmented-bar" module. + +## Creating a SegmentedBar + +``` XML + + + + + + + +``` +### Creating segmentedBar.items +It is important that an items array gets created and filled with +items first and then assigned to the segmented bar. + +### Selecting an item programmatically + diff --git a/apps/tests/ui/slider/slider-tests.ts b/apps/tests/ui/slider/slider-tests.ts index 509908fb2..038873631 100644 --- a/apps/tests/ui/slider/slider-tests.ts +++ b/apps/tests/ui/slider/slider-tests.ts @@ -7,23 +7,13 @@ import observable = require("data/observable"); import color = require("color"); import platform = require("platform"); -//  -// # Slider -// Using a slider requires the Slider module. -// ``` JavaScript +// >> article-require-slider import sliderModule = require("ui/slider"); -// ``` +// << article-require-slider // ### Binding the Progress and Slider value properties to a observable view-model property. -//``` XML -// -// -// {%raw%} -// {%endraw%} -// -// -//``` -//``` JavaScript + +// >> article-binding-slider-properties // function pageLoaded(args) { // var page = args.object; // var obj = new observable.Observable(); @@ -31,19 +21,15 @@ import sliderModule = require("ui/slider"); // page.bindingContext = obj; // } // exports.pageLoaded = pageLoaded; -//``` +// << article-binding-slider-properties -//  var TEST_VALUE = 5; export function test_set_TNS_value_updates_native_value() { - // - // ### Creating a slider - // ``` JavaScript + // >> article-creating-slider var slider = new sliderModule.Slider(); - // ``` - // + // << article-creating-slider function testAction(views: Array) { slider.value = TEST_VALUE; @@ -172,14 +158,11 @@ export function test_set_maxValue_should_adjust_value() { export function test_set_maxValue_should_adjust_value_and_minValue() { var slider = new sliderModule.Slider(); - // - // ### Setting the slider value and bounds - // ``` JavaScript + // >> article-setting-slider-values slider.maxValue = 120; slider.value = 80; slider.minValue = 50; - // ``` - // + // << article-setting-slider-values function testAction(views: Array) { slider.maxValue = 30; @@ -335,9 +318,7 @@ export function test_binding_value_to_model() { var slider = new sliderModule.Slider() function testAction(views: Array) { - // - // ### Binding value property to a model - // ``` JavaScript + // >> article-binding-value-property var model = new observable.Observable(); model.set("age", 21); var options: bindable.BindingOptions = { @@ -346,16 +327,15 @@ export function test_binding_value_to_model() { }; slider.bind(options, model); //// slider.value is now 21 - // + // >> (hide) TKUnit.assertEqual(slider.value, 21, "slider.value"); - // + // << (hide) model.set("age", 22); //// slider.value is now 22 - // + // >> (hide) TKUnit.assertEqual(slider.value, 22, "slider.value"); - // - // ``` - // + // << (hide) + // << article-binding-value-property } helper.buildUIAndRunTest(slider, testAction); diff --git a/apps/tests/ui/slider/slider.md b/apps/tests/ui/slider/slider.md new file mode 100644 index 000000000..1319b0a72 --- /dev/null +++ b/apps/tests/ui/slider/slider.md @@ -0,0 +1,24 @@ +--- +nav-title: "slider How-To" +title: "How-To" +description: "Examples for using slider" +--- +# Slider +Using a slider requires the Slider module. + +### Binding the Progress and Slider value properties to a observable view-model property. +``` XML + + + {%raw%} + {%endraw%} + + +``` + +### Creating a slider + +### Setting the slider value and bounds + +### Binding value property to a model + diff --git a/apps/tests/ui/style/style-tests.ts b/apps/tests/ui/style/style-tests.ts index 4133d2a1b..97565d905 100644 --- a/apps/tests/ui/style/style-tests.ts +++ b/apps/tests/ui/style/style-tests.ts @@ -13,9 +13,7 @@ import viewModule = require("ui/core/view"); import styleModule = require("ui/styling/style"); import dependencyObservableModule = require("ui/core/dependency-observable"); -// -// # Styling -// + export function test_css_dataURI_is_applied_to_backgroundImageSource() { var stack = new stackModule.StackLayout(); @@ -133,20 +131,15 @@ export function test_css_is_applied_inside_NestedControls() { // Basic selector tests export function test_setting_css() { - // - // ### Setting CSS to a page - // ``` JavaScript + // >> article-setting-css-page var page = new pageModule.Page(); page.css = ".title { font-size: 20 }"; - // ``` - // + // << article-setting-css-page TKUnit.assert(page.css === ".title { font-size: 20 }", "CSS not set correctly."); } -// -// ## Using CSS selectors -// + // Basic selector tests export function test_type_selector() { @@ -155,9 +148,7 @@ export function test_type_selector() { let btn: buttonModule.Button; let label: labelModule.Label; - // - // ### Using type selector - // ``` JavaScript + // >> article-using-type-selector page.css = "button { background-color: red; }"; //// Will be styled @@ -165,8 +156,7 @@ export function test_type_selector() { //// Won't be styled label = new labelModule.Label(); - // ``` - // + // << article-using-type-selector let stack = new stackModule.StackLayout(); page.content = stack; @@ -184,9 +174,7 @@ export function test_class_selector() { let btnWithClass: buttonModule.Button; let btnWithNoClass: buttonModule.Button; - // - // ### Using class selector - // ``` JavaScript + // >> article-using-class-selector page.css = ".test { color: red; }"; //// Will be styled @@ -195,8 +183,7 @@ export function test_class_selector() { //// Won't be styled btnWithNoClass = new buttonModule.Button(); - // ``` - // + // << article-using-class-selector var stack = new stackModule.StackLayout(); page.content = stack; @@ -231,9 +218,7 @@ export function test_id_selector() { let btnWithId: buttonModule.Button; let btnWithNoId: buttonModule.Button; - // - // ### Using id selector - // ``` JavaScript + // >> article-using-id-selector page.css = "#myButton { color: red; }"; //// Will be styled @@ -242,8 +227,7 @@ export function test_id_selector() { //// Won't be styled btnWithNoId = new buttonModule.Button(); - // ``` - // + // << article-using-id-selector var stack = new stackModule.StackLayout(); page.content = stack; @@ -275,15 +259,12 @@ export function test_type_and_state_selector() { page.style._resetValue(styling.properties.colorProperty); var btn: buttonModule.Button; - // - // ### Using state selector - // ``` JavaScript + // >>article-using-state-selector page.css = "button:pressed { color: red; }"; //// Will be red when pressed btn = new buttonModule.Button(); - // ``` - // + // << article-using-state-selector var stack = new stackModule.StackLayout(); page.content = stack; stack.addChild(btn); diff --git a/apps/tests/ui/style/style.md b/apps/tests/ui/style/style.md new file mode 100644 index 000000000..9ffa5aeb2 --- /dev/null +++ b/apps/tests/ui/style/style.md @@ -0,0 +1,18 @@ +--- +nav-title: "styling How-To" +title: "How-To" +description: "Examples for using styling" +--- +# Styling +### Setting CSS to a page + +## Using CSS selectors +### Using type selector + +### Using class selector + +### Using id selector + +### Using state selector + +For information and example how to use style properties please refer to special [**Styling**](../../../styling.md) topic. diff --git a/apps/tests/ui/switch/switch-tests.ts b/apps/tests/ui/switch/switch-tests.ts index eb5fc527b..dfb6dfbc6 100644 --- a/apps/tests/ui/switch/switch-tests.ts +++ b/apps/tests/ui/switch/switch-tests.ts @@ -5,41 +5,27 @@ import bindable = require("ui/core/bindable"); import observable = require("data/observable"); import color = require("color"); import platform = require("platform"); -//  -// # Switch -// Using a switch requires the Switch module. -// ``` JavaScript +// >> article-require-switch import switchModule = require("ui/switch"); -// ``` +// << article-require-switch // ### Binding the Switch checked property and Button isEanbled property to a observable view-model property. -//``` XML -// -// -// {%raw%} -//