Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Making sure FloatingNotificationBanner is always in front of all views #427

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix: Made sure FloatingNotificationBanner is always on top
  • Loading branch information
Karnika Advani committed Mar 13, 2024
commit 0671719d0d5f48c51d22551cb9df7f0aa46843e1
16 changes: 14 additions & 2 deletions NotificationBanner/Classes/FloatingNotificationBanner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ open class FloatingNotificationBanner: GrowingNotificationBanner {
rightView: UIView? = nil,
style: BannerStyle = .info,
colors: BannerColorsProtocol? = nil,
iconPosition: IconPosition = .center
iconPosition: IconPosition = .center,
alwaysInFront: Bool = true
) {

super.init(
Expand Down Expand Up @@ -72,9 +73,13 @@ open class FloatingNotificationBanner: GrowingNotificationBanner {
if let subtitleTextAlign = subtitleTextAlign {
subtitleLabel!.textAlignment = subtitleTextAlign
}

if alwaysInFront {
setAlwaysInFront()
}
}

public init(customView: UIView) {
public init(customView: UIView, alwaysInFront: Bool = false) {
super.init(style: .customView)
self.customView = customView

Expand All @@ -84,6 +89,10 @@ open class FloatingNotificationBanner: GrowingNotificationBanner {
}

spacerView.backgroundColor = customView.backgroundColor

if alwaysInFront {
setAlwaysInFront()
}
}

/**
Expand Down Expand Up @@ -174,4 +183,7 @@ private extension FloatingNotificationBanner {
contentView.layer.shouldRasterize = true
}

private func setAlwaysInFront() {
self.layer.zPosition = CGFloat(Float.greatestFiniteMagnitude)
}
}