chore: use nativescript.config with apps

This commit is contained in:
Nathan Walker
2020-08-30 10:29:35 -07:00
parent eeb9e069b1
commit 8bbb3fefae
1067 changed files with 45 additions and 82 deletions

View File

@@ -0,0 +1,80 @@
import * as buttonModule from '@nativescript/core/ui/button';
import * as pageModule from '@nativescript/core/ui/page';
import * as textFieldModule from '@nativescript/core/ui/text-field';
import * as stackLayoutModule from '@nativescript/core/ui/layouts/stack-layout';
import * as observableModule from '@nativescript/core/data/observable';
export function createPage() {
var page = new pageModule.Page();
var stack = new stackLayoutModule.StackLayout();
var sourceOneWay = new observableModule.Observable();
var sourceTwoWay = new observableModule.Observable();
var targetOneWay = new textFieldModule.TextField();
var targetTwoWay = new textFieldModule.TextField();
var buttonOneWay = new buttonModule.Button();
var buttonTwoWay = new buttonModule.Button();
var buttonSetText = new buttonModule.Button();
targetOneWay.id = 'textFieldOneWay';
targetTwoWay.id = 'textFieldTwoWay';
buttonOneWay.id = 'buttonOneWay';
buttonTwoWay.id = 'buttonTwoWay';
buttonSetText.id = 'buttonSetText';
targetOneWay.automationText = 'textFieldOneWay';
targetTwoWay.automationText = 'textFieldTwoWay';
buttonSetText.automationText = 'buttonSetText';
//buttonOneWay.automationText = "buttonOneWay";
//buttonTwoWay.automationText = "buttonTwoWay";
buttonSetText.text = 'SetText';
buttonSetText.on(buttonModule.Button.tapEvent, function () {
targetOneWay.text = 'Test';
targetTwoWay.text = 'Test';
});
stack.addChild(buttonSetText);
// OneWay Binding
var bindingOptionOneWay = {
sourceProperty: 'textSource',
targetProperty: 'text',
twoWay: false,
};
targetOneWay.bind(bindingOptionOneWay, sourceOneWay);
sourceOneWay.set('textSource', 'OneWay');
buttonOneWay.on(buttonModule.Button.loadedEvent, function () {
buttonOneWay.text = sourceOneWay.get('textSource');
});
buttonOneWay.on(buttonModule.Button.tapEvent, function () {
buttonOneWay.text = sourceOneWay.get('textSource');
});
stack.addChild(targetOneWay);
stack.addChild(buttonOneWay);
// TwoWay Binding
var bindingOptionTwoWay = {
sourceProperty: 'textSource',
targetProperty: 'text',
twoWay: true,
};
targetTwoWay.bind(bindingOptionTwoWay, sourceTwoWay);
sourceTwoWay.set('textSource', 'TwoWay');
buttonTwoWay.on(buttonModule.Button.loadedEvent, function () {
buttonTwoWay.text = sourceTwoWay.get('textSource');
});
buttonTwoWay.on(buttonModule.Button.tapEvent, function () {
buttonTwoWay.text = sourceTwoWay.get('textSource');
});
stack.addChild(targetTwoWay);
stack.addChild(buttonTwoWay);
page.content = stack;
return page;
}

View File

@@ -0,0 +1,18 @@
import { EventData } from '@nativescript/core/data/observable';
import { SubMainPageViewModel } from '../sub-main-page-view-model';
import { WrapLayout } from '@nativescript/core/ui/layouts/wrap-layout';
import { Page } from '@nativescript/core/ui/page';
export function pageLoaded(args: EventData) {
const page = <Page>args.object;
const wrapLayout = <WrapLayout>page.getViewById('wrapLayoutWithExamples');
page.bindingContext = new SubMainPageViewModel(wrapLayout, loadExamples());
}
export function loadExamples() {
const examples = new Map<string, string>();
examples.set('basics', 'bindings/basics-page');
examples.set('xmlbasics', 'bindings/xmlbasics-page');
return examples;
}

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Page loaded="pageLoaded">
<ScrollView orientation="vertical" row="1">
<WrapLayout id="wrapLayoutWithExamples"/>
</ScrollView>
</Page>

View File

@@ -0,0 +1,42 @@
import * as buttonModule from '@nativescript/core/ui/button';
import * as stackLayoutModule from '@nativescript/core/ui/layouts/stack-layout';
import * as textFieldModule from '@nativescript/core/ui/text-field';
import * as observable from '@nativescript/core/data/observable';
export function stack0Loaded(args: observable.EventData) {
var source = new observable.Observable();
var stack0 = <stackLayoutModule.StackLayout>args.object;
var target = stack0.getViewById<textFieldModule.TextField>('tf');
var button = stack0.getViewById<textFieldModule.TextField>('btn');
var bindingOptions = {
sourceProperty: 'textSource',
targetProperty: 'text', // ,
// twoWay: true
};
target.bind(bindingOptions, source);
source.set('textSource', 'Text');
button.on(buttonModule.Button.tapEvent, function () {
button.text = source.get('textSource');
});
}
export function stack1Loaded(args: observable.EventData) {
var stack1 = <stackLayoutModule.StackLayout>args.object;
stack1.bindingContext = { text: 'Label' };
}
export function stack2Loaded(args: observable.EventData) {
var stack2 = <stackLayoutModule.StackLayout>args.object;
stack2.bindingContext = {
myProperty: 'Button',
myFunction: () => {
console.log('### onTap event ###');
},
};
}
export function stack3Loaded(args: observable.EventData) {
var stack3 = <stackLayoutModule.StackLayout>args.object;
stack3.bindingContext = { myItems: [{ text: 'Label1' }, { text: 'Label2' }] };
}

View File

@@ -0,0 +1,21 @@
<Page>
<StackLayout>
<StackLayout loaded="stack0Loaded" orientation="horizontal">
<TextField id="tf" automationText="tf" text="{{ textSource }}" width="150" />
<Button id="btn" width="150" />
</StackLayout>
<StackLayout loaded="stack1Loaded">
<Label id="label" automationText="label" text="{{ text }}" />
</StackLayout>
<StackLayout loaded="stack2Loaded">
<Button id="button" automationText="button" text="{{ myProperty }}" tap="{{ myFunction }}" />
</StackLayout>
<StackLayout loaded="stack3Loaded">
<ListView id="listView" automationText="listView" items="{{ myItems }}">
<ListView.itemTemplate>
<Label id="item" text="{{ text }}"/>
</ListView.itemTemplate>
</ListView>
</StackLayout>
</StackLayout>
</Page>