Skip to content

Commit

Permalink
feat(App): update safe area handling to support iOS 16 and later
Browse files Browse the repository at this point in the history
  • Loading branch information
lgmarchi committed Dec 12, 2024
1 parent 00a357d commit 5d999c8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
10 changes: 2 additions & 8 deletions ios/App/App/PluginSafeAreasColor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class SafeAreasColorPlugin: CAPPlugin, CAPBridgedPlugin {
}

DispatchQueue.main.async {
if #available(iOS 13.0, *) {
if #available(iOS 16.0, *) {
// Find the active window in iOS 13 or later
if let window = UIApplication.shared.connectedScenes
.compactMap({ $0 as? UIWindowScene })
Expand All @@ -30,13 +30,7 @@ public class SafeAreasColorPlugin: CAPPlugin, CAPBridgedPlugin {
call.reject("No active window found")
}
} else {
// For iOS 12 and earlier
if let window = UIApplication.shared.keyWindow {
window.backgroundColor = uiColor
call.resolve(["value": "Color set successfully"])
} else {
call.reject("No key window found")
}
call.reject("Earlier versions than iOS 16 are not supported")
}
}

Expand Down
10 changes: 4 additions & 6 deletions ios/App/PluginViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,15 @@ class PluginViewController: CAPBridgeViewController {
var leftPadding: CGFloat = 0
var rightPadding: CGFloat = 0

if #available(iOS 13.0, *) {
if #available(iOS 16.0, *) {
let window = view.window ?? UIApplication.shared.windows.first { $0.isKeyWindow }
topPadding = window?.safeAreaInsets.top ?? 0
bottomPadding = window?.safeAreaInsets.bottom ?? 0
leftPadding = window?.safeAreaInsets.left ?? 0
rightPadding = window?.safeAreaInsets.right ?? 0
} else {
topPadding = UIApplication.shared.statusBarFrame.height
}

webView.frame.origin = CGPoint(x: leftPadding, y: topPadding)
webView.frame.size = CGSize(width: UIScreen.main.bounds.width - leftPadding - rightPadding, height: UIScreen.main.bounds.height - topPadding - bottomPadding)
webView.frame.origin = CGPoint(x: leftPadding, y: topPadding)
webView.frame.size = CGSize(width: UIScreen.main.bounds.width - leftPadding - rightPadding, height: UIScreen.main.bounds.height - topPadding - bottomPadding)
}
}
}

0 comments on commit 5d999c8

Please sign in to comment.