beforeRunningAnimation method

void beforeRunningAnimation()
inherited

Implementation

void beforeRunningAnimation() {
  for (var i = 0; i < animationName.length; i++) {
    final name = animationName[i];

    if (name == NONE) {
      return;
    }
    final fillMode = camelize(_getSingleString(animationFillMode, i));
    List<Keyframe>? keyframes = _getKeyFrames(name);
    // In some cases, inline styles are flushed before pending stylesheets
    // are applied/indexed (e.g., immediately after appending a <style> node).
    // If keyframes are not yet available but there are pending stylesheets,
    // update styles synchronously so that @keyframes rules are indexed.
    if (keyframes == null && target.ownerDocument.styleNodeManager.hasPendingStyleSheet) {
      // Apply pending stylesheets so Document.ruleSet.keyframesRules is up-to-date.
      target.ownerDocument.updateStyleIfNeeded();
      keyframes = _getKeyFrames(name);
    }
    if (keyframes == null) {
      return;
    }
    FillMode mode = FillMode.values.firstWhere((element) {
      return element.toString().split('.').last == fillMode;
    });
    Animation? animation = _runningAnimation[name];
    if (animation != null) {
      return;
    }

    if (mode == FillMode.backwards || mode == FillMode.both) {
      final styles = getAnimationInitStyle(keyframes);

      styles.forEach((property, value) {
        String? originStyle = target.inlineStyle[property];
        if (originStyle != null) {
          _cacheOriginProperties.putIfAbsent(property, () => originStyle);
        }
        target.setInlineStyle(property, value);
      });
    }
  }
  target.style.flushPendingProperties();
}