-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into refacto/switch/space
- Loading branch information
Showing
14 changed files
with
341 additions
and
111 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
core/Sources/Common/UIKit/Extension/Animation/UIView+ExecuteExtension.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// | ||
// UIView+ExecuteExtension.swift | ||
// SparkCore | ||
// | ||
// Created by robin.lemaire on 26/10/2023. | ||
// Copyright © 2023 Adevinta. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
enum UIExecuteAnimationType { | ||
case unanimated | ||
case animated(duration: TimeInterval) | ||
} | ||
|
||
extension UIView { | ||
|
||
/// Execute a code with or without animation. | ||
static func execute( | ||
animationType: UIExecuteAnimationType, | ||
instructions: @escaping () -> Void, | ||
completion: ((Bool) -> Void)? = nil | ||
) { | ||
switch animationType { | ||
case .unanimated: | ||
instructions() | ||
completion?(true) | ||
|
||
case .animated(let duration): | ||
UIView.animate( | ||
withDuration: duration, | ||
animations: instructions, | ||
completion: completion) | ||
} | ||
} | ||
|
||
/// Execute a code with or without transition animation. | ||
static func execute( | ||
with view: UIView, | ||
animationType: UIExecuteAnimationType, | ||
options: UIView.AnimationOptions = [], | ||
instructions: @escaping () -> Void, | ||
completion: ((Bool) -> Void)? = nil | ||
) { | ||
switch animationType { | ||
case .unanimated: | ||
instructions() | ||
completion?(true) | ||
|
||
case .animated(let duration): | ||
UIView.transition( | ||
with: view, | ||
duration: duration, | ||
options: options, | ||
animations: instructions, | ||
completion: completion) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.