Skip to content

Commit 4530406

Browse files
mrsnow-gitDaltron
authored andcommitted
Display several banners stacked (Daltron#234)
* Rasterize banners shadow to speed up rendering * Update marque labels duration calculation to minimum value possible * Implement possibility to display several banners on screen simultaneously with animations calculations, taps for dismiss and in-process banners showing * Fix banner frame y position calculations for .bottom styled banners * Change default value for banners visible on screen at once * Add Simultaneous Floating Notification banners usage example * Update Copyright on Example app Launch Screen * Fix misspelling in Example app * Update README for more usage code axamples * Update README to include more apps used this library
1 parent 686d00f commit 4530406

12 files changed

+324
-81
lines changed

AppIcons/lukapizza.png

8.21 KB
Loading

AppIcons/ris.png

4.82 KB
Loading

AppIcons/tsum.png

5.18 KB
Loading

Example/NotificationBanner/Base.lproj/LaunchScreen.xib

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="11762" systemVersion="15G1421" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" colorMatched="YES">
3-
<device id="retina4_7" orientation="portrait">
4-
<adaptation id="fullscreen"/>
5-
</device>
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="14868" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" colorMatched="YES">
3+
<device id="retina4_7" orientation="portrait" appearance="light"/>
64
<dependencies>
7-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11757"/>
8-
<capability name="Constraints with non-1.0 multipliers" minToolsVersion="5.1"/>
5+
<deployment identifier="iOS"/>
6+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14824"/>
97
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
108
</dependencies>
119
<objects>
@@ -15,14 +13,14 @@
1513
<rect key="frame" x="0.0" y="0.0" width="480" height="480"/>
1614
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
1715
<subviews>
18-
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text=" Copyright (c) 2017 CocoaPods. All rights reserved." textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumFontSize="9" translatesAutoresizingMaskIntoConstraints="NO" id="8ie-xW-0ye">
19-
<rect key="frame" x="20" y="439" width="441" height="21"/>
16+
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Copyright © 2017-2019 NotificatiosBanner. All rights reserved." textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumFontSize="9" translatesAutoresizingMaskIntoConstraints="NO" id="8ie-xW-0ye">
17+
<rect key="frame" x="20" y="439" width="440" height="21"/>
2018
<fontDescription key="fontDescription" type="system" pointSize="17"/>
2119
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
2220
<nil key="highlightedColor"/>
2321
</label>
2422
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="NotificationBanner" textAlignment="center" lineBreakMode="middleTruncation" baselineAdjustment="alignBaselines" minimumFontSize="18" translatesAutoresizingMaskIntoConstraints="NO" id="kId-c2-rCX">
25-
<rect key="frame" x="20" y="140" width="441" height="43"/>
23+
<rect key="frame" x="20" y="139.5" width="440" height="43"/>
2624
<fontDescription key="fontDescription" type="boldSystem" pointSize="36"/>
2725
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
2826
<nil key="highlightedColor"/>

Example/NotificationBanner/ExampleView.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ protocol ExampleViewDelegate : class {
1919
func basicCustomNotificationCellSelected(at index: Int)
2020
func basicGrowingNotificationCellSelected(at index: Int)
2121
func basicFloatingNotificationCellSelected(at index: Int)
22+
func basicSimulanteousFloatingNotificationCellSelected(at index: Int)
2223
func basicStatusBarNotificationCellSelected(at index: Int)
2324
}
2425

@@ -119,7 +120,7 @@ class ExampleView: UIView {
119120
extension ExampleView : UITableViewDataSource {
120121

121122
func numberOfSections(in tableView: UITableView) -> Int {
122-
return 6
123+
return 7
123124
}
124125

125126
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
@@ -167,6 +168,8 @@ extension ExampleView : UITableViewDelegate {
167168
} else if indexPath.section == 4 {
168169
delegate?.basicFloatingNotificationCellSelected(at: indexPath.row)
169170
} else if indexPath.section == 5 {
171+
delegate?.basicSimulanteousFloatingNotificationCellSelected(at: indexPath.row)
172+
} else if indexPath.section == 6 {
170173
delegate?.basicStatusBarNotificationCellSelected(at: indexPath.row)
171174
}
172175
}

Example/NotificationBanner/ExampleViewController.swift

Lines changed: 104 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,94 @@ extension ExampleViewController: ExampleViewDelegate {
263263
shadowBlurRadius: 15)
264264
}
265265
}
266+
267+
internal func basicSimulanteousFloatingNotificationCellSelected(at index: Int) {
268+
269+
func showBanners(_ banners: [FloatingNotificationBanner],
270+
in notificationBannerQueue: NotificationBannerQueue) {
271+
banners.forEach { banner in
272+
banner.show(bannerPosition: selectedBannerPosition(),
273+
queue: notificationBannerQueue,
274+
cornerRadius: 8,
275+
shadowColor: UIColor(red: 0.431, green: 0.459, blue: 0.494, alpha: 1),
276+
shadowBlurRadius: 16,
277+
shadowEdgeInsets: UIEdgeInsets(top: 8, left: 8, bottom: 0, right: 8))
278+
}
279+
}
280+
281+
switch index {
282+
case 0:
283+
let bannerQueue2AllowedSuccess = NotificationBannerQueue(maxBannersOnScreenSimultaneously: 2)
284+
285+
let banner1 = FloatingNotificationBanner(title: "Success Notification 1",
286+
subtitle: "First Success Notification in current queue with 2 banners allowed simultaneously",
287+
style: .success)
288+
banner1.delegate = self
289+
290+
let banner2 = FloatingNotificationBanner(title: "Success Notification 2",
291+
subtitle: "Second Success Notification in current queue with 2 banners allowed simultaneously",
292+
style: .success)
293+
banner2.delegate = self
294+
295+
let banner3 = FloatingNotificationBanner(title: "Success Notification 3",
296+
subtitle: "Third Success Notification in current queue with 2 banners allowed simultaneously",
297+
style: .success)
298+
banner3.delegate = self
299+
300+
showBanners([banner1, banner2, banner3],
301+
in: bannerQueue2AllowedSuccess)
302+
303+
case 1:
304+
let bannerQueue3AllowedDanger = NotificationBannerQueue(maxBannersOnScreenSimultaneously: 3)
305+
306+
let banner1 = FloatingNotificationBanner(title: "Danger Notification 1",
307+
subtitle: "First Danger Notification in current queue with 3 banners allowed simultaneously",
308+
style: .danger)
309+
banner1.delegate = self
310+
311+
let banner2 = FloatingNotificationBanner(title: "Danger Notification 2",
312+
subtitle: "Second Danger Notification in current queue with 3 banners allowed simultaneously",
313+
style: .danger)
314+
banner2.delegate = self
315+
316+
showBanners([banner1, banner2],
317+
in: bannerQueue3AllowedDanger)
318+
319+
case 2:
320+
let bannerQueue5AllowedMixed = NotificationBannerQueue(maxBannersOnScreenSimultaneously: 3)
321+
322+
let banner1 = FloatingNotificationBanner(title: "Success Notification - 1",
323+
subtitle: "First Notification from 5 in current queue with 3 banners allowed simultaneously",
324+
style: .success)
325+
banner1.delegate = self
326+
327+
let banner2 = FloatingNotificationBanner(title: "Danger Notification - 2",
328+
subtitle: "Second Notification from 5 in current queue with 3 banners allowed simultaneously",
329+
style: .danger)
330+
banner2.delegate = self
331+
332+
let banner3 = FloatingNotificationBanner(title: "Info Notification - 3",
333+
subtitle: "Third Notification from 5 in current queue with 3 banners allowed simultaneously",
334+
style: .info)
335+
banner3.delegate = self
336+
337+
let banner4 = FloatingNotificationBanner(title: "Success Notification - 4",
338+
subtitle: "Fourth Notification from 5 in current queue with 3 banners allowed simultaneously",
339+
style: .success)
340+
banner4.delegate = self
341+
342+
let banner5 = FloatingNotificationBanner(title: "Info Notification - 5",
343+
subtitle: "Fifth Notification from 5 in current queue with 3 banners allowed simultaneously",
344+
style: .info)
345+
banner5.delegate = self
346+
347+
showBanners([banner1, banner2, banner3, banner4, banner5],
348+
in: bannerQueue5AllowedMixed)
349+
350+
default:
351+
break
352+
}
353+
}
266354

