mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 20:11:24 +08:00
Merge pull request #1836 from NativeScript/animate
Animation error handing improved
This commit is contained in:
@ -327,6 +327,78 @@ export var test_AnimateOpacity = function (done) {
|
||||
});
|
||||
}
|
||||
|
||||
export var test_AnimateOpacity_ShouldThrow_IfNotNumber = () => {
|
||||
var label = new labelModule.Label();
|
||||
helper.buildUIAndRunTest(label, (views: Array<viewModule.View>) => {
|
||||
TKUnit.assertThrows(() => {
|
||||
label.animate({ opacity: <any>"0.75" });
|
||||
}, "Setting opacity to a non number should throw.");
|
||||
});
|
||||
}
|
||||
|
||||
export var test_AnimateDelay_ShouldThrow_IfNotNumber = () => {
|
||||
var label = new labelModule.Label();
|
||||
helper.buildUIAndRunTest(label, (views: Array<viewModule.View>) => {
|
||||
TKUnit.assertThrows(() => {
|
||||
label.animate({ delay: <any>"1" });
|
||||
}, "Setting delay to a non number should throw.");
|
||||
});
|
||||
}
|
||||
|
||||
export var test_AnimateDuration_ShouldThrow_IfNotNumber = () => {
|
||||
var label = new labelModule.Label();
|
||||
helper.buildUIAndRunTest(label, (views: Array<viewModule.View>) => {
|
||||
TKUnit.assertThrows(() => {
|
||||
label.animate({ duration: <any>"1" });
|
||||
}, "Setting duration to a non number should throw.");
|
||||
});
|
||||
}
|
||||
|
||||
export var test_AnimateIterations_ShouldThrow_IfNotNumber = () => {
|
||||
var label = new labelModule.Label();
|
||||
helper.buildUIAndRunTest(label, (views: Array<viewModule.View>) => {
|
||||
TKUnit.assertThrows(() => {
|
||||
label.animate({ iterations: <any>"1" });
|
||||
}, "Setting iterations to a non number should throw.");
|
||||
});
|
||||
}
|
||||
|
||||
export var test_AnimateRotate_ShouldThrow_IfNotNumber = () => {
|
||||
var label = new labelModule.Label();
|
||||
helper.buildUIAndRunTest(label, (views: Array<viewModule.View>) => {
|
||||
TKUnit.assertThrows(() => {
|
||||
label.animate({ rotate: <any>"1" });
|
||||
}, "Setting rotate to a non number should throw.");
|
||||
});
|
||||
}
|
||||
|
||||
export var test_AnimateScale_ShouldThrow_IfNotPair = () => {
|
||||
var label = new labelModule.Label();
|
||||
helper.buildUIAndRunTest(label, (views: Array<viewModule.View>) => {
|
||||
TKUnit.assertThrows(() => {
|
||||
label.animate({ scale: <any>"1" });
|
||||
}, "Setting scale to a non Pair should throw.");
|
||||
});
|
||||
}
|
||||
|
||||
export var test_AnimateTranslate_ShouldThrow_IfNotPair = () => {
|
||||
var label = new labelModule.Label();
|
||||
helper.buildUIAndRunTest(label, (views: Array<viewModule.View>) => {
|
||||
TKUnit.assertThrows(() => {
|
||||
label.animate({ translate: <any>"1" });
|
||||
}, "Setting translate to a non Pair should throw.");
|
||||
});
|
||||
}
|
||||
|
||||
export var test_AnimateBackgroundColor_ShouldThrow_IfNotValidColorStringOrColor = () => {
|
||||
var label = new labelModule.Label();
|
||||
helper.buildUIAndRunTest(label, (views: Array<viewModule.View>) => {
|
||||
TKUnit.assertThrows(() => {
|
||||
label.animate({ backgroundColor: <any>"test" });
|
||||
}, "Setting backgroundColor to a not valid color string or Color should throw.");
|
||||
});
|
||||
}
|
||||
|
||||
export var test_AnimateBackgroundColor = function(done) {
|
||||
var mainPage: pageModule.Page;
|
||||
var label: labelModule.Label;
|
||||
@ -356,6 +428,37 @@ export var test_AnimateBackgroundColor = function (done) {
|
||||
});
|
||||
}
|
||||
|
||||
export var test_AnimateBackgroundColor_FromString = function(done) {
|
||||
var mainPage: pageModule.Page;
|
||||
var label: labelModule.Label;
|
||||
var pageFactory = function(): pageModule.Page {
|
||||
label = new labelModule.Label();
|
||||
label.text = "label";
|
||||
var stackLayout = new stackLayoutModule.StackLayout();
|
||||
stackLayout.addChild(label);
|
||||
mainPage = new pageModule.Page();
|
||||
mainPage.content = stackLayout;
|
||||
return mainPage;
|
||||
};
|
||||
|
||||
helper.navigate(pageFactory);
|
||||
TKUnit.waitUntilReady(() => { return label.isLoaded });
|
||||
|
||||
var expected = "Red";
|
||||
var clr = new colorModule.Color(expected);
|
||||
|
||||
label.animate({ backgroundColor: <any>expected })
|
||||
.then(() => {
|
||||
TKUnit.assert(label.backgroundColor.equals(clr));
|
||||
helper.goBack();
|
||||
done();
|
||||
})
|
||||
.catch((e) => {
|
||||
helper.goBack();
|
||||
done(e);
|
||||
});
|
||||
}
|
||||
|
||||
export var test_AnimateTranslate = function(done) {
|
||||
var mainPage: pageModule.Page;
|
||||
var label: labelModule.Label;
|
||||
|
@ -1,5 +1,7 @@
|
||||
import definition = require("ui/animation");
|
||||
import viewModule = require("ui/core/view");
|
||||
import colorModule = require("color");
|
||||
import types = require("utils/types");
|
||||
import * as traceModule from "trace";
|
||||
|
||||
var trace: typeof traceModule;
|
||||
@ -144,6 +146,27 @@ export class Animation implements definition.Animation {
|
||||
throw new Error("No animation target specified.");
|
||||
}
|
||||
|
||||
for (let item in animationDefinition) {
|
||||
if (!types.isDefined(animationDefinition[item])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((item === Properties.opacity ||
|
||||
item === Properties.rotate ||
|
||||
item === "duration" ||
|
||||
item === "delay" ||
|
||||
item === "iterations") && !types.isNumber(animationDefinition[item])) {
|
||||
throw new Error(`Property ${item} must be valid number. Value: ${animationDefinition[item]}`);
|
||||
} else if ((item === Properties.scale ||
|
||||
item === Properties.translate) &&
|
||||
(!types.isNumber((<definition.Pair>animationDefinition[item]).x) ||
|
||||
!types.isNumber((<definition.Pair>animationDefinition[item]).y))) {
|
||||
throw new Error(`Property ${item} must be valid Pair. Value: ${animationDefinition[item]}`);
|
||||
} else if (item === Properties.backgroundColor && !colorModule.Color.isValid(animationDefinition.backgroundColor)) {
|
||||
throw new Error(`Property ${item} must be valid color. Value: ${animationDefinition[item]}`);
|
||||
}
|
||||
}
|
||||
|
||||
var propertyAnimations = new Array<PropertyAnimation>();
|
||||
|
||||
// opacity
|
||||
@ -164,7 +187,8 @@ export class Animation implements definition.Animation {
|
||||
propertyAnimations.push({
|
||||
target: animationDefinition.target,
|
||||
property: Properties.backgroundColor,
|
||||
value: animationDefinition.backgroundColor,
|
||||
value: types.isString(animationDefinition.backgroundColor) ?
|
||||
new colorModule.Color(<any>animationDefinition.backgroundColor) : animationDefinition.backgroundColor,
|
||||
duration: animationDefinition.duration,
|
||||
delay: animationDefinition.delay,
|
||||
iterations: animationDefinition.iterations,
|
||||
|
Reference in New Issue
Block a user