Skip to content

Instantly share code, notes, and snippets.

@ColinCampbell
Created March 15, 2011 19:28
Show Gist options
  • Select an option

  • Save ColinCampbell/871278 to your computer and use it in GitHub Desktop.

Select an option

Save ColinCampbell/871278 to your computer and use it in GitHub Desktop.
diff --git a/frameworks/core_foundation/tests/views/view/animation.js b/frameworks/core_foundation/tests/views/view/animation.js
index fe6f663..b738b77 100644
--- a/frameworks/core_foundation/tests/views/view/animation.js
+++ b/frameworks/core_foundation/tests/views/view/animation.js
@@ -289,6 +289,32 @@ if (SC.platform.supportsCSSTransitions) {
SC.RunLoop.end();
});
+ test("should not add animation for properties that have the same value as existing layout", function() {
+ var callbacks = 0;
+
+ SC.RunLoop.begin();
+ // we set width to the same value, but we change height
+ view.invokeLater('animate', 1, {width: 100, height: 50}, 0.5, function() { callbacks++; });
+ SC.RunLoop.end();
+
+ ok(callbacks === 0, "precond - callback should not have been run yet");
+
+ stop(2000);
+
+ // we need to test changing the width at a later time
+ setTimeout(function() {
+ start();
+
+ equals(callbacks, 1, "callback should have been run once, for height change");
+
+ SC.RunLoop.begin();
+ view.animate('width', 50, 0.5);
+ SC.RunLoop.end();
+
+ equals(callbacks, 1, "callback should still have only been called once, even though width has now been animated");
+ }, 1000);
+ });
+
test("should warn if multiple callbacks for transitions");
}
diff --git a/frameworks/core_foundation/views/view/animation.js b/frameworks/core_foundation/views/view/animation.js
index 39f9c56..eae8481 100644
--- a/frameworks/core_foundation/views/view/animation.js
+++ b/frameworks/core_foundation/views/view/animation.js
@@ -82,26 +82,20 @@ SC.View.reopen(
// Very similar to #adjust
for(key in hash) {
- if (!hash.hasOwnProperty(key)) { continue; }
+ if (!hash.hasOwnProperty(key) || !SC.ANIMATABLE_PROPERTIES[key]) { continue; }
value = hash[key];
cur = layout[key];
+ curAnim = layout.animate[key];
- if (cur !== value) { didChange = YES; }
-
- if (SC.ANIMATABLE_PROPERTIES[key]) {
- curAnim = layout.animate[key];
-
- // loose comparison used instead of (value === null || value === undefined)
- if (value == null) { throw "Can only animate to an actual value!"; }
-
- // FIXME: We should check more than duration
- if (curAnim && curAnim.duration !== options.duration) { didChange = YES; }
+ // loose comparison used instead of (value === null || value === undefined)
+ if (value == null) { throw "Can only animate to an actual value!"; }
+ // FIXME: We should check more than duration
+ if (cur !== value || (curAnim && curAnim.duration !== options.duration)) {
+ didChange = YES;
layout.animate[key] = options;
+ layout[key] = value;
}
-
- layout[key] = value;
-
}
// now set adjusted layout
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment