Skip to content

Commit 2c4ce00

Browse files
committed
♻️ Replace NotificationBanner with a simple custom error banner
# Conflicts: # README.md
1 parent 4d1fb84 commit 2c4ce00

File tree

4 files changed

+65
-49
lines changed

4 files changed

+65
-49
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ Sample iOS app written the way I write iOS apps because I cannot share the app I
4242
- [RxSwift](https://github.com/ReactiveX/RxSwift) - Reactive Programming in Swift
4343
- [RxSwiftExt](https://github.com/RxSwiftCommunity/RxSwiftExt) - A collection of Rx operators & tools not found in the core RxSwift distribution
4444
- [FeedKit](https://github.com/nmdias/FeedKit) - An RSS, Atom and JSON Feed parser written in Swift
45-
- [NotificationBanner](https://github.com/Daltron/NotificationBanner) - The easiest way to display highly customizable in app notification banners in iOS
4645
- [SwiftLint](https://github.com/realm/SwiftLint) - A tool to enforce Swift style and conventions
4746

4847
## Author

Sources/iOSSampleApp.xcodeproj/project.pbxproj

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10-
F300AE2B244F76DD00F5E060 /* NotificationBannerSwift in Frameworks */ = {isa = PBXBuildFile; productRef = F300AE2A244F76DD00F5E060 /* NotificationBannerSwift */; };
1110
F33474E7244F64220034B1C2 /* RxSwift in Frameworks */ = {isa = PBXBuildFile; productRef = F33474E6244F64220034B1C2 /* RxSwift */; };
1211
F33474E9244F64220034B1C2 /* RxCocoa in Frameworks */ = {isa = PBXBuildFile; productRef = F33474E8244F64220034B1C2 /* RxCocoa */; };
1312
F33474EB244F64220034B1C2 /* RxRelay in Frameworks */ = {isa = PBXBuildFile; productRef = F33474EA244F64220034B1C2 /* RxRelay */; };
@@ -86,7 +85,6 @@
8685
files = (
8786
F33474EB244F64220034B1C2 /* RxRelay in Frameworks */,
8887
F33474FA244F67270034B1C2 /* RxSwiftExt in Frameworks */,
89-
F300AE2B244F76DD00F5E060 /* NotificationBannerSwift in Frameworks */,
9088
F33474E9244F64220034B1C2 /* RxCocoa in Frameworks */,
9189
F33474E7244F64220034B1C2 /* RxSwift in Frameworks */,
9290
F33474F7244F65050034B1C2 /* FeedKit in Frameworks */,
@@ -203,7 +201,6 @@
203201
F33474EA244F64220034B1C2 /* RxRelay */,
204202
F33474F6244F65050034B1C2 /* FeedKit */,
205203
F33474F9244F67270034B1C2 /* RxSwiftExt */,
206-
F300AE2A244F76DD00F5E060 /* NotificationBannerSwift */,
207204
);
208205
productName = iOSSampleApp;
209206
productReference = F3A812B41F83740E00A09AAB /* iOSSampleApp.app */;
@@ -253,7 +250,6 @@
253250
F33474E5244F64220034B1C2 /* XCRemoteSwiftPackageReference "RxSwift" */,
254251
F33474F5244F65050034B1C2 /* XCRemoteSwiftPackageReference "FeedKit" */,
255252
F33474F8244F67270034B1C2 /* XCRemoteSwiftPackageReference "RxSwiftExt" */,
256-
F300AE29244F76DC00F5E060 /* XCRemoteSwiftPackageReference "NotificationBanner" */,
257253
F32344CD29D814B900B1886D /* XCRemoteSwiftPackageReference "SwiftLint" */,
258254
F3DFFC5C2A4C84E2001F5565 /* XCRemoteSwiftPackageReference "SwiftGenPlugin" */,
259255
);
@@ -611,14 +607,6 @@
611607
/* End XCConfigurationList section */
612608

613609
/* Begin XCRemoteSwiftPackageReference section */
614-
F300AE29244F76DC00F5E060 /* XCRemoteSwiftPackageReference "NotificationBanner" */ = {
615-
isa = XCRemoteSwiftPackageReference;
616-
repositoryURL = "https://github.com/Daltron/NotificationBanner";
617-
requirement = {
618-
kind = exactVersion;
619-
version = 3.0.4;
620-
};
621-
};
622610
F32344CD29D814B900B1886D /* XCRemoteSwiftPackageReference "SwiftLint" */ = {
623611
isa = XCRemoteSwiftPackageReference;
624612
repositoryURL = "https://github.com/realm/SwiftLint";
@@ -662,11 +650,6 @@
662650
/* End XCRemoteSwiftPackageReference section */
663651

664652
/* Begin XCSwiftPackageProductDependency section */
665-
F300AE2A244F76DD00F5E060 /* NotificationBannerSwift */ = {
666-
isa = XCSwiftPackageProductDependency;
667-
package = F300AE29244F76DC00F5E060 /* XCRemoteSwiftPackageReference "NotificationBanner" */;
668-
productName = NotificationBannerSwift;
669-
};
670653
F32344CE29D814C000B1886D /* SwiftLintPlugin */ = {
671654
isa = XCSwiftPackageProductDependency;
672655
package = F32344CD29D814B900B1886D /* XCRemoteSwiftPackageReference "SwiftLint" */;

Sources/iOSSampleApp/Data/Licenses.plist

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,6 @@
22
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
33
<plist version="1.0">
44
<array>
5-
<dict>
6-
<key>license</key>
7-
<string>MIT License</string>
8-
<key>text</key>
9-
<string>Copyright (c) 2017-2023 Daltron &lt;[email protected]&gt;
10-
11-
Permission is hereby granted, free of charge, to any person obtaining a copy
12-
of this software and associated documentation files (the &quot;Software&quot;), to deal
13-
in the Software without restriction, including without limitation the rights
14-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15-
copies of the Software, and to permit persons to whom the Software is
16-
furnished to do so, subject to the following conditions:
17-
18-
The above copyright notice and this permission notice shall be included in
19-
all copies or substantial portions of the Software.
20-
21-
THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27-
THE SOFTWARE.
28-
</string>
29-
<key>title</key>
30-
<string>NotificationBanner</string>
31-
</dict>
325
<dict>
336
<key>license</key>
347
<string>MIT License</string>

Sources/iOSSampleApp/Supporting Files/Extensions/UIViewController+Extensions.swift

Lines changed: 65 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,77 @@
77
//
88

99
import Foundation
10-
import NotificationBannerSwift
1110
import UIKit
1211

1312
protocol ToastCapable: AnyObject {
1413
func showErrorToast(message: String)
1514
}
1615

17-
extension ToastCapable where Self: UIViewController {
16+
extension ToastCapable {
1817
func showErrorToast(message: String) {
19-
let banner = StatusBarNotificationBanner(title: message, style: .danger)
20-
banner.show()
18+
ToastBanner.show(message: message)
19+
}
20+
}
21+
22+
final class ToastBanner {
23+
static func show(message: String) {
24+
guard let windowScene = UIApplication.shared.connectedScenes
25+
.first(where: { $0.activationState == .foregroundActive }) as? UIWindowScene,
26+
let window = windowScene.windows.first(where: { $0.isKeyWindow }) else {
27+
return
28+
}
29+
30+
let banner = UIView() &> {
31+
$0.backgroundColor = .systemRed
32+
$0.translatesAutoresizingMaskIntoConstraints = false
33+
}
34+
35+
let label = UILabel() &> {
36+
$0.text = message
37+
$0.textColor = .white
38+
$0.font = UIFont.preferredFont(forTextStyle: .body)
39+
$0.textAlignment = .center
40+
$0.numberOfLines = 0
41+
$0.translatesAutoresizingMaskIntoConstraints = false
42+
}
43+
44+
banner.addSubview(label)
45+
window.addSubview(banner)
46+
47+
let topConstraint = banner.topAnchor.constraint(equalTo: window.topAnchor)
48+
NSLayoutConstraint.activate([
49+
banner.leadingAnchor.constraint(equalTo: window.leadingAnchor),
50+
banner.trailingAnchor.constraint(equalTo: window.trailingAnchor),
51+
topConstraint,
52+
53+
label.leadingAnchor.constraint(equalTo: banner.leadingAnchor, constant: 12),
54+
label.trailingAnchor.constraint(equalTo: banner.trailingAnchor, constant: -12),
55+
label.topAnchor.constraint(equalTo: banner.safeAreaLayoutGuide.topAnchor, constant: 6),
56+
label.bottomAnchor.constraint(equalTo: banner.bottomAnchor, constant: -6)
57+
])
58+
59+
window.layoutIfNeeded()
60+
let height = banner.frame.height
61+
banner.transform = CGAffineTransform(translationX: 0, y: -height)
62+
63+
UIView.animate(
64+
withDuration: 0.3,
65+
animations: {
66+
banner.transform = .identity
67+
},
68+
completion: { _ in
69+
DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) {
70+
UIView.animate(
71+
withDuration: 0.3,
72+
animations: {
73+
banner.transform = CGAffineTransform(translationX: 0, y: -height)
74+
},
75+
completion: { _ in
76+
banner.removeFromSuperview()
77+
}
78+
)
79+
}
80+
}
81+
)
2182
}
2283
}

0 commit comments

Comments
 (0)