Skip to content

Commit 8f884e5

Browse files
committed
Added fade update method.
1 parent b1ddf12 commit 8f884e5

File tree

6 files changed

+68
-31
lines changed

6 files changed

+68
-31
lines changed

Sources/SparrowKit/Foundation/Extensions/Do.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323
import Foundation
2424
#endif
2525
#if !os(Linux)
26-
import CoreGraphics
26+
import CoreGraphics
2727
#endif
2828
#if os(iOS) || os(tvOS)
29-
import UIKit.UIGeometry
29+
import UIKit.UIGeometry
3030
#endif
3131

3232
public protocol Do {}
@@ -61,18 +61,18 @@ extension Do where Self: Any {
6161
extension NSObject: Do {}
6262

6363
#if !os(Linux)
64-
extension CGPoint: Do {}
65-
extension CGRect: Do {}
66-
extension CGSize: Do {}
67-
extension CGVector: Do {}
64+
extension CGPoint: Do {}
65+
extension CGRect: Do {}
66+
extension CGSize: Do {}
67+
extension CGVector: Do {}
6868
#endif
6969

7070
extension Array: Do {}
7171
extension Dictionary: Do {}
7272
extension Set: Do {}
7373

7474
#if os(iOS) || os(tvOS)
75-
extension UIEdgeInsets: Do {}
76-
extension UIOffset: Do {}
77-
extension UIRectEdge: Do {}
75+
extension UIEdgeInsets: Do {}
76+
extension UIOffset: Do {}
77+
extension UIRectEdge: Do {}
7878
#endif

Sources/SparrowKit/UIKit/Extensions/UILabelExtension.swift

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -84,25 +84,6 @@ extension UILabel {
8484
frame.setWidth(width)
8585
}
8686
}
87-
88-
// MARK: - Animations
89-
90-
/**
91-
SparrowKit: Set new text via fade animation.
92-
93-
- parameter newText: New text for label.
94-
- parameter duration: Time of full animation.
95-
- parameter completion: Call at end of animation.
96-
*/
97-
open func setTextWithFade(newText: String, duration: TimeInterval = 0.6, completion: (()->Void)? = nil) {
98-
fadeOut(duration: duration / 2) { [weak self] _ in
99-
guard let self = self else { return }
100-
self.text = newText
101-
self.fadeIn(duration: duration / 2) { _ in
102-
completion?()
103-
}
104-
}
105-
}
10687
}
10788

10889
#endif
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// The MIT License (MIT)
2+
// Copyright © 2020 Ivan Vorobei (hello@ivanvorobei.by)
3+
//
4+
// Permission is hereby granted, free of charge, to any person obtaining a copy
5+
// of this software and associated documentation files (the "Software"), to deal
6+
// in the Software without restriction, including without limitation the rights
7+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
// copies of the Software, and to permit persons to whom the Software is
9+
// furnished to do so, subject to the following conditions:
10+
//
11+
// The above copyright notice and this permission notice shall be included in all
12+
// copies or substantial portions of the Software.
13+
//
14+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+
// SOFTWARE.
21+
22+
#if canImport(UIKit) && (os(iOS) || os(tvOS))
23+
import UIKit
24+
25+
public protocol UIFadeOut {}
26+
27+
extension UIFadeOut where Self: UIView {
28+
29+
/**
30+
SparrowKit: Hide view with fade out animation.
31+
32+
- parameter duration: Duration of all animation.
33+
- parameter delay: Pause when view dissapear in middle of animation.
34+
- parameter work: Apply view changes here.
35+
- parameter completion: Call after end of animation.
36+
*/
37+
public func fadeUpdate(duration: TimeInterval = 0.6, delay: TimeInterval = 0.1, work: @escaping (Self)->Void, completion: @escaping ()->Void) {
38+
let partDuration = (duration - delay) / 2
39+
let storedAlpha = self.alpha
40+
UIView.animate(withDuration: partDuration, delay: .zero, options: [.beginFromCurrentState, .allowUserInteraction], animations: { [weak self] in
41+
self?.alpha = .zero
42+
}, completion: { [weak self] finished in
43+
if let self = self {
44+
work(self)
45+
}
46+
UIView.animate(withDuration: partDuration, delay: delay, options: [.beginFromCurrentState, .allowUserInteraction], animations: { [weak self] in
47+
self?.alpha = storedAlpha
48+
}, completion: { finished in
49+
completion()
50+
})
51+
})
52+
}
53+
}
54+
55+
extension UIView: UIFadeOut {}
56+
57+
#endif
58+

Sources/SparrowKit/UIKit/Extensions/UIViewExtension.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,8 +382,6 @@ extension UIView {
382382
motionEffects.removeAll()
383383
}
384384

385-
// MARK: - Animations
386-
387385
/**
388386
SparrowKit: Appear view with fade in animation.
389387

SparrowKit.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Pod::Spec.new do |s|
22

33
s.name = 'SparrowKit'
4-
s.version = '3.2.1'
4+
s.version = '3.2.2'
55
s.summary = 'Collection of native Swift extensions to boost your development. Support tvOS and watchOS.'
66
s.homepage = 'https://github.com/ivanvorobei/SparrowKit'
77
s.source = { :git => 'https://github.com/ivanvorobei/SparrowKit.git', :tag => s.version }

0 commit comments

Comments
 (0)