SwiftKickMobile / SwiftMessages

A very flexible message bar for UIKit and SwiftUI.
MIT License
7.32k stars 746 forks source link

How to make `statusLine` to cover navigationBar? #443

Closed borut-t closed 3 years ago

borut-t commented 3 years ago

I want to show message over statusBar and navigationBar. I just can't figure out how to make this happen with this library. Can you give me some suggestions?

wtmoose commented 3 years ago

Covering the status bar hasn't been possible since iOS 13. You can hide it thought.

This is covered in the documentation:

        /**
         Displays the message in a new window at the specified window level.
         SwiftMessages automatically increases the top margins of any message
         view that adopts the `MarginInsetting` protocol (as `MessageView` does)
         to account for the status bar. As of iOS 13, windows can no longer cover the
         status bar. The only alternative is to set `Config.prefersStatusBarHidden = true`
         to hide it.
        */
        case window(windowLevel: UIWindow.Level)

I do need to update the readme.

borut-t commented 3 years ago

@wtmoose sorry for the confusion. I don't want to cover the status, but show banner bellow it and cover navigation bar.

wtmoose commented 3 years ago

config.presentationContext = .window(windowLevel: .normal)

borut-t commented 3 years ago
Screenshot 2020-12-17 at 21 13 30

@wtmoose I don't get it. It covers the navigation bar just by half. I would expect to fully cover it. Also, I cannot get the title to be visible πŸ€”

Here is the code:

let view = MessageView.viewFromNib(layout: .statusLine)
view.configureContent(title: "No internet connection.", body: "")
view.bodyLabel?.isHidden = true
view.configureTheme(.warning)
view.configureTheme(backgroundColor: .init(red: 255, green: 116, blue: 116), foregroundColor: .white)
view.button?.isHidden = true

var config = SwiftMessages.defaultConfig
config.duration = .forever
config.presentationStyle = .top
config.presentationContext = .window(windowLevel: .normal)
config.interactiveHide = false

SwiftMessages.show(config: config, view: view)
wtmoose commented 3 years ago

The the .statusLine layout you're using was designed to be a 20pt tall bar with a single line of text covering the 20pt status bar on pre-notch phones. The height you see is what you get on a notched phone – it extends far enough below the notch to fit the line of text.

The .statusLine view has only a single element – a label connected to the bodyLabel outlet – which you've hidden. There is no title.

The layouts provided with SwiftMessages are designed to size to fit the content. There is no layout specifically designed to precisely cover the navigation bar.

If you don't have enough content to cover the bar, you can add an explicit height constraint.

borut-t commented 3 years ago

Thanks, @wtmoose for an explanation. I think it would be worth mentioning the behaviour of all predefined layouts how they are used and what are defaults. For my case, I've decided to go with backgroundHeight.

borut-t commented 3 years ago

@wtmoose smth still baffles me. In my setup (tabBar + navBar), the top inset on notch device is 88 pts. When I set this value for backgroundHeight, the banner doesn't fully cover navBar, but it should. So my guess is that the view is offset up a bit to compensate for the bouncing animation. Is that correct? If so, can make sure that the given backgroundHeight gets respected?

wtmoose commented 3 years ago

bounceAnimationOffset is an exposed property on the view that you can change or add to your background height.

borut-t commented 3 years ago

@wtmoose that helps thanks πŸ‘Œ