void CKComponentBoundsAnimationApply()

in ComponentKit/Core/CKComponentBoundsAnimation.mm [13:51]


void CKComponentBoundsAnimationApply(const CKComponentBoundsAnimation &animation,
                                     void (^animations)(void),
                                     void (^completion)(BOOL finished))
{
  // Avoid capturing the unmanaged reference to animation
  auto const ac = animation.completion;
  auto const _completion = ^(BOOL finished){
    if (auto c = ac) {
      c();
    }
    if (auto c = completion) {
      c(finished);
    }
  };

  if (animation.duration == 0) {
    [UIView performWithoutAnimation:animations];
    _completion(YES);
  } else {
    [CATransaction begin];
    [CATransaction setAnimationTimingFunction:animation.timingFunction];
    if (animation.mode == CKComponentBoundsAnimationModeSpring) {
      [UIView animateWithDuration:animation.duration
                            delay:animation.delay
           usingSpringWithDamping:animation.springDampingRatio
            initialSpringVelocity:animation.springInitialVelocity
                          options:animation.options
                       animations:animations
                       completion:_completion];
    } else {
      [UIView animateWithDuration:animation.duration
                            delay:animation.delay
                          options:animation.options
                       animations:animations
                       completion:_completion];
    }
    [CATransaction commit];
  }
}