mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-17 04:41:36 +08:00
refactor: reset css property value when ''" (empty string) is set (#5085)
This commit is contained in:
@ -465,17 +465,17 @@ export class CssProperty<T extends Style, U> implements definitions.CssProperty<
|
|||||||
|
|
||||||
const property = this;
|
const property = this;
|
||||||
|
|
||||||
function setLocalValue(this: T, value: U): void {
|
function setLocalValue(this: T, newValue: U | string): void {
|
||||||
const reset = value === unsetValue;
|
const reset = newValue === unsetValue || newValue === "";
|
||||||
|
let value: U;
|
||||||
if (reset) {
|
if (reset) {
|
||||||
value = defaultValue;
|
value = defaultValue;
|
||||||
delete this[sourceKey];
|
delete this[sourceKey];
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
this[sourceKey] = ValueSource.Local;
|
this[sourceKey] = ValueSource.Local;
|
||||||
if (valueConverter && typeof value === "string") {
|
value = (valueConverter && typeof newValue === "string") ?
|
||||||
value = valueConverter(value);
|
valueConverter(newValue) :
|
||||||
}
|
<U>newValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const oldValue: U = key in this ? this[key] : defaultValue;
|
const oldValue: U = key in this ? this[key] : defaultValue;
|
||||||
@ -533,8 +533,7 @@ export class CssProperty<T extends Style, U> implements definitions.CssProperty<
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function setCssValue(this: T, value: U): void {
|
function setCssValue(this: T, newValue: U | string): void {
|
||||||
const reset = value === unsetValue;
|
|
||||||
const currentValueSource: number = this[sourceKey] || ValueSource.Default;
|
const currentValueSource: number = this[sourceKey] || ValueSource.Default;
|
||||||
|
|
||||||
// We have localValueSource - NOOP.
|
// We have localValueSource - NOOP.
|
||||||
@ -542,13 +541,15 @@ export class CssProperty<T extends Style, U> implements definitions.CssProperty<
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const reset = newValue === unsetValue || newValue === "";
|
||||||
|
let value: U;
|
||||||
if (reset) {
|
if (reset) {
|
||||||
value = defaultValue;
|
value = defaultValue;
|
||||||
delete this[sourceKey];
|
delete this[sourceKey];
|
||||||
} else {
|
} else {
|
||||||
if (valueConverter && typeof value === "string") {
|
value = valueConverter && typeof newValue === "string" ?
|
||||||
value = valueConverter(value);
|
valueConverter(newValue) :
|
||||||
}
|
<U>newValue;
|
||||||
this[sourceKey] = ValueSource.Css;
|
this[sourceKey] = ValueSource.Css;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -716,13 +717,14 @@ export class CssAnimationProperty<T extends Style, U> implements definitions.Css
|
|||||||
return {
|
return {
|
||||||
enumerable, configurable,
|
enumerable, configurable,
|
||||||
get: getsComputed ? function (this: T) { return this[computedValue]; } : function (this: T) { return this[symbol]; },
|
get: getsComputed ? function (this: T) { return this[computedValue]; } : function (this: T) { return this[symbol]; },
|
||||||
set(this: T, boxedValue: U) {
|
set(this: T, boxedValue: U | string) {
|
||||||
|
|
||||||
const oldValue = this[computedValue];
|
const oldValue = this[computedValue];
|
||||||
const oldSource = this[computedSource];
|
const oldSource = this[computedSource];
|
||||||
const wasSet = oldSource !== ValueSource.Default;
|
const wasSet = oldSource !== ValueSource.Default;
|
||||||
|
const reset = boxedValue === unsetValue || boxedValue === "";
|
||||||
if (boxedValue === unsetValue) {
|
|
||||||
|
if (reset) {
|
||||||
this[symbol] = unsetValue;
|
this[symbol] = unsetValue;
|
||||||
if (this[computedSource] === propertySource) {
|
if (this[computedSource] === propertySource) {
|
||||||
// Fallback to lower value source.
|
// Fallback to lower value source.
|
||||||
@ -856,7 +858,7 @@ export class InheritedCssProperty<T extends Style, U> extends CssProperty<T, U>
|
|||||||
const property = this;
|
const property = this;
|
||||||
|
|
||||||
const setFunc = (valueSource: ValueSource) => function (this: T, boxedValue: any): void {
|
const setFunc = (valueSource: ValueSource) => function (this: T, boxedValue: any): void {
|
||||||
const reset = boxedValue === unsetValue;
|
const reset = boxedValue === unsetValue || boxedValue === "";
|
||||||
const currentValueSource: number = this[sourceKey] || ValueSource.Default;
|
const currentValueSource: number = this[sourceKey] || ValueSource.Default;
|
||||||
if (reset) {
|
if (reset) {
|
||||||
// If we want to reset cssValue and we have localValue - return;
|
// If we want to reset cssValue and we have localValue - return;
|
||||||
@ -1309,4 +1311,4 @@ export function getComputedCssValues(view: ViewBase): [string, any][] {
|
|||||||
result.push(["bottom", "auto"]);
|
result.push(["bottom", "auto"]);
|
||||||
result.push(["right", "auto"]);
|
result.push(["right", "auto"]);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user