267355
internal func basicStatusBarNotificationCellSelected(at index: Int) {
268356
switch index {
@@ -334,6 +422,8 @@ extension ExampleViewController: ExampleViewDelegate {
334422
case 4:
335423
return 4
336424
case 5:
425+
return 3
426+
case 6:
337427
return 6
338428
default:
339429
return 0
@@ -353,6 +443,8 @@ extension ExampleViewController: ExampleViewDelegate {
353443
case 4:
354444
return "Floating Notification Banners"
355445
case 5:
446+
return "Simultaneous Floating Notification Banners"
447+
case 6:
356448
return "Status Bar Notifications"
357449
default:
358450
return ""
@@ -362,7 +454,7 @@ extension ExampleViewController: ExampleViewDelegate {
362454
internal func blockColor(at indexPath: IndexPath) -> UIColor {
363455

364456
if indexPath == IndexPath(row: numberOfCells(for: indexPath.section) - 2, section: 0)
365-
|| indexPath == IndexPath(row: numberOfCells(for: indexPath.section) - 2, section: 5) {
457+
|| indexPath == IndexPath(row: numberOfCells(for: indexPath.section) - 2, section: 6) {
366458
return CustomBannerColors().color(for: .warning)
367459
}
368460

@@ -446,6 +538,17 @@ extension ExampleViewController: ExampleViewDelegate {
446538
return ("", nil)
447539
}
448540
} else if indexPath.section == 5 {
541+
switch indexPath.row {
542+
case 0:
543+
return ("3 Success Notifications", "Display it at once, with 2 in queue allowed simultaneosly")
544+
case 1:
545+
return ("2 Danger Notifications", "Display it at once, with 3 in queue allowed simultaneosly")
546+
case 2:
547+
return ("5 Mixed Notifications", "Display it at once, with 3 in queue allowed simultaneosly")
548+
default:
549+
return ("", nil)
550+
}
551+
} else if indexPath.section == 6 {
449552
switch indexPath.row {
450553
case 0:
451554
return ("Success Notification", nil)

NotificationBanner/Classes/BannerPositionFrame.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,11 @@ class BannerPositionFrame: NSObject {
3333
bannerWidth: CGFloat,
3434
bannerHeight: CGFloat,
3535
maxY: CGFloat,
36+
finishYOffset: CGFloat = 0,
3637
edgeInsets: UIEdgeInsets?) {
3738
super.init()
3839
self.startFrame = startFrame(for: bannerPosition, bannerWidth: bannerWidth, bannerHeight: bannerHeight, maxY: maxY, edgeInsets: edgeInsets)
39-
self.endFrame = endFrame(for: bannerPosition, bannerWidth: bannerWidth, bannerHeight: bannerHeight, maxY: maxY, edgeInsets: edgeInsets)
40+
self.endFrame = endFrame(for: bannerPosition, bannerWidth: bannerWidth, bannerHeight: bannerHeight, maxY: maxY, finishYOffset: finishYOffset, edgeInsets: edgeInsets)
4041
}
4142

4243
/**
@@ -77,25 +78,27 @@ class BannerPositionFrame: NSObject {
7778
- parameter bannerWidth: The width of the notification banner
7879
- parameter bannerHeight: The height of the notification banner
7980
- parameter maxY: The maximum `y` position the banner can slide in from. This value is only used if the bannerPosition is .bottom
81+
- parameter finishYOffset: The `y` position offset the banner can slide in. Used for displaying several banenrs simaltaneously
8082
- parameter edgeInsets: The sides edges insets from superview
8183
*/
8284
private func endFrame(for bannerPosition: BannerPosition,
8385
bannerWidth: CGFloat,
8486
bannerHeight: CGFloat,
8587
maxY: CGFloat,
88+
finishYOffset: CGFloat = 0,
8689
edgeInsets: UIEdgeInsets?) -> CGRect {
8790

8891
let edgeInsets = edgeInsets ?? .zero
8992

9093
switch bannerPosition {
9194
case .bottom:
9295
return CGRect(x: edgeInsets.left,
93-
y: maxY - bannerHeight - edgeInsets.bottom,
96+
y: maxY - bannerHeight - edgeInsets.bottom - finishYOffset,
9497
width: startFrame.width,
9598
height: startFrame.height)
9699
case .top:
97100
return CGRect(x: edgeInsets.left,
98-
y: edgeInsets.top,
101+
y: edgeInsets.top + finishYOffset,
99102
width: startFrame.width,
100103
height: startFrame.height)
101104
}

0 commit comments

Comments
 (0)