Skip to content

Commit

Permalink
Suppprt scenes based apps (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
kirillyakimovich authored Jun 12, 2024
1 parent a3352c6 commit 52ef933
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
4 changes: 4 additions & 0 deletions Sources/Hammer/Utilties/UIKit+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ extension UIDevice {
extension UIWindow {
convenience init(wrapping viewController: UIViewController) {
self.init(frame: UIScreen.main.bounds)
if #available(iOS 13.0, *), self.windowScene == nil {
self.windowScene = UIApplication.shared.connectedScenes
.compactMap { $0 as? UIWindowScene }.first
}
self.rootViewController = viewController
}
}
Expand Down
17 changes: 17 additions & 0 deletions TestHost/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,22 @@
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UIApplicationSceneManifest</key>
<dict>
<key>UIApplicationSupportsMultipleScenes</key>
<false/>
<key>UISceneConfigurations</key>
<dict>
<key>UIWindowSceneSessionRoleApplication</key>
<array>
<dict>
<key>UISceneDelegateClassName</key>
<string>$(PRODUCT_MODULE_NAME).SceneDelegate</string>
<key>UISceneConfigurationName</key>
<string>Default Configuration</string>
</dict>
</array>
</dict>
</dict>
</dict>
</plist>
8 changes: 8 additions & 0 deletions TestHost/SceneDelegate.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import UIKit

@available(iOS 13.0, *)
final class SceneDelegate: UIResponder, UISceneDelegate {
var window: UIWindow?
func scene(_ scene: UIScene, willConnectTo session: UISceneSession,
options connectionOptions: UIScene.ConnectionOptions) {}
}
5 changes: 2 additions & 3 deletions Tests/HammerTests/KeyboardTests.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Hammer
@testable import Hammer
import UIKit
import XCTest

Expand Down Expand Up @@ -187,8 +187,7 @@ final class KeyboardTests: XCTestCase {
view.centerXAnchor.constraint(equalTo: viewController.view.centerXAnchor),
])

let window = UIWindow(frame: UIScreen.main.bounds)
window.rootViewController = viewController
let window = UIWindow(wrapping: viewController)
window.isHidden = false

let eventGenerator = try EventGenerator(window: window)
Expand Down

0 comments on commit 52ef933

Please sign in to comment.