MCPcopy Create free account
hub / github.com/NativeScript/NativeScript / createPage

Function createPage

apps/ui/src/bindings/basics-page.ts:7–80  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

5import * as observableModule from '@nativescript/core/data/observable';
6
7export function createPage() {
8 var page = new pageModule.Page();
9 var stack = new stackLayoutModule.StackLayout();
10 var sourceOneWay = new observableModule.Observable();
11 var sourceTwoWay = new observableModule.Observable();
12 var targetOneWay = new textFieldModule.TextField();
13 var targetTwoWay = new textFieldModule.TextField();
14 var buttonOneWay = new buttonModule.Button();
15 var buttonTwoWay = new buttonModule.Button();
16 var buttonSetText = new buttonModule.Button();
17
18 targetOneWay.id = 'textFieldOneWay';
19 targetTwoWay.id = 'textFieldTwoWay';
20 buttonOneWay.id = 'buttonOneWay';
21 buttonTwoWay.id = 'buttonTwoWay';
22 buttonSetText.id = 'buttonSetText';
23
24 targetOneWay.automationText = 'textFieldOneWay';
25 targetTwoWay.automationText = 'textFieldTwoWay';
26 buttonSetText.automationText = 'buttonSetText';
27 //buttonOneWay.automationText = "buttonOneWay";
28 //buttonTwoWay.automationText = "buttonTwoWay";
29
30 buttonSetText.text = 'SetText';
31 buttonSetText.on(buttonModule.Button.tapEvent, function () {
32 targetOneWay.text = 'Test';
33 targetTwoWay.text = 'Test';
34 });
35 stack.addChild(buttonSetText);
36
37 // OneWay Binding
38 var bindingOptionOneWay = {
39 sourceProperty: 'textSource',
40 targetProperty: 'text',
41 twoWay: false,
42 };
43
44 targetOneWay.bind(bindingOptionOneWay, sourceOneWay);
45 sourceOneWay.set('textSource', 'OneWay');
46
47 buttonOneWay.on(buttonModule.Button.loadedEvent, function () {
48 buttonOneWay.text = sourceOneWay.get('textSource');
49 });
50 buttonOneWay.on(buttonModule.Button.tapEvent, function () {
51 buttonOneWay.text = sourceOneWay.get('textSource');
52 });
53
54 stack.addChild(targetOneWay);
55 stack.addChild(buttonOneWay);
56
57 // TwoWay Binding
58 var bindingOptionTwoWay = {
59 sourceProperty: 'textSource',
60 targetProperty: 'text',
61 twoWay: true,
62 };
63
64 targetTwoWay.bind(bindingOptionTwoWay, sourceTwoWay);

Callers

nothing calls this directly

Calls 5

setMethod · 0.95
getMethod · 0.95
bindMethod · 0.80
onMethod · 0.65
addChildMethod · 0.45

Tested by

no test coverage detected