SwiftKickMobile / SwiftMessages

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

KeyboardTrackingView causes a small space under bottom-style view #483

Closed kientux closed 2 years ago

kientux commented 2 years ago

When I add KeyboardTrackingView to config and show a bottom-style view, there is a small space under it.

let messageView = BaseView(frame: .zero)

let backgroundView = CornerRoundingView()
backgroundView.cornerRadius = 12
backgroundView.layer.masksToBounds = true
messageView.installBackgroundView(backgroundView)

let contentView = UIView(frame: CGRect(x: 0, y: 0, width: 320, height: 128))
contentView.backgroundColor = .white
messageView.installContentView(contentView)

messageView.layoutMarginAdditions = .zero
messageView.respectSafeArea = false

var config = SwiftMessages.defaultConfig
config.keyboardTrackingView = KeyboardTrackingView()
config.dimMode = .color(color: UIColor(white: 0, alpha: 0.55), interactive: true)

config.presentationStyle = .bottom
config.duration = .forever
config.interactiveHide = false

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

// alertPresenter = SwiftMessages()
alertPresenter.show(config: config, view: messageView)

respectSafeArea = false is for iPhone with notch so we can clearly see it. I tried on normal iPhones and this still happens.

Screenshots:

With KeyboardTrackingView:

Simulator Screen Shot - iPhone 11 - 2021-09-29 at 16 14 19

Without:

Simulator Screen Shot - iPhone 11 - 2021-09-29 at 16 14 06

wtmoose commented 2 years ago

Can you try the work/9.0.5 branch?

Here's an explanation if you're interested. By default, the bottom presentation places the message view 5pt below the screen so that the spring animation doesn't show a gap under the view when it overshoots. This behavior is intended for cases where the message view has a background color. However, you're using a clear message view with a background view that provides the visible region of the view. The background view's constraints negate the 5pt offset, so it aligns with the bottom of the screen. However, when you add the keyboard tracking view, the entire message view, along with the background view, is pushed up by 5pt.

You can fix this by setting the following:

messageView.bounceAnimationOffset = 0

But on the work/9.0.5 branch, I've accounted for bounceAnimationOffset with the keyboard tracking view, so the above setting isn't needed.

kientux commented 2 years ago

Thank you, I tried the work/9.0.5 branch and it worked as expected. Anyway, I use a custom TopBottomAnimation to disable the spring damping so setting bounceAnimationOffset = 0 also do the work.