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