Skip to content

Commit 00d8201

Browse files
author
Hristo Hristov
authored
propagate inheritable values only on child added. (NativeScript#3926)
segmented bar createNativeView returns the nativeView
1 parent b2c6cf2 commit 00d8201

File tree

4 files changed

+25
-39
lines changed

4 files changed

+25
-39
lines changed

tns-core-modules/ui/core/properties/properties.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ export class CssAnimationProperty<T extends Style, U> {
111111
export function initNativeView(view: ViewBase): void;
112112
export function resetNativeView(view: ViewBase): void;
113113
export function resetCSSProperties(style: Style): void;
114-
export function propagateInheritableProperties(view: ViewBase): void;
115-
export function propagateInheritableCssProperties(style: Style): void;
114+
export function propagateInheritableProperties(view: ViewBase, childView: ViewBase): void;
115+
export function propagateInheritableCssProperties(parentStyle: Style, childStyle: Style): void;
116116
export function clearInheritedProperties(view: ViewBase): void;
117117

118118
export function makeValidator<T>(...values: T[]): (value: any) => value is T;

tns-core-modules/ui/core/properties/properties.ts

Lines changed: 17 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,46 +1065,28 @@ export function resetCSSProperties(style: Style): void {
10651065
}
10661066
}
10671067

1068-
export function propagateInheritableProperties(view: ViewBase): void {
1068+
export function propagateInheritableProperties(view: ViewBase, child: ViewBase): void {
10691069
const inheritablePropertyValues = inheritablePropertyValuesOn(view);
1070-
if (inheritablePropertyValues.length === 0) {
1071-
return;
1072-
}
1073-
1074-
view.eachChild((child) => {
1075-
for (let pair of inheritablePropertyValues) {
1076-
const prop = pair.property;
1077-
const sourceKey = prop.sourceKey;
1078-
const currentValueSource: number = child[sourceKey] || ValueSource.Default;
1079-
if (currentValueSource <= ValueSource.Inherited) {
1080-
prop.setInheritedValue.call(child, pair.value);
1081-
}
1070+
for (let pair of inheritablePropertyValues) {
1071+
const prop = pair.property;
1072+
const sourceKey = prop.sourceKey;
1073+
const currentValueSource: number = child[sourceKey] || ValueSource.Default;
1074+
if (currentValueSource <= ValueSource.Inherited) {
1075+
prop.setInheritedValue.call(child, pair.value);
10821076
}
1083-
1084-
return true;
1085-
});
1086-
}
1087-
1088-
export function propagateInheritableCssProperties(style: Style): void {
1089-
const view = style.view;
1090-
const inheritableCssPropertyValues = inheritableCssPropertyValuesOn(style);
1091-
if (inheritableCssPropertyValues.length === 0) {
1092-
return;
10931077
}
1078+
}
10941079

1095-
view.eachChild((child) => {
1096-
for (let pair of inheritableCssPropertyValues) {
1097-
const prop = pair.property;
1098-
const sourceKey = prop.sourceKey;
1099-
const style = child.style;
1100-
const currentValueSource: number = style[sourceKey] || ValueSource.Default;
1101-
if (currentValueSource <= ValueSource.Inherited) {
1102-
prop.setInheritedValue.call(style, pair.value, ValueSource.Inherited);
1103-
}
1080+
export function propagateInheritableCssProperties(parentStyle: Style, childStyle: Style): void {
1081+
const inheritableCssPropertyValues = inheritableCssPropertyValuesOn(parentStyle);
1082+
for (let pair of inheritableCssPropertyValues) {
1083+
const prop = pair.property;
1084+
const sourceKey = prop.sourceKey;
1085+
const currentValueSource: number = childStyle[sourceKey] || ValueSource.Default;
1086+
if (currentValueSource <= ValueSource.Inherited) {
1087+
prop.setInheritedValue.call(childStyle, pair.value, ValueSource.Inherited);
11041088
}
1105-
1106-
return true;
1107-
});
1089+
}
11081090
}
11091091

11101092
export function makeValidator<T>(...values: T[]): (value: any) => value is T {

tns-core-modules/ui/core/view-base/view-base.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -534,14 +534,14 @@ export abstract class ViewBase extends Observable implements ViewBaseDefinition
534534
}
535535

536536
public _addViewCore(view: ViewBase, atIndex?: number) {
537-
propagateInheritableProperties(this);
537+
propagateInheritableProperties(this, view);
538538

539539
const styleScope = this._styleScope;
540540
if (styleScope) {
541541
view._setStyleScope(styleScope);
542542
}
543543

544-
propagateInheritableCssProperties(this.style);
544+
propagateInheritableCssProperties(this.style, view.style);
545545

546546
if (this._context) {
547547
view._setupUI(this._context, atIndex);

tns-core-modules/ui/segmented-bar/segmented-bar.android.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ function initializeNativeClasses(): void {
9292
export class SegmentedBarItem extends SegmentedBarItemBase {
9393
nativeView: android.widget.TextView;
9494

95+
public createNativeView(): android.widget.TextView {
96+
return this.nativeView;
97+
}
98+
9599
public setupNativeView(tabIndex: number): void {
96100
// TabHost.TabSpec.setIndicator DOES NOT WORK once the title has been set.
97101
// http://stackoverflow.com/questions/2935781/modify-tab-indicator-dynamically-in-android

0 commit comments

Comments
 (0)