CssAnimationProperties, when unset, were not setting the default native value. (#4595)

This commit is contained in:
Panayot Cankov
2017-07-26 19:16:26 +03:00
committed by SvetoslavTsenov
parent d978424f35
commit 2f6ca2524b
6 changed files with 66 additions and 21 deletions

View File

@ -0,0 +1,8 @@
<Page xmlns="http://schemas.nativescript.org/tns.xsd">
<StackLayout id="root">
<SearchBar />
<Progress value="50" maxValue="100" margin="22" />
<Button text="set" tap="set" margin="2" />
<Button text="clear" tap="clear" margin="2" />
</StackLayout>
</Page>

View File

@ -0,0 +1,3 @@
.styled > StackLayout > * {
background-color: red;
}

View File

@ -0,0 +1,7 @@
export function set(args) {
args.object.page.className = "styled";
}
export function clear(args) {
args.object.page.className = "";
}

View File

@ -0,0 +1,8 @@
<Page xmlns="http://schemas.nativescript.org/tns.xsd">
<StackLayout id="root">
<SearchBar />
<Progress value="50" maxValue="100" margin="22" />
<Button text="set" tap="set" margin="2" />
<Button text="clear" tap="clear" margin="2" />
</StackLayout>
</Page>

View File

@ -24,6 +24,7 @@ export function loadExamples() {
examples.set("1657-ios", "issues/issue-1657-ios");
examples.set("tabview-with-scrollview_4022","issues/tabview-with-scrollview_4022");
examples.set("3354-ios", "issues/issue-3354");
examples.set("4450", "issues/issue-4450");
return examples;
}

View File

@ -658,6 +658,7 @@ export class CssAnimationProperty<T extends Style, U> {
public readonly keyframe: string;
public readonly defaultValueKey: symbol;
public readonly key: symbol;
private readonly source: symbol;
public readonly defaultValue: U;
@ -699,6 +700,7 @@ export class CssAnimationProperty<T extends Style, U> {
const computedValue = Symbol("computed-value:" + propertyName);
this.key = computedValue;
const computedSource = Symbol("computed-source:" + propertyName);
this.source = computedSource;
this.getDefault = Symbol(propertyName + ":getDefault");
const getDefault = this.getDefault;
@ -712,7 +714,11 @@ export class CssAnimationProperty<T extends Style, U> {
enumerable, configurable,
get: getsComputed ? function (this: T) { return this[computedValue]; } : function (this: T) { return this[symbol]; },
set(this: T, boxedValue: U) {
let oldValue = this[computedValue];
const oldValue = this[computedValue];
const oldSource = this[computedSource];
const wasSet = oldSource !== ValueSource.Default;
if (boxedValue === unsetValue) {
this[symbol] = unsetValue;
if (this[computedSource] === propertySource) {
@ -724,8 +730,8 @@ export class CssAnimationProperty<T extends Style, U> {
this[computedSource] = ValueSource.Css;
this[computedValue] = this[cssValue];
} else {
this[computedSource] = ValueSource.Default;
this[computedValue] = defaultValueKey in this ? this[defaultValueKey] : defaultValue;
delete this[computedSource];
delete this[computedValue];
}
}
} else {
@ -738,33 +744,45 @@ export class CssAnimationProperty<T extends Style, U> {
this[computedValue] = boxedValue;
}
}
let value = this[computedValue];
if (oldValue !== value && (!equalityComparer || !equalityComparer(oldValue, value))) {
if (valueChanged) {
const value = this[computedValue];
const source = this[computedSource];
const isSet = source !== ValueSource.Default;
const computedValueChanged = oldValue !== value && (!equalityComparer || !equalityComparer(oldValue, value));
if (computedValueChanged && valueChanged) {
valueChanged(this, oldValue, value);
}
const view = this.view;
if (view[setNative]) {
if (view[setNative] && (computedValueChanged || isSet !== wasSet)) {
if (view._suspendNativeUpdatesCount) {
if (view._suspendedUpdates) {
view._suspendedUpdates[propertyName] = property;
}
} else {
if (!(defaultValueKey in this)) {
if (isSet) {
if (!wasSet && !(defaultValueKey in this)) {
this[defaultValueKey] = view[getDefault] ? view[getDefault]() : defaultValue;
}
view[setNative](value);
} else if (wasSet) {
if (defaultValueKey in this) {
view[setNative](this[defaultValueKey]);
} else {
view[setNative](defaultValue);
}
}
if (this.hasListeners(eventName)) {
}
}
if (computedValueChanged && this.hasListeners(eventName)) {
this.notify<PropertyChangeData>({ object: this, eventName, propertyName, value, oldValue });
}
}
}
}
}
const defaultPropertyDescriptor = descriptor(defaultValueKey, ValueSource.Default, false, false, false);
const cssPropertyDescriptor = descriptor(cssValue, ValueSource.Css, false, false, false);
@ -807,7 +825,7 @@ export class CssAnimationProperty<T extends Style, U> {
}
public isSet(instance: T): boolean {
return instance[this.key] !== unsetValue;
return instance[this.source] !== ValueSource.Default;
}
}
CssAnimationProperty.prototype.isStyleProperty = true;