Skip to content

Commit

Permalink
feat(splash-screen): Make splash work in apps that use scenes (#631)
Browse files Browse the repository at this point in the history
Co-authored-by: jcesarmobile <jcesarmobile@gmail.com>
  • Loading branch information
RishatShamsutdinov and jcesarmobile authored Dec 6, 2021
1 parent d05f609 commit cf0d214
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions splash-screen/ios/Plugin/SplashScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -117,16 +117,17 @@ import Capacitor
// Update the bounds for the splash image. This will also be called when
// the parent view observers fire
private func updateSplashImageBounds() {
guard let delegate = UIApplication.shared.delegate else {
CAPLog.print("Unable to find root window object for SplashScreen bounds. Please file an issue")
return
var window: UIWindow? = UIApplication.shared.delegate?.window as? UIWindow

if #available(iOS 13, *), window == nil {
window = (UIApplication.shared.connectedScenes.first as? UIWindowScene)?.windows.filter({$0.isKeyWindow}).first
}

guard let window = delegate.window as? UIWindow else {
if let unwrappedWindow = window {
viewController.view.frame = CGRect(origin: CGPoint(x: 0, y: 0), size: unwrappedWindow.bounds.size)
} else {
CAPLog.print("Unable to find root window object for SplashScreen bounds. Please file an issue")
return
}
viewController.view.frame = CGRect(origin: CGPoint(x: 0, y: 0), size: window.bounds.size)
}

override public func observeValue(forKeyPath keyPath: String?, of object: Any?, change _: [NSKeyValueChangeKey: Any]?, context: UnsafeMutableRawPointer?) {
Expand Down

0 comments on commit cf0d214

Please sign in to comment.