fix: tab navigations don't work with lowercase xml (#8016)

This commit is contained in:
Martin Yankov
2019-11-21 14:48:33 +02:00
committed by GitHub
parent b069ff38f3
commit 800f5bcfe4
11 changed files with 116 additions and 17 deletions

View File

@@ -2304,6 +2304,9 @@ export class TabStripItem extends View {
image: Image;
// (undocumented)
_index: number;
label: Label;
on(eventNames: string, callback: (data: EventData) => void);

View File

@@ -1,12 +1,12 @@
// Types
import { TabNavigationBase as TabNavigationBaseDefinition, SelectedIndexChangedEventData } from ".";
import { TabContentItem } from "../tab-content-item";
import { TabStrip } from "../tab-strip";
import { TabStripItem } from "../tab-strip-item";
import { ViewBase, AddArrayFromBuilder, AddChildFromBuilder, EventData } from "../../core/view";
// Requires
import { View, Property, CoercibleProperty, isIOS, Color } from "../../core/view";
import { View, Property, CoercibleProperty, isIOS } from "../../core/view";
import { TabContentItem } from "../tab-content-item";
import { TabStrip } from "../tab-strip";
// TODO: Impl trace
// export const traceCategory = "TabView";
@@ -29,14 +29,14 @@ export class TabNavigationBase extends View implements TabNavigationBaseDefiniti
}
public _addChildFromBuilder(name: string, value: any): void {
if (name === "TabContentItem") {
if (value instanceof TabContentItem) {
if (!this.items) {
this.items = new Array<TabContentItem>();
}
this.items.push(<TabContentItem>value);
this._addView(value);
// selectedIndexProperty.coerce(this);
} else if (name === "TabStrip") {
} else if (value instanceof TabStrip) {
// Setting tabStrip will trigger onTabStripChanged
this.tabStrip = value;
}

View File

@@ -3,8 +3,6 @@ import { TabStripItem as TabStripItemDefinition } from ".";
import { PropertyChangeData } from "../../../data/observable";
import { TabNavigationBase } from "../tab-navigation-base";
import { TabStrip } from "../tab-strip";
import { Image } from "../../image/image";
import { Label } from "../../label/label";
import { Color } from "../../../color";
import { AddChildFromBuilder } from "../../core/view";
@@ -12,8 +10,9 @@ import { AddChildFromBuilder } from "../../core/view";
import {
View, ViewBase, CSSType, backgroundColorProperty, backgroundInternalProperty, PseudoClassHandler
} from "../../core/view";
import { Tabs } from "../../tabs";
import { isIOS } from "../../../platform";
import { Image } from "../../image/image";
import { Label } from "../../label/label";
export * from "../../core/view";
export const traceCategory = "TabView";
@@ -173,14 +172,14 @@ export class TabStripItem extends View implements TabStripItemDefinition, AddChi
}
public _addChildFromBuilder(name: string, value: any): void {
if (name === "Image") {
if (value instanceof Image) {
this.image = <Image>value;
this.iconSource = (<Image>value).src;
this._addView(value);
// selectedIndexProperty.coerce(this);
}
if (name === "Label") {
if (value instanceof Label) {
this.label = <Label>value;
this.title = (<Label>value).text;
this._addView(value);
@@ -213,7 +212,9 @@ export class TabStripItem extends View implements TabStripItemDefinition, AddChi
const parent = <TabStrip>this.parent;
const tabStripParent = parent && <TabNavigationBase>parent.parent;
if (this._index === tabStripParent.selectedIndex &&
!(isIOS && tabStripParent instanceof Tabs)) {
!(isIOS && tabStripParent.cssType.toLowerCase() === "tabs")) {
// HACK: tabStripParent instanceof Tabs creates a circular dependency
// HACK: tabStripParent.cssType === "Tabs" is a hacky workaround
this._goToVisualState("highlighted");
}
} else {

View File

@@ -2,7 +2,6 @@
import { Color } from "../../../color";
import { AddArrayFromBuilder, AddChildFromBuilder, EventData, ViewBase } from "../../core/view";
import { TabNavigationBase } from "../tab-navigation-base";
import { TabStripItem } from "../tab-strip-item";
import { TabStripItemEventData, TabStrip as TabStripDefinition } from "./";
// Requires
@@ -10,6 +9,7 @@ import {
backgroundColorProperty, backgroundInternalProperty, booleanConverter,
colorProperty, CSSType, fontInternalProperty, Property, View
} from "../../core/view";
import { TabStripItem } from "../tab-strip-item";
import { textTransformProperty } from "../../text-base";
export const traceCategory = "TabView";
@@ -44,7 +44,7 @@ export class TabStrip extends View implements TabStripDefinition, AddChildFromBu
}
public _addChildFromBuilder(name: string, value: any): void {
if (name === "TabStripItem") {
if (value instanceof TabStripItem) {
if (!this.items) {
this.items = new Array<TabStripItem>();
}

View File

@@ -140,7 +140,7 @@ export class TabViewBase extends View implements TabViewDefinition, AddChildFrom
}
public _addChildFromBuilder(name: string, value: any): void {
if (name === "TabViewItem") {
if (value instanceof TabViewItemBase) {
if (!this.items) {
this.items = new Array<TabViewItemBase>();
}

View File

@@ -1,6 +1,7 @@
{
"main": "app.js",
"android": {
"v8Flags": "--expose_gc"
"v8Flags": "--expose_gc",
"markingMode": "none"
}
}

View File

@@ -199,6 +199,9 @@ allTests["LABEL"] = labelTests;
import * as bottomNavigationTests from "./ui/bottom-navigation/bottom-navigation-tests";
allTests["BOTTOM-NAVIGATION"] = bottomNavigationTests;
import * as bottomNavigationTestsNew from "./ui/bottom-navigation/bottom-navigation-tests-new";
allTests["BOTTOM-NAVIGATION-NEW"] = bottomNavigationTestsNew;
import * as bottomNavigationNavigationTests from "./ui/bottom-navigation/bottom-navigation-navigation-tests";
// TODO: uncomment this
// allTests["BOTTOM-NAVIGATION-NAVIGATION"] = bottomNavigationNavigationTests;
@@ -206,12 +209,18 @@ import * as bottomNavigationNavigationTests from "./ui/bottom-navigation/bottom-
import * as tabsTests from "./ui/tabs/tabs-tests";
allTests["TABS"] = tabsTests;
import * as tabsTestsNew from "./ui/tabs/tabs-tests-new";
allTests["TABS-NEW"] = tabsTestsNew;
import * as tabsNavigationTests from "./ui/tabs/tabs-navigation-tests";
allTests["TABS-NAVIGATION"] = tabsNavigationTests;
import * as tabViewTests from "./ui/tab-view/tab-view-tests";
allTests["TAB-VIEW"] = tabViewTests;
import * as tabViewTestsNew from "./ui/tab-view/tab-view-tests-new";
allTests["TAB-VIEW-NEW"] = tabViewTestsNew;
import * as tabViewNavigationTests from "./ui/tab-view/tab-view-navigation-tests";
allTests["TAB-VIEW-NAVIGATION"] = tabViewNavigationTests;

View File

@@ -0,0 +1,33 @@
import { Image, Label, BottomNavigation, Builder, TabContentItem, TabStrip, TabStripItem } from "@nativescript/core/ui";
import * as TKUnit from "../../tk-unit";
export function test_lowercase_declaration() {
const root = Builder.parse(`
<bottom-navigation>
<tab-strip id="tab-strip">
<tab-strip-item id="tab-strip-item">
<image src="res://icon" id="tab-strip-item-image" />
<label text="test" id="tab-strip-item-label" />
</tab-strip-item>
</tab-strip>
<tab-content-item id="tab-content-item">
<label text="test" id="tab-content-item-label" />
</tab-content-item>
</bottom-navigation>
`);
const tabStrip = root.getViewById("tab-strip");
const tabStripItem = root.getViewById("tab-strip-item");
const tabStripItemImage = root.getViewById("tab-strip-item-image");
const tabStripItemLabel = root.getViewById("tab-strip-item-label");
const tabContentItem = root.getViewById("tab-content-item");
const tabContentItemLabel = root.getViewById("tab-content-item-label");
TKUnit.assert(root instanceof BottomNavigation, "Expected result: BottomNavigation!; Actual result: " + root);
TKUnit.assert(tabStrip instanceof TabStrip, "Expected result: TabStrip!; Actual result: " + tabStrip);
TKUnit.assert(tabStripItem instanceof TabStripItem, "Expected result: TabStripItem!; Actual result: " + tabStripItem);
TKUnit.assert(tabStripItemImage instanceof Image, "Expected result: Image!; Actual result: " + tabStripItemImage);
TKUnit.assert(tabStripItemLabel instanceof Label, "Expected result: Label!; Actual result: " + tabStripItemLabel);
TKUnit.assert(tabContentItem instanceof TabContentItem, "Expected result: TabContentItem!; Actual result: " + tabContentItem);
TKUnit.assert(tabContentItemLabel instanceof Label, "Expected result: Label!; Actual result: " + tabContentItemLabel);
}

View File

@@ -0,0 +1,19 @@
import { Label, Builder, TabView, TabViewItem } from "@nativescript/core/ui";
import * as TKUnit from "../../tk-unit";
export function test_lowercase_declaration() {
const root = Builder.parse(`
<tab-view>
<tab-view-item id="tab-view-item">
<label text="test" id="tab-view-item-label" />
</tab-view-item>
</tab-view>
`);
const tabViewItem = root.getViewById("tab-view-item");
const tabViewItemLabel = root.getViewById("tab-view-item-label");
TKUnit.assert(root instanceof TabView, "Expected result: TabView!; Actual result: " + root);
TKUnit.assert(tabViewItem instanceof TabViewItem, "Expected result: TabViewItem!; Actual result: " + tabViewItem);
TKUnit.assert(tabViewItemLabel instanceof Label, "Expected result: Label!; Actual result: " + tabViewItemLabel);
}

View File

@@ -0,0 +1,33 @@
import { Image, Label, Builder, TabContentItem, Tabs, TabStrip, TabStripItem } from "@nativescript/core/ui";
import * as TKUnit from "../../tk-unit";
export function test_lowercase_declaration() {
const root = Builder.parse(`
<tabs>
<tab-strip id="tab-strip">
<tab-strip-item id="tab-strip-item">
<image src="res://icon" id="tab-strip-item-image" />
<label text="test" id="tab-strip-item-label" />
</tab-strip-item>
</tab-strip>
<tab-content-item id="tab-content-item">
<label text="test" id="tab-content-item-label" />
</tab-content-item>
</tabs>
`);
const tabStrip = root.getViewById("tab-strip");
const tabStripItem = root.getViewById("tab-strip-item");
const tabStripItemImage = root.getViewById("tab-strip-item-image");
const tabStripItemLabel = root.getViewById("tab-strip-item-label");
const tabContentItem = root.getViewById("tab-content-item");
const tabContentItemLabel = root.getViewById("tab-content-item-label");
TKUnit.assert(root instanceof Tabs, "Expected result: Tabs!; Actual result: " + root);
TKUnit.assert(tabStrip instanceof TabStrip, "Expected result: TabStrip!; Actual result: " + tabStrip);
TKUnit.assert(tabStripItem instanceof TabStripItem, "Expected result: TabStripItem!; Actual result: " + tabStripItem);
TKUnit.assert(tabStripItemImage instanceof Image, "Expected result: Image!; Actual result: " + tabStripItemImage);
TKUnit.assert(tabStripItemLabel instanceof Label, "Expected result: Label!; Actual result: " + tabStripItemLabel);
TKUnit.assert(tabContentItem instanceof TabContentItem, "Expected result: TabContentItem!; Actual result: " + tabContentItem);
TKUnit.assert(tabContentItemLabel instanceof Label, "Expected result: Label!; Actual result: " + tabContentItemLabel);
}

View File

@@ -12,8 +12,8 @@ const { NativeScriptWorkerPlugin } = require("nativescript-worker-loader/NativeS
const TerserPlugin = require("terser-webpack-plugin");
const hashSalt = Date.now().toString();
const ANDROID_MAX_CYCLES = 66;
const IOS_MAX_CYCLES = 39;
const ANDROID_MAX_CYCLES = 63;
const IOS_MAX_CYCLES = 36;
let numCyclesDetected = 0;
module.exports = env => {