mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
tests refactored
This commit is contained in:
3
tests/.vscode/launch.json
vendored
3
tests/.vscode/launch.json
vendored
@@ -43,7 +43,8 @@
|
||||
"sourceMaps": true,
|
||||
"diagnosticLogging": false,
|
||||
"emulator": false,
|
||||
"rebuild": false
|
||||
"rebuild": false,
|
||||
"stopOnEntry": true
|
||||
},
|
||||
{
|
||||
"name": "Launch on Android",
|
||||
|
||||
@@ -55,7 +55,7 @@ allTests["CONNECTIVITY"] = require("./connectivity-tests");
|
||||
|
||||
// allTests["PROXY-VIEW-CONTAINER"] = require("./ui/proxy-view-container/proxy-view-container-tests")
|
||||
allTests["SCROLL-VIEW"] = require("./ui/scroll-view/scroll-view-tests");
|
||||
// allTests["ACTION-BAR"] = require("./ui/action-bar/action-bar-tests");
|
||||
allTests["ACTION-BAR"] = require("./ui/action-bar/action-bar-tests");
|
||||
// allTests["XML-DECLARATION"] = require("./xml-declaration/xml-declaration-tests");
|
||||
allTests["DOCKLAYOUT"] = require("./ui/layouts/dock-layout-tests");
|
||||
allTests["WRAPLAYOUT"] = require("./ui/layouts/wrap-layout-tests");
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import * as TKUnit from "../../TKUnit";
|
||||
import * as LabelModule from "ui/label";
|
||||
import * as helper from "../helper";
|
||||
import * as builder from "ui/builder";
|
||||
import * as button from "ui/button";
|
||||
import * as PageModule from "ui/page";
|
||||
import * as viewModule from "ui/core/view";
|
||||
import * as fs from "file-system";
|
||||
import { Label } from "ui/label";
|
||||
import { Button } from "ui/button";
|
||||
import { Page } from "ui/page";
|
||||
import { View } from "ui/core/view";
|
||||
import { Observable } from "data/observable";
|
||||
|
||||
// >> actionbar-common-require
|
||||
@@ -13,14 +13,14 @@ import * as actionBarModule from "ui/action-bar";
|
||||
// << actionbar-common-require
|
||||
|
||||
export function test_actionItem_inherit_bindingContext() {
|
||||
var page: PageModule.Page;
|
||||
var label: LabelModule.Label;
|
||||
var context = { text: "item" };
|
||||
let page: Page;
|
||||
let label: Label;
|
||||
const context = { text: "item" };
|
||||
|
||||
var pageFactory = function (): PageModule.Page {
|
||||
page = new PageModule.Page();
|
||||
const pageFactory = function (): Page {
|
||||
page = new Page();
|
||||
page.bindingContext = context;
|
||||
var actionItem = new actionBarModule.ActionItem();
|
||||
const actionItem = new actionBarModule.ActionItem();
|
||||
|
||||
actionItem.bind({
|
||||
sourceProperty: "text",
|
||||
@@ -29,7 +29,7 @@ export function test_actionItem_inherit_bindingContext() {
|
||||
|
||||
page.actionBar.actionItems.addItem(actionItem);
|
||||
|
||||
label = new LabelModule.Label();
|
||||
label = new Label();
|
||||
label.text = "Text";
|
||||
page.content = label;
|
||||
return page;
|
||||
@@ -41,7 +41,7 @@ export function test_actionItem_inherit_bindingContext() {
|
||||
}
|
||||
|
||||
export function test_actionBar_inherit_bindingContext_inXML() {
|
||||
var p = <PageModule.Page>builder.parse(
|
||||
const p = <Page>builder.parse(
|
||||
"<Page> <Page.actionBar> <ActionBar title=\"{{ myProp }} \" /> </Page.actionBar> </Page>");
|
||||
p.bindingContext = { myProp: "success" };
|
||||
|
||||
@@ -49,52 +49,52 @@ export function test_actionBar_inherit_bindingContext_inXML() {
|
||||
};
|
||||
|
||||
export function test_actionItem_inherit_bindingContext_inXML() {
|
||||
var p = <PageModule.Page>builder.parse(
|
||||
const p = <Page>builder.parse(
|
||||
"<Page> <Page.actionBar> <ActionBar> <ActionBar.actionItems>" +
|
||||
"<ActionItem text=\"{{ myProp }} \" />" +
|
||||
"</ActionBar.actionItems> </ActionBar> </Page.actionBar> </Page>");
|
||||
p.bindingContext = { myProp: "success" };
|
||||
|
||||
var actionItem = p.actionBar.actionItems.getItemAt(0);
|
||||
const actionItem = p.actionBar.actionItems.getItemAt(0);
|
||||
|
||||
TKUnit.assertEqual(actionItem.text, "success", "actionItem.text");
|
||||
};
|
||||
|
||||
export function test_actionItem_page_property_inXML() {
|
||||
var p = <PageModule.Page>builder.parse(
|
||||
const p = <Page>builder.parse(
|
||||
"<Page> <Page.actionBar> <ActionBar> <ActionBar.actionItems>" +
|
||||
"<ActionItem text=\"test\" />" +
|
||||
"</ActionBar.actionItems> </ActionBar> </Page.actionBar> </Page>");
|
||||
|
||||
var actionItem = p.actionBar.actionItems.getItemAt(0);
|
||||
const actionItem = p.actionBar.actionItems.getItemAt(0);
|
||||
|
||||
TKUnit.assertEqual(actionItem.page, p, "actionItem.page");
|
||||
};
|
||||
|
||||
export function test_actionItem_actionView_inXML() {
|
||||
var p = <PageModule.Page>builder.parse(
|
||||
const p = <Page>builder.parse(
|
||||
"<Page> <Page.actionBar> <ActionBar> <ActionItem> <ActionItem.actionView>" +
|
||||
"<Label/>" +
|
||||
"</ActionItem.actionView> </ActionItem> </ActionBar> </Page.actionBar> </Page>");
|
||||
|
||||
var label = <LabelModule.Label>p.actionBar.actionItems.getItemAt(0).actionView;
|
||||
TKUnit.assert(label instanceof LabelModule.Label, "ActionItem.actionView not loaded correctly");
|
||||
const label = <Label>p.actionBar.actionItems.getItemAt(0).actionView;
|
||||
TKUnit.assert(label instanceof Label, "ActionItem.actionView not loaded correctly");
|
||||
};
|
||||
|
||||
export function test_actionItem_actionView_inherit_bindingContext_inXML() {
|
||||
var p = <PageModule.Page>builder.parse(
|
||||
const p = <Page>builder.parse(
|
||||
"<Page> <Page.actionBar> <ActionBar> <ActionItem> <ActionItem.actionView>" +
|
||||
"<Label text=\"{{ myProp }} \" />" +
|
||||
"</ActionItem.actionView> </ActionItem> </ActionBar> </Page.actionBar> </Page>");
|
||||
p.bindingContext = { myProp: "success" };
|
||||
|
||||
var label = <LabelModule.Label>p.actionBar.actionItems.getItemAt(0).actionView;
|
||||
TKUnit.assert(label instanceof LabelModule.Label, "ActionItem.actionView not loaded correctly");
|
||||
const label = <Label>p.actionBar.actionItems.getItemAt(0).actionView;
|
||||
TKUnit.assert(label instanceof Label, "ActionItem.actionView not loaded correctly");
|
||||
TKUnit.assertEqual(label.text, "success", "ActionItem.actionView");
|
||||
};
|
||||
|
||||
export function test_ActionBar_is_not_empty_when_actionItem_actionView_is_set() {
|
||||
var p = <PageModule.Page>builder.parse(
|
||||
const p = <Page>builder.parse(
|
||||
"<Page> <Page.actionBar> <ActionBar> <ActionItem> <ActionItem.actionView>" +
|
||||
"<Label text=\"test\" />" +
|
||||
"</ActionItem.actionView> </ActionItem> </ActionBar> </Page.actionBar> </Page>");
|
||||
@@ -103,50 +103,50 @@ export function test_ActionBar_is_not_empty_when_actionItem_actionView_is_set()
|
||||
};
|
||||
|
||||
export function test_navigationButton_inherit_bindingContext_inXML() {
|
||||
var p = <PageModule.Page>builder.parse(
|
||||
const p = <Page>builder.parse(
|
||||
"<Page> <Page.actionBar> <ActionBar>" +
|
||||
"<NavigationButton text=\"{{ myProp }} \" />" +
|
||||
"</ActionBar> </Page.actionBar> </Page>");
|
||||
p.bindingContext = { myProp: "success" };
|
||||
|
||||
var navButton = p.actionBar.navigationButton;
|
||||
const navButton = p.actionBar.navigationButton;
|
||||
TKUnit.assertEqual(navButton.text, "success", "actionItem.text");
|
||||
};
|
||||
|
||||
export function test_titleView_inherit_bindingContext_inXML() {
|
||||
var p = <PageModule.Page>builder.parse(
|
||||
const p = <Page>builder.parse(
|
||||
"<Page> <Page.actionBar> <ActionBar> <ActionBar.titleView>" +
|
||||
"<Button text=\"{{ myProp }} \" />" +
|
||||
"</ActionBar.titleView> </ActionBar> </Page.actionBar> </Page>");
|
||||
p.bindingContext = { myProp: "success" };
|
||||
|
||||
var centerBtn = <button.Button>p.actionBar.titleView;
|
||||
TKUnit.assert(centerBtn instanceof button.Button, "titleView not loaded correctly");
|
||||
const centerBtn = <Button>p.actionBar.titleView;
|
||||
TKUnit.assert(centerBtn instanceof Button, "titleView not loaded correctly");
|
||||
TKUnit.assertEqual(centerBtn.text, "success", "actionItem.text");
|
||||
};
|
||||
|
||||
export function test_titleView_inXML() {
|
||||
var p = <PageModule.Page>builder.parse(
|
||||
const p = <Page>builder.parse(
|
||||
"<Page> <Page.actionBar> <ActionBar> <ActionBar.titleView>" +
|
||||
"<Button/>" +
|
||||
"</ActionBar.titleView> </ActionBar> </Page.actionBar> </Page>");
|
||||
|
||||
var centerBtn = <button.Button>p.actionBar.titleView;
|
||||
TKUnit.assert(centerBtn instanceof button.Button, "titleView not loaded correctly");
|
||||
const centerBtn = <Button>p.actionBar.titleView;
|
||||
TKUnit.assert(centerBtn instanceof Button, "titleView not loaded correctly");
|
||||
};
|
||||
|
||||
export function test_titleView_inXML_short_definition() {
|
||||
var p = <PageModule.Page>builder.parse(
|
||||
const p = <Page>builder.parse(
|
||||
"<Page> <Page.actionBar> <ActionBar>" +
|
||||
"<Button/>" +
|
||||
"</ActionBar> </Page.actionBar> </Page>");
|
||||
|
||||
var centerBtn = <button.Button>p.actionBar.titleView;
|
||||
TKUnit.assert(centerBtn instanceof button.Button, "titleView not loaded correctly");
|
||||
const centerBtn = <Button>p.actionBar.titleView;
|
||||
TKUnit.assert(centerBtn instanceof Button, "titleView not loaded correctly");
|
||||
};
|
||||
|
||||
export function test_ActionBar_is_not_empty_when_titleView_is_set() {
|
||||
var p = <PageModule.Page>builder.parse(
|
||||
const p = <Page>builder.parse(
|
||||
"<Page> <Page.actionBar> <ActionBar> <ActionBar.titleView>" +
|
||||
"<Button text=\"test\" />" +
|
||||
"</ActionBar.titleView> </ActionBar> </Page.actionBar> </Page>");
|
||||
@@ -155,18 +155,18 @@ export function test_ActionBar_is_not_empty_when_titleView_is_set() {
|
||||
};
|
||||
|
||||
export function test_ActionBarItemBindingToEvent() {
|
||||
var p = <PageModule.Page>builder.parse('<Page><Page.actionBar><ActionBar><ActionBar.actionItems><ActionItem tap="{{ test }}"/></ActionBar.actionItems></ActionBar></Page.actionBar></Page>');
|
||||
const p = <Page>builder.parse('<Page><Page.actionBar><ActionBar><ActionBar.actionItems><ActionItem tap="{{ test }}"/></ActionBar.actionItems></ActionBar></Page.actionBar></Page>');
|
||||
|
||||
var testAction = function (views: Array<viewModule.View>) {
|
||||
var page = <PageModule.Page>views[0];
|
||||
var firstHandlerCallCounter = 0;
|
||||
var secondHandlerCallCounter = 0;
|
||||
var firstHandler = function () { firstHandlerCallCounter++; };
|
||||
var secondHandler = function () { secondHandlerCallCounter++; };
|
||||
const testAction = function (views: Array<View>) {
|
||||
const page = <Page>views[0];
|
||||
let firstHandlerCallCounter = 0;
|
||||
let secondHandlerCallCounter = 0;
|
||||
const firstHandler = function () { firstHandlerCallCounter++; };
|
||||
const secondHandler = function () { secondHandlerCallCounter++; };
|
||||
|
||||
page.bindingContext = new Observable({ "test": firstHandler });
|
||||
|
||||
var actionBarItem = page.actionBar.actionItems.getItemAt(0);
|
||||
const actionBarItem = page.actionBar.actionItems.getItemAt(0);
|
||||
|
||||
TKUnit.assertEqual((<any>actionBarItem)._observers["tap"].length, 1, "There should be only one listener");
|
||||
TKUnit.assertEqual((<any>actionBarItem)._observers["tap"][0].callback + "", "function () { firstHandlerCallCounter++; }", "First handler is not equal");
|
||||
@@ -175,25 +175,24 @@ export function test_ActionBarItemBindingToEvent() {
|
||||
|
||||
TKUnit.assertEqual((<any>actionBarItem)._observers["tap"].length, 1, "There should be only one listener");
|
||||
TKUnit.assertEqual((<any>actionBarItem)._observers["tap"][0].callback + "", "function () { secondHandlerCallCounter++; }", "Second handler is not equal");
|
||||
}
|
||||
};
|
||||
|
||||
helper.navigate(function () { return p; });
|
||||
testAction([p]);
|
||||
}
|
||||
|
||||
export function test_Setting_ActionItems_doesnt_thrown() {
|
||||
let page: Page;
|
||||
let label: Label;
|
||||
let gotException = false;
|
||||
|
||||
var page: PageModule.Page;
|
||||
var label: LabelModule.Label;
|
||||
var gotException = false;
|
||||
|
||||
var pageFactory = function (): PageModule.Page {
|
||||
page = new PageModule.Page();
|
||||
var actionItem = new actionBarModule.ActionItem();
|
||||
const pageFactory = function (): Page {
|
||||
page = new Page();
|
||||
const actionItem = new actionBarModule.ActionItem();
|
||||
actionItem.text = "Item";
|
||||
page.actionBar.actionItems.addItem(actionItem);
|
||||
|
||||
label = new LabelModule.Label();
|
||||
label = new Label();
|
||||
label.text = "Text";
|
||||
page.content = label;
|
||||
return page;
|
||||
@@ -211,9 +210,9 @@ export function test_Setting_ActionItems_doesnt_thrown() {
|
||||
|
||||
export function test_Setting_ActionItemsWithNumberAsText_doesnt_thrown() {
|
||||
|
||||
var gotException = false;
|
||||
let gotException = false;
|
||||
|
||||
var moduleName = __dirname.substr(fs.knownFolders.currentApp().path.length);
|
||||
const moduleName = __dirname.substr(fs.knownFolders.currentApp().path.length);
|
||||
|
||||
try {
|
||||
helper.navigateToModule(moduleName + "/ActionBar_NumberAsText");
|
||||
@@ -226,19 +225,19 @@ export function test_Setting_ActionItemsWithNumberAsText_doesnt_thrown() {
|
||||
}
|
||||
|
||||
export function test_CanDefineEverythingAsContentBetweenTheTwoTags() {
|
||||
var moduleName = __dirname.substr(fs.knownFolders.currentApp().path.length);
|
||||
helper.navigateToModuleAndRunTest(moduleName + "/ActionBar_BetweenTags", undefined, (page: PageModule.Page) => {
|
||||
const moduleName = __dirname.substr(fs.knownFolders.currentApp().path.length);
|
||||
helper.navigateToModuleAndRunTest(moduleName + "/ActionBar_BetweenTags", undefined, (page: Page) => {
|
||||
|
||||
TKUnit.assertNotNull(page.actionBar.navigationButton);
|
||||
TKUnit.assertEqual(page.actionBar.navigationButton.text, "nb");
|
||||
|
||||
TKUnit.assertNull(page.actionBar.title);
|
||||
TKUnit.assertNotNull(page.actionBar.titleView);
|
||||
TKUnit.assertTrue(page.actionBar.titleView instanceof LabelModule.Label);
|
||||
TKUnit.assertEqual((<LabelModule.Label>page.actionBar.titleView).text, "tv");
|
||||
TKUnit.assertTrue(page.actionBar.titleView instanceof Label);
|
||||
TKUnit.assertEqual((<Label>page.actionBar.titleView).text, "tv");
|
||||
|
||||
TKUnit.assertNotNull(page.actionBar.actionItems);
|
||||
var items = page.actionBar.actionItems.getItems();
|
||||
const items = page.actionBar.actionItems.getItems();
|
||||
TKUnit.assertEqual(items.length, 3);
|
||||
|
||||
TKUnit.assertEqual(items[0].text, "i1");
|
||||
@@ -248,19 +247,19 @@ export function test_CanDefineEverythingAsContentBetweenTheTwoTags() {
|
||||
}
|
||||
|
||||
export function test_LoadedEventsOrder() {
|
||||
var loadedEvents = new Array<string>();
|
||||
var pageFactory = function (): PageModule.Page {
|
||||
var page = new PageModule.Page();
|
||||
page.on(viewModule.View.loadedEvent, () => {
|
||||
const loadedEvents = new Array<string>();
|
||||
const pageFactory = function (): Page {
|
||||
const page = new Page();
|
||||
page.on(View.loadedEvent, () => {
|
||||
loadedEvents.push("page");
|
||||
});
|
||||
|
||||
page.actionBar.on(viewModule.View.loadedEvent, () => {
|
||||
page.actionBar.on(View.loadedEvent, () => {
|
||||
loadedEvents.push("action-bar");
|
||||
});
|
||||
|
||||
var content = new LabelModule.Label();
|
||||
content.on(viewModule.View.loadedEvent, () => {
|
||||
const content = new Label();
|
||||
content.on(View.loadedEvent, () => {
|
||||
loadedEvents.push("content");
|
||||
});
|
||||
page.content = content;
|
||||
@@ -274,14 +273,14 @@ export function test_LoadedEventsOrder() {
|
||||
}
|
||||
|
||||
export function test_LoadedEventsOrder_WithoutPageContent() {
|
||||
var loadedEvents = new Array<string>();
|
||||
var pageFactory = function (): PageModule.Page {
|
||||
var page = new PageModule.Page();
|
||||
page.on(viewModule.View.loadedEvent, () => {
|
||||
const loadedEvents = new Array<string>();
|
||||
const pageFactory = function (): Page {
|
||||
const page = new Page();
|
||||
page.on(View.loadedEvent, () => {
|
||||
loadedEvents.push("page");
|
||||
});
|
||||
|
||||
page.actionBar.on(viewModule.View.loadedEvent, () => {
|
||||
page.actionBar.on(View.loadedEvent, () => {
|
||||
loadedEvents.push("action-bar");
|
||||
});
|
||||
|
||||
@@ -294,8 +293,8 @@ export function test_LoadedEventsOrder_WithoutPageContent() {
|
||||
}
|
||||
|
||||
export function test_setId() {
|
||||
var pageFactory = function (): PageModule.Page {
|
||||
var page = new PageModule.Page();
|
||||
const pageFactory = function (): Page {
|
||||
const page = new Page();
|
||||
page.actionBar.id = "myId";
|
||||
|
||||
return page;
|
||||
@@ -310,11 +309,11 @@ export function test_setId() {
|
||||
}
|
||||
|
||||
export function createPageAndNavigate() {
|
||||
var page: PageModule.Page;
|
||||
var pageFactory = function (): PageModule.Page {
|
||||
page = new PageModule.Page();
|
||||
let page: Page;
|
||||
const pageFactory = function (): Page {
|
||||
page = new Page();
|
||||
|
||||
var label = new LabelModule.Label();
|
||||
const label = new Label();
|
||||
label.text = "Text";
|
||||
page.content = label;
|
||||
return page;
|
||||
|
||||
@@ -6,12 +6,12 @@ import { Visibility } from "ui/enums";
|
||||
global.moduleMerge(actionTestsCommon, exports);
|
||||
|
||||
export function test_actionItem_visibility() {
|
||||
var actionItem = new ActionItem();
|
||||
const actionItem = new ActionItem();
|
||||
actionItem.text = "Test";
|
||||
var page = actionTestsCommon.createPageAndNavigate();
|
||||
const page = actionTestsCommon.createPageAndNavigate();
|
||||
page.actionBar.actionItems.addItem(actionItem);
|
||||
var toolbar = <android.support.v7.widget.Toolbar>(<any>page.actionBar)._toolbar;
|
||||
var menu = toolbar.getMenu();
|
||||
const toolbar = <android.support.v7.widget.Toolbar>(<any>page.actionBar)._toolbar;
|
||||
const menu = toolbar.getMenu();
|
||||
|
||||
TKUnit.assertTrue(menu.hasVisibleItems(), "Visibility does not work");
|
||||
actionItem.visibility = Visibility.collapse;
|
||||
@@ -19,12 +19,12 @@ export function test_actionItem_visibility() {
|
||||
}
|
||||
|
||||
export function test_navigationButton_visibility() {
|
||||
var actionItem = new ActionItem();
|
||||
const actionItem = new ActionItem();
|
||||
actionItem.icon = "~/small-image.png";
|
||||
var page = actionTestsCommon.createPageAndNavigate();
|
||||
const page = actionTestsCommon.createPageAndNavigate();
|
||||
page.actionBar.navigationButton = actionItem;
|
||||
|
||||
var toolbar = <android.support.v7.widget.Toolbar>(<any>page.actionBar)._toolbar;
|
||||
const toolbar = <android.support.v7.widget.Toolbar>(<any>page.actionBar)._toolbar;
|
||||
|
||||
TKUnit.assertNotNull(toolbar.getNavigationIcon(), "Visibility does not work");
|
||||
actionItem.visibility = Visibility.collapse;
|
||||
|
||||
@@ -13,7 +13,8 @@
|
||||
}
|
||||
},
|
||||
"dependencies": {
|
||||
"tns-core-modules": "2.4.0"
|
||||
"tns-core-modules": "2.4.0",
|
||||
"tns-core-modules-widgets": "file:///Users/vakrilov/Work/Projects/tns-core-modules-widgets/dist/tns-core-modules-widgets-2.5.0.tgz"
|
||||
},
|
||||
"devDependencies": {
|
||||
"tns-platform-declarations": "*",
|
||||
|
||||
@@ -28,6 +28,7 @@ export class ActionBarBase extends View implements ActionBarDefinition {
|
||||
set navigationButton(value: NavigationButton) {
|
||||
if (this._navigationButton !== value) {
|
||||
if (this._navigationButton) {
|
||||
this._removeView(this._navigationButton);
|
||||
this._navigationButton.actionBar = undefined;
|
||||
}
|
||||
|
||||
@@ -35,6 +36,7 @@ export class ActionBarBase extends View implements ActionBarDefinition {
|
||||
|
||||
if (this._navigationButton) {
|
||||
this._navigationButton.actionBar = this;
|
||||
this._addView(this._navigationButton);
|
||||
}
|
||||
|
||||
this.update();
|
||||
@@ -76,12 +78,6 @@ export class ActionBarBase extends View implements ActionBarDefinition {
|
||||
}
|
||||
set page(value: Page) {
|
||||
this._page = value;
|
||||
// // TODO: Move this in _eachChildView of Page class.
|
||||
// this.unbind("bindingContext");
|
||||
// this.bind({
|
||||
// sourceProperty: "bindingContext",
|
||||
// targetProperty: "bindingContext"
|
||||
// }, this._page);
|
||||
}
|
||||
|
||||
get android(): AndroidActionBarSettings {
|
||||
@@ -104,7 +100,7 @@ export class ActionBarBase extends View implements ActionBarDefinition {
|
||||
this._actionItems = new ActionItems(this);
|
||||
}
|
||||
|
||||
public static onTitleChanged
|
||||
public static onTitleChanged;
|
||||
|
||||
public update() {
|
||||
//
|
||||
@@ -132,26 +128,11 @@ export class ActionBarBase extends View implements ActionBarDefinition {
|
||||
}
|
||||
}
|
||||
|
||||
// public _onBindingContextChanged(oldValue: any, newValue: any) {
|
||||
// super._onBindingContextChanged(oldValue, newValue);
|
||||
// if (this._navigationButton) {
|
||||
// this._navigationButton.bindingContext = newValue;
|
||||
// }
|
||||
|
||||
// this._actionItems.getItems().forEach((item, i, arr) => { item.bindingContext = newValue; });
|
||||
// }
|
||||
|
||||
public eachChildView(callback: (child: View) => boolean) {
|
||||
const titleView = this.titleView;
|
||||
if (titleView) {
|
||||
callback(titleView);
|
||||
}
|
||||
|
||||
this.actionItems.getItems().forEach((actionItem) => {
|
||||
if (actionItem.actionView) {
|
||||
callback(actionItem.actionView);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public eachChild(callback: (child: ViewBase) => boolean) {
|
||||
@@ -199,6 +180,9 @@ export class ActionItems implements ActionItemsDefinition {
|
||||
|
||||
this._items.push(item);
|
||||
item.actionBar = this._actionBar;
|
||||
|
||||
this._actionBar._addView(item);
|
||||
|
||||
this.invalidate();
|
||||
}
|
||||
|
||||
@@ -207,12 +191,14 @@ export class ActionItems implements ActionItemsDefinition {
|
||||
throw new Error("Cannot remove empty item");
|
||||
}
|
||||
|
||||
var itemIndex = this._items.indexOf(item);
|
||||
const itemIndex = this._items.indexOf(item);
|
||||
if (itemIndex < 0) {
|
||||
throw new Error("Cannot find item to remove");
|
||||
}
|
||||
|
||||
this._items.splice(itemIndex, 1);
|
||||
this._actionBar._removeView(item);
|
||||
|
||||
item.actionBar = undefined;
|
||||
this.invalidate();
|
||||
}
|
||||
@@ -222,7 +208,7 @@ export class ActionItems implements ActionItemsDefinition {
|
||||
}
|
||||
|
||||
public getVisibleItems(): Array<ActionItemDefinition> {
|
||||
var visibleItems = [];
|
||||
const visibleItems = [];
|
||||
this._items.forEach((item) => {
|
||||
if (isVisible(item)) {
|
||||
visibleItems.push(item);
|
||||
@@ -279,14 +265,20 @@ export class ActionItemBase extends ViewBase implements ActionItemDefinition {
|
||||
}
|
||||
set actionView(value: View) {
|
||||
if (this._actionView !== value) {
|
||||
if (this._actionView && this._actionBar) {
|
||||
this._actionBar._removeView(this._actionView);
|
||||
if (this._actionView) {
|
||||
this._actionView.style[horizontalAlignmentProperty.cssName] = unsetValue;
|
||||
this._actionView.style[verticalAlignmentProperty.cssName] = unsetValue;
|
||||
this._removeView(this._actionView);
|
||||
}
|
||||
|
||||
this._actionView = value;
|
||||
this._addActionViewToActionBar();
|
||||
|
||||
if (this._actionView) {
|
||||
this._addView(this._actionView);
|
||||
this._actionView.style[horizontalAlignmentProperty.cssName] = HorizontalAlignment.CENTER;
|
||||
this._actionView.style[verticalAlignmentProperty.cssName] = VerticalAlignment.MIDDLE;
|
||||
}
|
||||
|
||||
if (this._actionBar) {
|
||||
this._actionBar.update();
|
||||
}
|
||||
@@ -299,11 +291,6 @@ export class ActionItemBase extends ViewBase implements ActionItemDefinition {
|
||||
set actionBar(value: ActionBarDefinition) {
|
||||
if (value !== this._actionBar) {
|
||||
this._actionBar = value;
|
||||
if (this._actionBar) {
|
||||
// ActionBarBase overrides _eachChildView so bindingContext should work without any manual work.
|
||||
// this.bindingContext = this._actionBar.bindingContext;
|
||||
this._addActionViewToActionBar();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -319,11 +306,9 @@ export class ActionItemBase extends ViewBase implements ActionItemDefinition {
|
||||
this.actionView = value;
|
||||
}
|
||||
|
||||
private _addActionViewToActionBar() {
|
||||
if (this._actionView && !this._actionView._isAddedToNativeVisualTree && this._actionBar) {
|
||||
this._actionView.style[horizontalAlignmentProperty.cssName] = HorizontalAlignment.CENTER;
|
||||
this._actionView.style[verticalAlignmentProperty.cssName] = VerticalAlignment.MIDDLE;
|
||||
this._actionBar._addView(this._actionView);
|
||||
public eachChild(callback: (child: ViewBase) => boolean) {
|
||||
if (this._actionView) {
|
||||
callback(this._actionView);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ export class AndroidActionBarSettings implements AndroidActionBarSettingsDefinit
|
||||
}
|
||||
}
|
||||
|
||||
export class NavigationButton extends ActionItemBase {
|
||||
export class NavigationButton extends ActionItem {
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user