From 00d82010ae70b82e098955ed42e5ccdd95335c1d Mon Sep 17 00:00:00 2001 From: Hristo Hristov Date: Mon, 3 Apr 2017 11:08:11 +0300 Subject: [PATCH] propagate inheritable values only on child added. (#3926) segmented bar createNativeView returns the nativeView --- .../ui/core/properties/properties.d.ts | 4 +- .../ui/core/properties/properties.ts | 52 ++++++------------- .../ui/core/view-base/view-base.ts | 4 +- .../ui/segmented-bar/segmented-bar.android.ts | 4 ++ 4 files changed, 25 insertions(+), 39 deletions(-) diff --git a/tns-core-modules/ui/core/properties/properties.d.ts b/tns-core-modules/ui/core/properties/properties.d.ts index bdb338576..9fb03194b 100644 --- a/tns-core-modules/ui/core/properties/properties.d.ts +++ b/tns-core-modules/ui/core/properties/properties.d.ts @@ -111,8 +111,8 @@ export class CssAnimationProperty { export function initNativeView(view: ViewBase): void; export function resetNativeView(view: ViewBase): void; export function resetCSSProperties(style: Style): void; -export function propagateInheritableProperties(view: ViewBase): void; -export function propagateInheritableCssProperties(style: Style): void; +export function propagateInheritableProperties(view: ViewBase, childView: ViewBase): void; +export function propagateInheritableCssProperties(parentStyle: Style, childStyle: Style): void; export function clearInheritedProperties(view: ViewBase): void; export function makeValidator(...values: T[]): (value: any) => value is T; diff --git a/tns-core-modules/ui/core/properties/properties.ts b/tns-core-modules/ui/core/properties/properties.ts index b279fe237..79e55bef2 100644 --- a/tns-core-modules/ui/core/properties/properties.ts +++ b/tns-core-modules/ui/core/properties/properties.ts @@ -1065,46 +1065,28 @@ export function resetCSSProperties(style: Style): void { } } -export function propagateInheritableProperties(view: ViewBase): void { +export function propagateInheritableProperties(view: ViewBase, child: ViewBase): void { const inheritablePropertyValues = inheritablePropertyValuesOn(view); - if (inheritablePropertyValues.length === 0) { - return; - } - - view.eachChild((child) => { - for (let pair of inheritablePropertyValues) { - const prop = pair.property; - const sourceKey = prop.sourceKey; - const currentValueSource: number = child[sourceKey] || ValueSource.Default; - if (currentValueSource <= ValueSource.Inherited) { - prop.setInheritedValue.call(child, pair.value); - } + for (let pair of inheritablePropertyValues) { + const prop = pair.property; + const sourceKey = prop.sourceKey; + const currentValueSource: number = child[sourceKey] || ValueSource.Default; + if (currentValueSource <= ValueSource.Inherited) { + prop.setInheritedValue.call(child, pair.value); } - - return true; - }); + } } -export function propagateInheritableCssProperties(style: Style): void { - const view = style.view; - const inheritableCssPropertyValues = inheritableCssPropertyValuesOn(style); - if (inheritableCssPropertyValues.length === 0) { - return; - } - - view.eachChild((child) => { - for (let pair of inheritableCssPropertyValues) { - const prop = pair.property; - const sourceKey = prop.sourceKey; - const style = child.style; - const currentValueSource: number = style[sourceKey] || ValueSource.Default; - if (currentValueSource <= ValueSource.Inherited) { - prop.setInheritedValue.call(style, pair.value, ValueSource.Inherited); - } +export function propagateInheritableCssProperties(parentStyle: Style, childStyle: Style): void { + const inheritableCssPropertyValues = inheritableCssPropertyValuesOn(parentStyle); + for (let pair of inheritableCssPropertyValues) { + const prop = pair.property; + const sourceKey = prop.sourceKey; + const currentValueSource: number = childStyle[sourceKey] || ValueSource.Default; + if (currentValueSource <= ValueSource.Inherited) { + prop.setInheritedValue.call(childStyle, pair.value, ValueSource.Inherited); } - - return true; - }); + } } export function makeValidator(...values: T[]): (value: any) => value is T { diff --git a/tns-core-modules/ui/core/view-base/view-base.ts b/tns-core-modules/ui/core/view-base/view-base.ts index e6ff11388..77737d81f 100644 --- a/tns-core-modules/ui/core/view-base/view-base.ts +++ b/tns-core-modules/ui/core/view-base/view-base.ts @@ -534,14 +534,14 @@ export abstract class ViewBase extends Observable implements ViewBaseDefinition } public _addViewCore(view: ViewBase, atIndex?: number) { - propagateInheritableProperties(this); + propagateInheritableProperties(this, view); const styleScope = this._styleScope; if (styleScope) { view._setStyleScope(styleScope); } - propagateInheritableCssProperties(this.style); + propagateInheritableCssProperties(this.style, view.style); if (this._context) { view._setupUI(this._context, atIndex); diff --git a/tns-core-modules/ui/segmented-bar/segmented-bar.android.ts b/tns-core-modules/ui/segmented-bar/segmented-bar.android.ts index ad61f947a..b32a8f305 100644 --- a/tns-core-modules/ui/segmented-bar/segmented-bar.android.ts +++ b/tns-core-modules/ui/segmented-bar/segmented-bar.android.ts @@ -92,6 +92,10 @@ function initializeNativeClasses(): void { export class SegmentedBarItem extends SegmentedBarItemBase { nativeView: android.widget.TextView; + public createNativeView(): android.widget.TextView { + return this.nativeView; + } + public setupNativeView(tabIndex: number): void { // TabHost.TabSpec.setIndicator DOES NOT WORK once the title has been set. // http://stackoverflow.com/questions/2935781/modify-tab-indicator-dynamically-in-android