Skip to content

Commit 66841d3

Browse files
authored
feat(TopBottomPresentable): Adds 'TopBottomPresentable' protocol, allow any Animator to be presented correctly by the Presenter (SwiftKickMobile#548)
1 parent a49306b commit 66841d3

11 files changed

+96
-36
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
# Change Log
22
All notable changes to this project will be documented in this file.
33

4+
## 10.0.1
5+
6+
## Features
7+
8+
* Adds 'TopBottomPresentable' protocol to allow animators implementation to reuse 'top/bottom' integration in presentation
9+
410
## 10.0.0
511

612
### Features

SwiftMessages.podspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |spec|
22
spec.name = 'SwiftMessages'
3-
spec.version = '10.0.0'
3+
spec.version = '10.0.1'
44
spec.license = { :type => 'MIT' }
55
spec.homepage = 'https://github.com/SwiftKickMobile/SwiftMessages'
66
spec.authors = { 'Timothy Moose' => 'tim@swiftkickmobile.com' }

SwiftMessages.xcodeproj/project.pbxproj

+17-9
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
0797E40E26EE12B400691606 /* WindowScene.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0797E40D26EE12B400691606 /* WindowScene.swift */; };
1111
220655121FAF82B600F4E00F /* MarginAdjustable+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 220655111FAF82B600F4E00F /* MarginAdjustable+Extensions.swift */; };
1212
220D386E2597AA5B00BB2B88 /* SwiftMessages.Config+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 220D386D2597AA5B00BB2B88 /* SwiftMessages.Config+Extensions.swift */; };
13+
224C3C902C28A2F900B50B18 /* TopBottomPresentable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 224C3C8F2C28A2F900B50B18 /* TopBottomPresentable.swift */; };
14+
224C3C932C28BC4900B50B18 /* TopBottomAnimationStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 224C3C922C28BC4400B50B18 /* TopBottomAnimationStyle.swift */; };
1315
224FB69921153B440081D4DE /* CALayer+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 224FB69821153B440081D4DE /* CALayer+Extensions.swift */; };
1416
225304622290C76E00A03ACF /* NSLayoutConstraint+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 225304612290C76E00A03ACF /* NSLayoutConstraint+Extensions.swift */; };
1517
225304662293000C00A03ACF /* KeyboardTrackingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 225304652293000C00A03ACF /* KeyboardTrackingView.swift */; };
@@ -103,6 +105,8 @@
103105
0797E40D26EE12B400691606 /* WindowScene.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WindowScene.swift; sourceTree = "<group>"; };
104106
220655111FAF82B600F4E00F /* MarginAdjustable+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MarginAdjustable+Extensions.swift"; sourceTree = "<group>"; };
105107
220D386D2597AA5B00BB2B88 /* SwiftMessages.Config+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SwiftMessages.Config+Extensions.swift"; sourceTree = "<group>"; };
108+
224C3C8F2C28A2F900B50B18 /* TopBottomPresentable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TopBottomPresentable.swift; sourceTree = "<group>"; };
109+
224C3C922C28BC4400B50B18 /* TopBottomAnimationStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TopBottomAnimationStyle.swift; sourceTree = "<group>"; };
106110
224FB69821153B440081D4DE /* CALayer+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CALayer+Extensions.swift"; sourceTree = "<group>"; };
107111
225304612290C76E00A03ACF /* NSLayoutConstraint+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSLayoutConstraint+Extensions.swift"; sourceTree = "<group>"; };
108112
225304652293000C00A03ACF /* KeyboardTrackingView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyboardTrackingView.swift; sourceTree = "<group>"; };
@@ -314,20 +318,22 @@
314318
864495571D4F7C490056EB2A /* Base */ = {
315319
isa = PBXGroup;
316320
children = (
317-
86589D461D64B6E40041676C /* BaseView.swift */,
318-
86AAF82C1D580F410031EE32 /* Theme.swift */,
319-
8644955C1D4FAF7C0056EB2A /* WindowViewController.swift */,
320-
867BED201D622793005212E3 /* BackgroundViewable.swift */,
321-
864495551D4F7C390056EB2A /* Identifiable.swift */,
322-
86AAF81D1D5549680031EE32 /* MarginAdjustable.swift */,
323321
22E307FE1E74C5B100E35893 /* AccessibleMessage.swift */,
324-
22982C162B6030B000852311 /* HapticMessage.swift */,
325-
86AAF82A1D580DD70031EE32 /* Error.swift */,
326322
2298C2061EE480D000E2DDC1 /* Animator.swift */,
327-
2298C2041EE47DC900E2DDC1 /* Weak.swift */,
323+
867BED201D622793005212E3 /* BackgroundViewable.swift */,
324+
86589D461D64B6E40041676C /* BaseView.swift */,
328325
22F27950210CE25900273E7F /* CornerRoundingView.swift */,
326+
86AAF82A1D580DD70031EE32 /* Error.swift */,
327+
22982C162B6030B000852311 /* HapticMessage.swift */,
328+
864495551D4F7C390056EB2A /* Identifiable.swift */,
329329
225304652293000C00A03ACF /* KeyboardTrackingView.swift */,
330+
86AAF81D1D5549680031EE32 /* MarginAdjustable.swift */,
331+
86AAF82C1D580F410031EE32 /* Theme.swift */,
332+
224C3C922C28BC4400B50B18 /* TopBottomAnimationStyle.swift */,
333+
224C3C8F2C28A2F900B50B18 /* TopBottomPresentable.swift */,
334+
2298C2041EE47DC900E2DDC1 /* Weak.swift */,
330335
0797E40D26EE12B400691606 /* WindowScene.swift */,
336+
8644955C1D4FAF7C0056EB2A /* WindowViewController.swift */,
331337
);
332338
name = Base;
333339
sourceTree = "<group>";
@@ -568,6 +574,7 @@
568574
228F7DDF2ACF703A006C9644 /* SwiftMessageModifier.swift in Sources */,
569575
224FB69921153B440081D4DE /* CALayer+Extensions.swift in Sources */,
570576
22E01F641E74EC8B00ACE19A /* MaskingView.swift in Sources */,
577+
224C3C932C28BC4900B50B18 /* TopBottomAnimationStyle.swift in Sources */,
571578
2298C2051EE47DC900E2DDC1 /* Weak.swift in Sources */,
572579
228F7DE02ACF703A006C9644 /* MessageViewConvertible.swift in Sources */,
573580
86BBA9001D5E040600FE8F16 /* PassthroughView.swift in Sources */,
@@ -578,6 +585,7 @@
578585
22E307FF1E74C5B100E35893 /* AccessibleMessage.swift in Sources */,
579586
220D386E2597AA5B00BB2B88 /* SwiftMessages.Config+Extensions.swift in Sources */,
580587
2270044B1FAFA6DD0045DDC3 /* PhysicsAnimation.swift in Sources */,
588+
224C3C902C28A2F900B50B18 /* TopBottomPresentable.swift in Sources */,
581589
86BBA9041D5E040600FE8F16 /* NSBundle+Extensions.swift in Sources */,
582590
86BBA8FD1D5E03F800FE8F16 /* SwiftMessages.swift in Sources */,
583591
86BBA9021D5E040600FE8F16 /* WindowViewController.swift in Sources */,

SwiftMessages/Animator.swift

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import UIKit
1010

1111
public typealias AnimationCompletion = (_ completed: Bool) -> Void
1212

13+
@MainActor
1314
public protocol AnimationDelegate: AnyObject {
1415
func hide(animator: Animator)
1516
func panStarted(animator: Animator)

SwiftMessages/Presenter.swift

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import UIKit
1010

11+
@MainActor
1112
protocol PresenterDelegate: AnimationDelegate {
1213
func hide(presenter: Presenter)
1314
}

SwiftMessages/SwiftMessages.Config+Extensions.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ extension SwiftMessages.Config {
1717
}
1818
}
1919

20-
@available (iOS 13.0, *)
20+
@available(iOS 13.0, *)
2121
var windowScene: UIWindowScene? {
2222
switch presentationContext {
2323
case .windowScene(let scene, _): return scene as? UIWindowScene

SwiftMessages/SwiftMessages.swift

+4-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
import UIKit
1010

11-
@MainActor
1211
private let globalInstance = SwiftMessages()
1312

1413
/**
@@ -774,6 +773,7 @@ extension SwiftMessages: PresenterDelegate {
774773
queueAutoHide()
775774
}
776775

776+
@MainActor
777777
private func presenter(forAnimator animator: Animator) -> Presenter? {
778778
if let current = _current, animator === current.animator {
779779
return current
@@ -885,11 +885,12 @@ extension SwiftMessages {
885885
a set of static APIs that wrap calls to this instance. For example, `SwiftMessages.show()`
886886
is equivalent to `SwiftMessages.sharedInstance.show()`.
887887
*/
888+
@MainActor
888889
public static var sharedInstance: SwiftMessages {
889890
return globalInstance
890891
}
891-
892-
public static func show(viewProvider: @escaping ViewProvider) {
892+
893+
nonisolated public static func show(viewProvider: @escaping ViewProvider) {
893894
globalInstance.show(viewProvider: viewProvider)
894895
}
895896

SwiftMessages/TopBottomAnimation.swift

+4-8
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,12 @@
88

99
import UIKit
1010

11+
@MainActor
1112
public class TopBottomAnimation: NSObject, Animator {
1213

13-
public enum Style {
14-
case top
15-
case bottom
16-
}
17-
1814
public weak var delegate: AnimationDelegate?
1915

20-
public let style: Style
16+
public let style: TopBottomAnimationStyle
2117

2218
public var showDuration: TimeInterval = 0.4
2319

@@ -41,11 +37,11 @@ public class TopBottomAnimation: NSObject, Animator {
4137
weak var containerView: UIView?
4238
var context: AnimationContext?
4339

44-
public init(style: Style) {
40+
public init(style: TopBottomAnimationStyle) {
4541
self.style = style
4642
}
4743

48-
init(style: Style, delegate: AnimationDelegate) {
44+
init(style: TopBottomAnimationStyle, delegate: AnimationDelegate) {
4945
self.style = style
5046
self.delegate = delegate
5147
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//
2+
// TopBottomAnimationStyle.swift
3+
// SwiftMessages
4+
//
5+
// Created by Timothy Moose on 6/23/24.
6+
// Copyright © 2024 SwiftKick Mobile. All rights reserved.
7+
//
8+
9+
public enum TopBottomAnimationStyle {
10+
case top
11+
case bottom
12+
}
+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
//
2+
// File.swift
3+
//
4+
//
5+
// Created by Julien Di Marco on 23/04/2024.
6+
//
7+
8+
import Foundation
9+
10+
// MARK: - TopBottom Presentable Definition
11+
12+
@MainActor
13+
protocol TopBottomPresentable {
14+
var topBottomStyle: TopBottomAnimationStyle? { get }
15+
}
16+
17+
// MARK: - TopBottom Presentable Conformances
18+
19+
extension TopBottomAnimation: TopBottomPresentable {
20+
var topBottomStyle: TopBottomAnimationStyle? { return style }
21+
}
22+
23+
extension PhysicsAnimation: TopBottomPresentable {
24+
var topBottomStyle: TopBottomAnimationStyle? {
25+
switch placement {
26+
case .top: return .top
27+
case .bottom: return .bottom
28+
default: return nil
29+
}
30+
}
31+
}
32+
33+
// MARK: - Presentation Style Convenience
34+
35+
extension SwiftMessages.PresentationStyle {
36+
/// A temporary workaround to allow custom presentation contexts using `TopBottomAnimation`
37+
/// to display properly behind bars. THe long term solution is to refactor all of the
38+
/// presentation context logic to work with safe area insets.
39+
@MainActor
40+
var topBottomStyle: TopBottomAnimationStyle? {
41+
switch self {
42+
case .top: return .top
43+
case .bottom: return .bottom
44+
case .custom(let animator as TopBottomPresentable): return animator.topBottomStyle
45+
case .center: return nil
46+
default: return nil
47+
}
48+
}
49+
}

SwiftMessages/UIViewController+Extensions.swift

-14
Original file line numberDiff line numberDiff line change
@@ -85,17 +85,3 @@ extension UIViewController {
8585
return true
8686
}
8787
}
88-
89-
extension SwiftMessages.PresentationStyle {
90-
/// A temporary workaround to allow custom presentation contexts using `TopBottomAnimation`
91-
/// to display properly behind bars. THe long term solution is to refactor all of the
92-
/// presentation context logic to work with safe area insets.
93-
var topBottomStyle: TopBottomAnimation.Style? {
94-
switch self {
95-
case .top: return .top
96-
case .bottom: return .bottom
97-
case .custom(let animator): return (animator as? TopBottomAnimation)?.style
98-
case .center: return nil
99-
}
100-
}
101-
}

0 commit comments

Comments
 (0)