API Reference 0.3.24dart_web_toolkit_layoutLayoutAnimation

LayoutAnimation class

class LayoutAnimation extends Animation {

 Layout _layout;
 LayoutAnimationCallback _callback;

 LayoutAnimation(this._layout, this._callback);

 void onCancel() {
   onComplete();
 }

 void onComplete() {
   _layout.animation = null;
   _layout.layout();
   if (callback != null) {
     _callback.onAnimationComplete();
   }
 }

 void onUpdate(double progress) {
   for (Layer l in _layout.layers) {
     if (l.setTargetLeft) {
       l.left = l.sourceLeft + (l.targetLeft - l.sourceLeft) * progress;
     }
     if (l.setTargetRight) {
       l.right = l.sourceRight + (l.targetRight - l.sourceRight)
           * progress;
     }
     if (l.setTargetTop) {
       l.top = l.sourceTop + (l.targetTop - l.sourceTop) * progress;
     }
     if (l.setTargetBottom) {
       l.bottom = l.sourceBottom + (l.targetBottom - l.sourceBottom)
           * progress;
     }
     if (l.setTargetWidth) {
       l.width = l.sourceWidth + (l.targetWidth - l.sourceWidth)
           * progress;
     }
     if (l.setTargetHeight) {
       l.height = l.sourceHeight + (l.targetHeight - l.sourceHeight)
           * progress;
     }

     _layout.impl.layout(l);
     if (_callback != null) {
       _callback.onLayout(l, progress);
     }
   }
   _layout.impl.finalizeLayout(_layout.parentElem);
 }

}

Extends

Animation > LayoutAnimation

Constructors

new LayoutAnimation(Layout _layout, LayoutAnimationCallback _callback) #

Construct a new {@link AnimationScheduler} using the specified scheduler to sheduler request frames.

@param scheduler an {@link AnimationScheduler} instance

docs inherited from Animation
LayoutAnimation(this._layout, this._callback);

Properties

AnimationCallback callback #

inherited from Animation
AnimationCallback callback

int duration #

inherited from Animation

The duration of the {@link Animation} in milliseconds.

int duration = -1

Element element #

inherited from Animation

The element being animated.

dart_html.Element element

bool isStarted #

inherited from Animation

Has the {@link Animation} actually started.

bool isStarted = false

AnimationHandle requestHandle #

inherited from Animation

The ID of the pending animation request.

AnimationHandle requestHandle

int runId #

inherited from Animation

The unique ID of the current run. Used to handle cases where an animation is restarted within an execution block.

int runId = -1

bool running #

inherited from Animation

Is the animation running, even if it hasn't started yet.

bool running = false

AnimationScheduler scheduler #

inherited from Animation
AnimationScheduler scheduler

int startTime #

inherited from Animation

The start time of the {@link Animation}.

int startTime = -1

bool wasStarted #

inherited from Animation

