mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 03:31:45 +08:00
propagate inheritable values only on child added. (#3926)
segmented bar createNativeView returns the nativeView
This commit is contained in:
@ -111,8 +111,8 @@ export class CssAnimationProperty<T extends Style, U> {
|
|||||||
export function initNativeView(view: ViewBase): void;
|
export function initNativeView(view: ViewBase): void;
|
||||||
export function resetNativeView(view: ViewBase): void;
|
export function resetNativeView(view: ViewBase): void;
|
||||||
export function resetCSSProperties(style: Style): void;
|
export function resetCSSProperties(style: Style): void;
|
||||||
export function propagateInheritableProperties(view: ViewBase): void;
|
export function propagateInheritableProperties(view: ViewBase, childView: ViewBase): void;
|
||||||
export function propagateInheritableCssProperties(style: Style): void;
|
export function propagateInheritableCssProperties(parentStyle: Style, childStyle: Style): void;
|
||||||
export function clearInheritedProperties(view: ViewBase): void;
|
export function clearInheritedProperties(view: ViewBase): void;
|
||||||
|
|
||||||
export function makeValidator<T>(...values: T[]): (value: any) => value is T;
|
export function makeValidator<T>(...values: T[]): (value: any) => value is T;
|
||||||
|
@ -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);
|
const inheritablePropertyValues = inheritablePropertyValuesOn(view);
|
||||||
if (inheritablePropertyValues.length === 0) {
|
for (let pair of inheritablePropertyValues) {
|
||||||
return;
|
const prop = pair.property;
|
||||||
}
|
const sourceKey = prop.sourceKey;
|
||||||
|
const currentValueSource: number = child[sourceKey] || ValueSource.Default;
|
||||||
view.eachChild((child) => {
|
if (currentValueSource <= ValueSource.Inherited) {
|
||||||
for (let pair of inheritablePropertyValues) {
|
prop.setInheritedValue.call(child, pair.value);
|
||||||
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 {
|
export function propagateInheritableCssProperties(parentStyle: Style, childStyle: Style): void {
|
||||||
const view = style.view;
|
const inheritableCssPropertyValues = inheritableCssPropertyValuesOn(parentStyle);
|
||||||
const inheritableCssPropertyValues = inheritableCssPropertyValuesOn(style);
|
for (let pair of inheritableCssPropertyValues) {
|
||||||
if (inheritableCssPropertyValues.length === 0) {
|
const prop = pair.property;
|
||||||
return;
|
const sourceKey = prop.sourceKey;
|
||||||
}
|
const currentValueSource: number = childStyle[sourceKey] || ValueSource.Default;
|
||||||
|
if (currentValueSource <= ValueSource.Inherited) {
|
||||||
view.eachChild((child) => {
|
prop.setInheritedValue.call(childStyle, pair.value, ValueSource.Inherited);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return true;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function makeValidator<T>(...values: T[]): (value: any) => value is T {
|
export function makeValidator<T>(...values: T[]): (value: any) => value is T {
|
||||||
|
@ -534,14 +534,14 @@ export abstract class ViewBase extends Observable implements ViewBaseDefinition
|
|||||||
}
|
}
|
||||||
|
|
||||||
public _addViewCore(view: ViewBase, atIndex?: number) {
|
public _addViewCore(view: ViewBase, atIndex?: number) {
|
||||||
propagateInheritableProperties(this);
|
propagateInheritableProperties(this, view);
|
||||||
|
|
||||||
const styleScope = this._styleScope;
|
const styleScope = this._styleScope;
|
||||||
if (styleScope) {
|
if (styleScope) {
|
||||||
view._setStyleScope(styleScope);
|
view._setStyleScope(styleScope);
|
||||||
}
|
}
|
||||||
|
|
||||||
propagateInheritableCssProperties(this.style);
|
propagateInheritableCssProperties(this.style, view.style);
|
||||||
|
|
||||||
if (this._context) {
|
if (this._context) {
|
||||||
view._setupUI(this._context, atIndex);
|
view._setupUI(this._context, atIndex);
|
||||||
|
@ -92,6 +92,10 @@ function initializeNativeClasses(): void {
|
|||||||
export class SegmentedBarItem extends SegmentedBarItemBase {
|
export class SegmentedBarItem extends SegmentedBarItemBase {
|
||||||
nativeView: android.widget.TextView;
|
nativeView: android.widget.TextView;
|
||||||
|
|
||||||
|
public createNativeView(): android.widget.TextView {
|
||||||
|
return this.nativeView;
|
||||||
|
}
|
||||||
|
|
||||||
public setupNativeView(tabIndex: number): void {
|
public setupNativeView(tabIndex: number): void {
|
||||||
// TabHost.TabSpec.setIndicator DOES NOT WORK once the title has been set.
|
// TabHost.TabSpec.setIndicator DOES NOT WORK once the title has been set.
|
||||||
// http://stackoverflow.com/questions/2935781/modify-tab-indicator-dynamically-in-android
|
// http://stackoverflow.com/questions/2935781/modify-tab-indicator-dynamically-in-android
|
||||||
|
Reference in New Issue
Block a user