Skip to content

Commit 0c27983

Browse files
committed
Add way to customize WIndowViewController
1 parent abc5d54 commit 0c27983

16 files changed

+553
-481
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ All notable changes to this project will be documented in this file.
33

44
## 4.1.2
55

6+
### Features
7+
* #164 Added an optional `windowViewController` property to `SwiftMessages.Config` for supplying a custom subclass of `WindowViewController`.
8+
69
### Bug Fixes
710
* Custom presentation styles using `TopBottomAnimation` now display properly under top and bottom bars.
811

Demo/Podfile.lock

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
PODS:
2-
- SwiftMessages (4.0.1)
2+
- SwiftMessages (4.1.2)
33

44
DEPENDENCIES:
55
- SwiftMessages (from `../`)
@@ -9,8 +9,8 @@ EXTERNAL SOURCES:
99
:path: ../
1010

1111
SPEC CHECKSUMS:
12-
SwiftMessages: 794cbec72392c020e15e4c45dfcfce15781e07cb
12+
SwiftMessages: 7f883c0b717808e9557e9b385f8956418dddd1cb
1313

1414
PODFILE CHECKSUM: 6431c980c9207084d738b6ba87b2101dd9eb5097
1515

16-
COCOAPODS: 1.3.1
16+
COCOAPODS: 1.4.0

Demo/Pods/Local Podspecs/SwiftMessages.podspec.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Demo/Pods/Manifest.lock

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Demo/Pods/Pods.xcodeproj/project.pbxproj

+467-443
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Demo/Pods/Target Support Files/Pods-Demo/Pods-Demo-frameworks.sh

+38-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Demo/Pods/Target Support Files/Pods-Demo/Pods-Demo.debug.xcconfig

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Demo/Pods/Target Support Files/Pods-Demo/Pods-Demo.release.xcconfig

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Demo/Pods/Target Support Files/SwiftMessages/Info.plist

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Demo/Pods/Target Support Files/SwiftMessages/ResourceBundle-SwiftMessages-Info.plist

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Demo/Pods/Target Support Files/SwiftMessages/SwiftMessages.xcconfig

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

SwiftMessages.xcodeproj/project.pbxproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@
246246
children = (
247247
86589D461D64B6E40041676C /* BaseView.swift */,
248248
86AAF82C1D580F410031EE32 /* Theme.swift */,
249+
8644955C1D4FAF7C0056EB2A /* WindowViewController.swift */,
249250
867BED201D622793005212E3 /* BackgroundViewable.swift */,
250251
864495551D4F7C390056EB2A /* Identifiable.swift */,
251252
86AAF81D1D5549680031EE32 /* MarginAdjustable.swift */,
@@ -283,7 +284,6 @@
283284
86AAF8171D54F0650031EE32 /* PassthroughView.swift */,
284285
22E01F631E74EC8B00ACE19A /* MaskingView.swift */,
285286
86AAF8191D54F0850031EE32 /* PassthroughWindow.swift */,
286-
8644955C1D4FAF7C0056EB2A /* WindowViewController.swift */,
287287
86AAF81B1D551FE60031EE32 /* UIViewController+Utils.swift */,
288288
862C0CB01D5911C100D06168 /* NSBundle+Utils.swift */,
289289
);

SwiftMessages/Presenter.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ class Presenter: NSObject {
268268
private func getPresentationContext() throws -> PresentationContext {
269269

270270
func newWindowViewController(_ windowLevel: UIWindowLevel) -> UIViewController {
271-
let viewController = WindowViewController(windowLevel: windowLevel, config: config)
271+
let viewController = WindowViewController.newInstance(windowLevel: windowLevel, config: config)
272272
return viewController
273273
}
274274

SwiftMessages/SwiftMessages.swift

+7
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,13 @@ open class SwiftMessages {
309309
label, e.g. "dismiss" when the `interactive` option is used.
310310
*/
311311
public var dimModeAccessibilityLabel: String = "dismiss"
312+
313+
/**
314+
If specified, SwiftMessages calls this closure when an instance of
315+
`WindowViewController` is needed. Use this if you need to supply a custom subclass
316+
of `WindowViewController`.
317+
*/
318+
public var windowViewController: ((_ windowLevel: UIWindowLevel?, _ config: SwiftMessages.Config) -> WindowViewController)?
312319
}
313320

314321
/**

SwiftMessages/UIViewController+Utils.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ extension UIViewController {
2121
} else if case .bottom? = topBottomStyle, let tabBarController = sm_selectTabBarControllerTopDown() {
2222
return tabBarController
2323
}
24-
return WindowViewController(windowLevel: self.view.window?.windowLevel ?? UIWindowLevelNormal, config: config)
24+
return WindowViewController.newInstance(windowLevel: self.view.window?.windowLevel, config: config)
2525
}
2626

2727
fileprivate func sm_selectNavigationControllerTopDown() -> UINavigationController? {
@@ -80,7 +80,7 @@ extension UIViewController {
8080
if let parent = self.parent {
8181
return parent.sm_selectPresentationContextBottomUp(config)
8282
} else {
83-
return WindowViewController(windowLevel: self.view.window?.windowLevel ?? UIWindowLevelNormal, config: config)
83+
return WindowViewController.newInstance(windowLevel: self.view.window?.windowLevel, config: config)
8484
}
8585
}
8686
return self

SwiftMessages/WindowViewController.swift

+13-7
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,27 @@
88

99
import UIKit
1010

11-
class WindowViewController: UIViewController
11+
open class WindowViewController: UIViewController
1212
{
1313
fileprivate var window: UIWindow?
1414

1515
let windowLevel: UIWindowLevel
1616
let config: SwiftMessages.Config
1717

18-
override var shouldAutorotate: Bool {
18+
override open var shouldAutorotate: Bool {
1919
return config.shouldAutorotate
2020
}
2121

22-
init(windowLevel: UIWindowLevel = UIWindowLevelNormal, config: SwiftMessages.Config)
22+
public init(windowLevel: UIWindowLevel?, config: SwiftMessages.Config)
2323
{
24-
self.windowLevel = windowLevel
24+
self.windowLevel = windowLevel ?? UIWindowLevelNormal
2525
self.config = config
2626
let window = PassthroughWindow(frame: UIScreen.main.bounds)
2727
self.window = window
2828
super.init(nibName: nil, bundle: nil)
2929
self.view = PassthroughView()
3030
window.rootViewController = self
31-
window.windowLevel = windowLevel
31+
window.windowLevel = windowLevel ?? UIWindowLevelNormal
3232
}
3333

3434
func install(becomeKey: Bool) {
@@ -45,11 +45,17 @@ class WindowViewController: UIViewController
4545
window = nil
4646
}
4747

48-
required init?(coder aDecoder: NSCoder) {
48+
required public init?(coder aDecoder: NSCoder) {
4949
fatalError("init(coder:) has not been implemented")
5050
}
5151

52-
override public var preferredStatusBarStyle: UIStatusBarStyle {
52+
override open var preferredStatusBarStyle: UIStatusBarStyle {
5353
return config.preferredStatusBarStyle ?? super.preferredStatusBarStyle
5454
}
5555
}
56+
57+
extension WindowViewController {
58+
static func newInstance(windowLevel: UIWindowLevel?, config: SwiftMessages.Config) -> WindowViewController {
59+
return config.windowViewController?(windowLevel, config) ?? WindowViewController(windowLevel: windowLevel, config: config)
60+
}
61+
}

0 commit comments

Comments
 (0)