Bug 1417600 - Wait for another frame before setting animation out to ensure start of the animation. r?jaws draft
authorXidorn Quan <me@upsuper.org>
Thu, 16 Nov 2017 10:33:04 -0800
changeset 702295 9c15cc9bf8d42b9a1fbc4c63e79bfca56afd9f18
parent 702294 72480afaf2d300b0e71cc092bab8ac32ca78abe4
child 741415 a11f5998432c2bc702a0a9a0c3c37daaf12c480d
push id90429
push userxquan@mozilla.com
push dateWed, 22 Nov 2017 23:34:22 +0000
reviewersjaws
bugs1417600
milestone59.0a1
Bug 1417600 - Wait for another frame before setting animation out to ensure start of the animation. r?jaws MozReview-Commit-ID: 96nGBDgdr05
browser/components/customizableui/CustomizeMode.jsm
--- a/browser/components/customizableui/CustomizeMode.jsm
+++ b/browser/components/customizableui/CustomizeMode.jsm
@@ -603,19 +603,29 @@ CustomizeMode.prototype = {
       }
 
       function resolveAnimationPromise() {
         animationNode.removeEventListener("animationend", cleanupWidgetAnimationEnd);
         animationNode.removeEventListener("customizationending", cleanupCustomizationExit);
         resolve();
       }
 
-      animationNode.classList.add("animate-out");
-      animationNode.ownerGlobal.gNavToolbox.addEventListener("customizationending", cleanupCustomizationExit);
-      animationNode.addEventListener("animationend", cleanupWidgetAnimationEnd);
+      // Wait until the next frame before setting the class to ensure
+      // we do start the animation. We cannot use promiseLayoutFlushed
+      // here because callback is only invoked when any actual reflow
+      // happens, while that may not happen soonish enough. If we have
+      // an observer for style flush, we may be able to replace the
+      // nested rAFs with that.
+      this.window.requestAnimationFrame(() => {
+        this.window.requestAnimationFrame(() => {
+          animationNode.classList.add("animate-out");
+          animationNode.ownerGlobal.gNavToolbox.addEventListener("customizationending", cleanupCustomizationExit);
+          animationNode.addEventListener("animationend", cleanupWidgetAnimationEnd);
+        });
+      });
     });
   },
 
   async addToToolbar(aNode) {
     aNode = this._getCustomizableChildForNode(aNode);
     if (aNode.localName == "toolbarpaletteitem" && aNode.firstChild) {
       aNode = aNode.firstChild;
     }