Skip to content

Commit 60a4041

Browse files
committed
# Conflicts: # SwiftMessages.xcodeproj/project.pbxproj
2 parents 4408c09 + eeb6853 commit 60a4041

5 files changed

+36
-8
lines changed

SwiftMessages.xcodeproj/project.pbxproj

+4
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
2298C2051EE47DC900E2DDC1 /* Weak.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2298C2041EE47DC900E2DDC1 /* Weak.swift */; };
5757
2298C2071EE480D000E2DDC1 /* Animator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2298C2061EE480D000E2DDC1 /* Animator.swift */; };
5858
2298C2091EE486E300E2DDC1 /* EdgeAnimation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2298C2081EE486E300E2DDC1 /* EdgeAnimation.swift */; };
59+
229F778125FAB1E9008C2ACB /* UIWindow+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 229F778025FAB1E9008C2ACB /* UIWindow+Extensions.swift */; };
5960
22DFC9161EFF30F6001B1CA1 /* CenteredView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 22DFC9151EFF30F6001B1CA1 /* CenteredView.xib */; };
6061
22DFC9181F00674E001B1CA1 /* PhysicsPanHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 22DFC9171F00674E001B1CA1 /* PhysicsPanHandler.swift */; };
6162
22E01F641E74EC8B00ACE19A /* MaskingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 22E01F631E74EC8B00ACE19A /* MaskingView.swift */; };
@@ -144,6 +145,7 @@
144145
2298C2041EE47DC900E2DDC1 /* Weak.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Weak.swift; sourceTree = "<group>"; };
145146
2298C2061EE480D000E2DDC1 /* Animator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Animator.swift; sourceTree = "<group>"; };
146147
2298C2081EE486E300E2DDC1 /* EdgeAnimation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EdgeAnimation.swift; sourceTree = "<group>"; };
148+
229F778025FAB1E9008C2ACB /* UIWindow+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIWindow+Extensions.swift"; sourceTree = "<group>"; };
147149
22A2EA6E24EC6CFA00BB2540 /* Package.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Package.swift; sourceTree = "<group>"; };
148150
22DFC9151EFF30F6001B1CA1 /* CenteredView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = CenteredView.xib; path = Resources/CenteredView.xib; sourceTree = "<group>"; };
149151
22DFC9171F00674E001B1CA1 /* PhysicsPanHandler.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PhysicsPanHandler.swift; sourceTree = "<group>"; };
@@ -214,6 +216,7 @@
214216
220655111FAF82B600F4E00F /* MarginAdjustable+Extensions.swift */,
215217
22774B9F20B5EF2A00813732 /* UIEdgeInsets+Extensions.swift */,
216218
2290958025D9D407002E8111 /* UILayoutPriority+Extensions.swift */,
219+
229F778025FAB1E9008C2ACB /* UIWindow+Extensions.swift */,
217220
);
218221
name = Extensions;
219222
sourceTree = "<group>";
@@ -553,6 +556,7 @@
553556
86BBA9041D5E040600FE8F16 /* NSBundle+Extensions.swift in Sources */,
554557
86BBA8FD1D5E03F800FE8F16 /* SwiftMessages.swift in Sources */,
555558
86BBA9021D5E040600FE8F16 /* WindowViewController.swift in Sources */,
559+
229F778125FAB1E9008C2ACB /* UIWindow+Extensions.swift in Sources */,
556560
86BBA8FF1D5E040600FE8F16 /* Presenter.swift in Sources */,
557561
86BBA9051D5E040C00FE8F16 /* Theme.swift in Sources */,
558562
86BBA9081D5E040C00FE8F16 /* Error.swift in Sources */,

SwiftMessages/Presenter.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ class Presenter: NSObject {
301301
#if SWIFTMESSAGES_APP_EXTENSIONS
302302
throw SwiftMessagesError.noRootViewController
303303
#else
304-
if let rootViewController = UIApplication.shared.keyWindow?.rootViewController {
304+
if let rootViewController = UIWindow.keyWindow?.rootViewController {
305305
let viewController = rootViewController.sm_selectPresentationContextTopDown(config)
306306
return .viewController(Weak(value: viewController))
307307
} else {

SwiftMessages/SwiftMessages.Config+Extensions.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ extension SwiftMessages.Config {
2525
#if SWIFTMESSAGES_APP_EXTENSIONS
2626
return nil
2727
#else
28-
return UIApplication.shared.keyWindow?.windowScene
28+
return UIWindow.keyWindow?.windowScene
2929
#endif
3030
}
3131
}
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//
2+
// UIWindow+Extensions.swift
3+
// SwiftMessages
4+
//
5+
// Created by Timothy Moose on 3/11/21.
6+
// Copyright © 2021 SwiftKick Mobile. All rights reserved.
7+
//
8+
9+
import UIKit
10+
11+
extension UIWindow {
12+
static var keyWindow: UIWindow? {
13+
if #available(iOS 13.0, *) {
14+
return UIApplication.shared.connectedScenes
15+
.filter { $0.activationState == .foregroundActive }
16+
.compactMap { $0 as? UIWindowScene }
17+
.first?.windows
18+
.filter { $0.isKeyWindow }
19+
.first
20+
} else {
21+
return UIApplication.shared.keyWindow
22+
}
23+
}
24+
}

SwiftMessages/WindowViewController.swift

+6-6
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,9 @@ open class WindowViewController: UIViewController
3535
func install() {
3636
if #available(iOS 13, *) {
3737
window?.windowScene = config.windowScene
38-
if config.shouldBecomeKeyWindow {
39-
#if !SWIFTMESSAGES_APP_EXTENSIONS
40-
previousKeyWindow = UIApplication.shared.keyWindow
41-
#endif
42-
}
38+
#if !SWIFTMESSAGES_APP_EXTENSIONS
39+
previousKeyWindow = UIWindow.keyWindow
40+
#endif
4341
show(
4442
becomeKey: config.shouldBecomeKeyWindow,
4543
frame: config.windowScene?.coordinateSpace.bounds
@@ -60,12 +58,14 @@ open class WindowViewController: UIViewController
6058
}
6159

6260
func uninstall() {
61+
if window?.isKeyWindow == true {
62+
previousKeyWindow?.makeKeyAndVisible()
63+
}
6364
if #available(iOS 13, *) {
6465
window?.windowScene = nil
6566
}
6667
window?.isHidden = true
6768
window = nil
68-
previousKeyWindow?.makeKeyAndVisible()
6969
}
7070

7171
required public init?(coder aDecoder: NSCoder) {

0 commit comments

Comments
 (0)