|
1 | 1 | //
|
2 |
| -// Copyright 2019 Square Inc. |
| 2 | +// Copyright 2024 Block Inc. |
3 | 3 | //
|
4 | 4 | // Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | // you may not use this file except in compliance with the License.
|
@@ -407,10 +407,44 @@ public struct Animation<ElementType: AnyObject> {
|
407 | 407 | duration: TimeInterval? = nil,
|
408 | 408 | repeatStyle: AnimationRepeatStyle? = nil,
|
409 | 409 | completion: ((_ finished: Bool) -> Void)? = nil
|
| 410 | + ) -> AnimationInstance { |
| 411 | + return perform( |
| 412 | + on: element, |
| 413 | + delay: delay, |
| 414 | + durationProvider: FixedDurationProvider(duration: duration ?? implicitDuration), |
| 415 | + repeatStyle: repeatStyle, |
| 416 | + completion: completion |
| 417 | + ) |
| 418 | + } |
| 419 | + |
| 420 | + /// Perform the animation on the given `element`. |
| 421 | + /// |
| 422 | + /// The duration for each cycle of the animation will be determined in order of preference by: |
| 423 | + /// 1. An explicit duration, if provided via the `duration` parameter |
| 424 | + /// 2. The animation's implicit duration, as specified by the `implicitDuration` property |
| 425 | + /// |
| 426 | + /// The repeat style for the animation will be determined in order of preference by: |
| 427 | + /// 1. An explicit repeat style, if provided via the `repeatStyle` parameter |
| 428 | + /// 2. The animation's implicit repeat style, as specified by the `implicitRepeatStyle` property |
| 429 | + /// |
| 430 | + /// - parameter element: The element to be animated. |
| 431 | + /// - parameter delay: The time interval to wait before performing the animation. |
| 432 | + /// - parameter durationProvider: The duration provider to use for the animation. |
| 433 | + /// - parameter repeatStyle: The repeat style to use for the animation. |
| 434 | + /// - parameter completion: The completion block to call when the animation has concluded, with a parameter |
| 435 | + /// indicated whether the animation completed (as opposed to being cancelled). |
| 436 | + /// - returns: An animation instance that can be used to check the status of or cancel the animation. |
| 437 | + @discardableResult |
| 438 | + public func perform( |
| 439 | + on element: ElementType, |
| 440 | + delay: TimeInterval = 0, |
| 441 | + durationProvider: AnimationDurationProvider, |
| 442 | + repeatStyle: AnimationRepeatStyle? = nil, |
| 443 | + completion: ((_ finished: Bool) -> Void)? = nil |
410 | 444 | ) -> AnimationInstance {
|
411 | 445 | let driver = DisplayLinkDriver(
|
412 | 446 | delay: delay,
|
413 |
| - duration: duration ?? implicitDuration, |
| 447 | + duration: durationProvider.nextInstanceDuration(), |
414 | 448 | repeatStyle: repeatStyle ?? implicitRepeatStyle,
|
415 | 449 | completion: completion
|
416 | 450 | )
|
|
0 commit comments