Did the animation start before {@link #cancel()} was called.

bool wasStarted = false

Methods

void cancel() #

inherited from Animation

Immediately cancel this animation. If the animation is running or is scheduled to run, {@link #onCancel()} will be called.

void cancel() {
 // Ignore if the animation is not currently running.
 if (!running) {
   return;
 }

 // Reset the state.
 wasStarted = isStarted; // Used by onCancel.
 element = null;
 running = false;
 isStarted = false;

 // Cancel the animation request.
 if (requestHandle != null) {
   requestHandle.cancel();
   requestHandle = null;
 }

 onCancel();
}

double interpolate(double progress) #

inherited from Animation

Interpolate the linear progress into a more natural easing function.

Depending on the {@link Animation}, the return value of this method can be less than 0.0 or greater than 1.0.

@param progress the linear progress, between 0.0 and 1.0 @return the interpolated progress

double interpolate(double progress) {
 return (1 + dart_math.cos(dart_math.PI + progress * dart_math.PI)) / 2;
}

bool isRunning(int curRunId) #

inherited from Animation

Check if the specified run ID is still being run.

@param curRunId the current run ID to check @return true if running, false if canceled or restarted

bool isRunning(int curRunId) {
 return running && (runId == curRunId);
}

void onCancel() #

Called immediately after the animation is canceled. The default implementation of this method calls {@link #onComplete()} only if the animation has actually started running.

docs inherited from Animation
void onCancel() {
 onComplete();
}

void onComplete() #

Called immediately after the animation completes.

docs inherited from Animation
void onComplete() {
 _layout.animation = null;
 _layout.layout();
 if (callback != null) {
   _callback.onAnimationComplete();
 }
}

void onStart() #

inherited from Animation

Called immediately before the animation starts.

void onStart() {
 onUpdate(interpolate(0.0));
}

void onUpdate(double progress) #

Called when the animation should be updated.

The value of progress is between 0.0 and 1.0 (inclusive) (unless you override the {@link #interpolate(double)} method to provide a wider range of values). You can override {@link #onStart()} and {@link #onComplete()} to perform setup and tear down procedures.

@param progress a double, normally between 0.0 and 1.0 (inclusive)

docs inherited from Animation
void onUpdate(double progress) {
 for (Layer l in _layout.layers) {
   if (l.setTargetLeft) {
     l.left = l.sourceLeft + (l.targetLeft - l.sourceLeft) * progress;
   }
   if (l.setTargetRight) {
     l.right = l.sourceRight + (l.targetRight - l.sourceRight)
         * progress;
   }
   if (l.setTargetTop) {
     l.top = l.sourceTop + (l.targetTop - l.sourceTop) * progress;
   }
   if (l.setTargetBottom) {
     l.bottom = l.sourceBottom + (l.targetBottom - l.sourceBottom)
         * progress;
   }
   if (l.setTargetWidth) {
     l.width = l.sourceWidth + (l.targetWidth - l.sourceWidth)
         * progress;
   }
   if (l.setTargetHeight) {
     l.height = l.sourceHeight + (l.targetHeight - l.sourceHeight)
         * progress;
   }

   _layout.impl.layout(l);
   if (_callback != null) {
     _callback.onLayout(l, progress);
   }
 }
 _layout.impl.finalizeLayout(_layout.parentElem);
}

void run(int duration, {int startTime: null, Element element: null}) #

inherited from Animation

Run this animation at the given startTime. If the startTime has already passed, the animation will run synchronously as if it started at the specified start time. If the animation is already running, it will be canceled first. <p> If the element is not <code>null</code>, the {@link #onUpdate(double)} method might be called only if the element may be visible (generally left at the appreciation of the browser). Otherwise, it will be called unconditionally.

@param duration the duration of the animation in milliseconds @param startTime the synchronized start time in milliseconds @param element the element that visually bounds the entire animation

void run(int duration, {int startTime:null, dart_html.Element element:null}) {
 // Cancel the animation if it is running
 cancel();

 if (startTime == null) {
   startTime = (new DateTime.now()).millisecondsSinceEpoch;
 }

 // Save the duration and startTime
 running = true;
 isStarted = false;
 this.duration = duration;
 this.startTime = startTime;
 this.element = element;
 ++runId;

 // Execute the first callback.
 callback.execute((new DateTime.now()).millisecondsSinceEpoch);
}

bool update(int curTime) #

inherited from Animation

Update the {@link Animation}.

@param curTime the current time @return true if the animation should run again, false if it is complete

bool update(int curTime) {
 /*
  * Save the run id. If the runId is incremented during this execution block,
  * we know that this run has been canceled.
  */
 int curRunId = runId;

 bool finished = curTime >= startTime + duration;
 if (isStarted && !finished) {
   // Animation is in progress.
   double progress = (curTime - startTime) / duration;
   onUpdate(interpolate(progress));
   return isRunning(curRunId); // Check if this run was canceled.
 }
 if (!isStarted && curTime >= startTime) {
   /*
    * Start the animation. We do not call onUpdate() because onStart() calls
    * onUpdate() by default.
    */
   isStarted = true;
   onStart();
   if (!isRunning(curRunId)) {
     // This run was canceled.
     return false;
   }
   // Intentional fall through to possibly end the animation.
 }
 if (finished) {
   // Animation is complete.
   running = false;
   isStarted = false;
   onComplete();
   return false;
 }
 return true;
}