Skip to content

Commit abc5d54

Browse files
committed
Fix custom presentation style positioning
1 parent 3f37cec commit abc5d54

File tree

3 files changed

+27
-8
lines changed

3 files changed

+27
-8
lines changed

CHANGELOG.md

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

4+
## 4.1.2
5+
6+
### Bug Fixes
7+
* Custom presentation styles using `TopBottomAnimation` now display properly under top and bottom bars.
8+
49
## 4.1.1
510

611
### Features

SwiftMessages.podspec

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
Pod::Spec.new do |spec|
22
spec.name = 'SwiftMessages'
3-
spec.version = '4.1.1'
3+
spec.version = '4.1.2'
44
spec.license = { :type => 'MIT' }
55
spec.homepage = 'https://github.com/SwiftKickMobile/SwiftMessages'
66
spec.authors = { 'Timothy Moose' => 'tim@swiftkick.it' }
77
spec.summary = 'A very flexible message bar for iOS written in Swift.'
8-
spec.source = {:git => 'https://github.com/SwiftKickMobile/SwiftMessages.git', :tag => '4.1.1'}
8+
spec.source = {:git => 'https://github.com/SwiftKickMobile/SwiftMessages.git', :tag => '4.1.2'}
99
spec.platform = :ios, '8.0'
1010
spec.ios.deployment_target = '8.0'
1111
spec.source_files = 'SwiftMessages/**/*.swift'

SwiftMessages/UIViewController+Utils.swift

+20-6
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ private let fullScreenStyles: [UIModalPresentationStyle] = [.fullScreen, .overFu
1313
extension UIViewController {
1414

1515
func sm_selectPresentationContextTopDown(_ config: SwiftMessages.Config) -> UIViewController {
16-
let presentationStyle = config.presentationStyle
16+
let topBottomStyle = config.presentationStyle.topBottomStyle
1717
if let presented = sm_presentedFullScreenViewController() {
1818
return presented.sm_selectPresentationContextTopDown(config)
19-
} else if case .top = presentationStyle, let navigationController = sm_selectNavigationControllerTopDown() {
19+
} else if case .top? = topBottomStyle, let navigationController = sm_selectNavigationControllerTopDown() {
2020
return navigationController
21-
} else if case .bottom = presentationStyle, let tabBarController = sm_selectTabBarControllerTopDown() {
21+
} else if case .bottom? = topBottomStyle, let tabBarController = sm_selectTabBarControllerTopDown() {
2222
return tabBarController
2323
}
2424
return WindowViewController(windowLevel: self.view.window?.windowLevel ?? UIWindowLevelNormal, config: config)
@@ -60,15 +60,15 @@ extension UIViewController {
6060
}
6161

6262
func sm_selectPresentationContextBottomUp(_ config: SwiftMessages.Config) -> UIViewController {
63-
let presentationStyle = config.presentationStyle
63+
let topBottomStyle = config.presentationStyle.topBottomStyle
6464
if let parent = parent {
6565
if let navigationController = parent as? UINavigationController {
66-
if case .top = presentationStyle, navigationController.sm_isVisible(view: navigationController.navigationBar) {
66+
if case .top? = topBottomStyle, navigationController.sm_isVisible(view: navigationController.navigationBar) {
6767
return navigationController
6868
}
6969
return navigationController.sm_selectPresentationContextBottomUp(config)
7070
} else if let tabBarController = parent as? UITabBarController {
71-
if case .bottom = presentationStyle, tabBarController.sm_isVisible(view: tabBarController.tabBar) {
71+
if case .bottom? = topBottomStyle, tabBarController.sm_isVisible(view: tabBarController.tabBar) {
7272
return tabBarController
7373
}
7474
return tabBarController.sm_selectPresentationContextBottomUp(config)
@@ -94,3 +94,17 @@ extension UIViewController {
9494
return true
9595
}
9696
}
97+
98+
extension SwiftMessages.PresentationStyle {
99+
/// A temporary workaround to allow custom presentation contexts using `TopBottomAnimation`
100+
/// to display properly behind bars. THe long term solution is to refactor all of the
101+
/// presentation context logic to work with safe area insets.
102+
var topBottomStyle: TopBottomAnimation.Style? {
103+
switch self {
104+
case .top: return .top
105+
case .bottom: return .bottom
106+
case .custom(let animator): return (animator as? TopBottomAnimation)?.style
107+
case .center: return nil
108+
}
109+
}
110+
}

0 commit comments

Comments
 (0)