Skip to content

Commit

Permalink
Fix for status bar banner on non-notch iPhones on iOS 13 (#241)
Browse files Browse the repository at this point in the history
* Update README.md

* Adds FloatingNotificationBanner.swift to XcodeProject (Carthage)

* Fixes #240 status bar banner on non-notch iPhones on iOS 13
  • Loading branch information
igorkulman authored and Daltron committed Oct 1, 2019
1 parent 010a357 commit 07feb7e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
4 changes: 4 additions & 0 deletions NotificationBanner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
0D0D9ADF1F15D19D003B35A8 /* BannerPositionFrame.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D0D9ADE1F15D19D003B35A8 /* BannerPositionFrame.swift */; };
2B9A8469216538CA00A7418D /* GrowingNotificationBanner.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2B9A8468216538CA00A7418D /* GrowingNotificationBanner.swift */; };
2B9A846B216544E600A7418D /* String+heightForConstrainedWidth.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2B9A846A216544E600A7418D /* String+heightForConstrainedWidth.swift */; };
7ECA5719232FA42B00256BB9 /* FloatingNotificationBanner.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7ECA5718232FA42B00256BB9 /* FloatingNotificationBanner.swift */; };
823255AF1EB87313006F95C3 /* BannerColors.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8232559F1EB87313006F95C3 /* BannerColors.swift */; };
823255B01EB87313006F95C3 /* BannerStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 823255A01EB87313006F95C3 /* BannerStyle.swift */; };
823255B11EB87313006F95C3 /* BaseNotificationBanner.swift in Sources */ = {isa = PBXBuildFile; fileRef = 823255A11EB87313006F95C3 /* BaseNotificationBanner.swift */; };
Expand All @@ -28,6 +29,7 @@
0D0D9ADE1F15D19D003B35A8 /* BannerPositionFrame.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BannerPositionFrame.swift; sourceTree = "<group>"; };
2B9A8468216538CA00A7418D /* GrowingNotificationBanner.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GrowingNotificationBanner.swift; sourceTree = "<group>"; };
2B9A846A216544E600A7418D /* String+heightForConstrainedWidth.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "String+heightForConstrainedWidth.swift"; sourceTree = "<group>"; };
7ECA5718232FA42B00256BB9 /* FloatingNotificationBanner.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FloatingNotificationBanner.swift; sourceTree = "<group>"; };
8232558B1EB872AB006F95C3 /* NotificationBanner.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = NotificationBanner.framework; sourceTree = BUILT_PRODUCTS_DIR; };
8232559E1EB87313006F95C3 /* .gitkeep */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = .gitkeep; sourceTree = "<group>"; };
8232559F1EB87313006F95C3 /* BannerColors.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BannerColors.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -102,6 +104,7 @@
823255A41EB87313006F95C3 /* StatusBarNotificationBanner.swift */,
F7E13CF51FB192ED0008EE4C /* NotificationBannerUtilities.swift */,
2B9A8468216538CA00A7418D /* GrowingNotificationBanner.swift */,
7ECA5718232FA42B00256BB9 /* FloatingNotificationBanner.swift */,
2B9A846A216544E600A7418D /* String+heightForConstrainedWidth.swift */,
);
path = Classes;
Expand Down Expand Up @@ -219,6 +222,7 @@
823255B21EB87313006F95C3 /* NotificationBanner.swift in Sources */,
2B9A846B216544E600A7418D /* String+heightForConstrainedWidth.swift in Sources */,
0D0D9ADF1F15D19D003B35A8 /* BannerPositionFrame.swift in Sources */,
7ECA5719232FA42B00256BB9 /* FloatingNotificationBanner.swift in Sources */,
823255AF1EB87313006F95C3 /* BannerColors.swift in Sources */,
2B9A8469216538CA00A7418D /* GrowingNotificationBanner.swift in Sources */,
F7E13CF61FB192ED0008EE4C /* NotificationBannerUtilities.swift in Sources */,
Expand Down
14 changes: 12 additions & 2 deletions NotificationBanner/Classes/StatusBarNotificationBanner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,23 @@ open class StatusBarNotificationBanner: BaseNotificationBanner {
} else if shouldAdjustForNotchFeaturedIphone() {
return 50.0
} else {
return 20.0
return 20.0 + heightAdjustment
}
} set {
customBannerHeight = newValue
}
}

private var heightAdjustment: CGFloat {
// iOS 13 does not allow covering the status bar on non-notch iPhones
// The banner needs to be moved further down under the status bar in this case
guard #available(iOS 13.0, *), !NotificationBannerUtilities.isNotchFeaturedIPhone() else {
return 0
}

return UIApplication.shared.statusBarFrame.height
}

override init(style: BannerStyle, colors: BannerColorsProtocol? = nil) {
super.init(style: style, colors: colors)

Expand All @@ -49,7 +59,7 @@ open class StatusBarNotificationBanner: BaseNotificationBanner {
contentView.addSubview(titleLabel!)

titleLabel!.snp.makeConstraints { (make) in
make.top.equalToSuperview()
make.top.equalToSuperview().offset(heightAdjustment)
make.left.equalToSuperview().offset(5)
make.right.equalToSuperview().offset(-5)
make.bottom.equalToSuperview()
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ pod 'NotificationBannerSwift'

Then add `import NotificationBannerSwift` at the top of each file you use NotificationBanner in your project.

#### iOS13

```ruby
pod 'NotificationBannerSwift', :git => 'https://github.com/Daltron/NotificationBanner', :branch => 'ios13'
```

#### Swift 4.2

```ruby
Expand Down

0 comments on commit 07feb7e

Please sign in to comment.