How to detect dynamic-island size and changes in SwiftUI & UIKit

Viewed 2086

How can we detect the size and changes of the iPhone 14 pro dynamic-island?

Since the safe area provides a safe rectangle inside the rounded screen and top or bottom insets, but nothing about an object inside the rectangle.

The all we know about safe area:

enter image description here

3 Answers

It is not official, but according to unofficial rumours the dynamic island API will be part of Activities and ActivityKit and would be available later this year of 2022 (exact date not specified ). For further information pay close look for new Beta version of Activities

You can simply try to get the safe area top insets and use the dynamic height as you want.

In my scenario, requirement was to change status bar background colour. So I did something like this:

    let window = UIApplication.shared.windows.first
    let topPadding = window?.safeAreaInsets.top
    let statusBar = UIView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.size.width, height: topPadding ?? 0.0))
    statusBar.backgroundColor = UIColor(named: "AppPrimaryColor")
    UIApplication.shared.windows.filter {$0.isKeyWindow}.first?.addSubview(statusBar)

Dynamic island is fun to play with. screen shot

Related