Skip to content

Commit 637ebb7

Browse files
Added NavigationController support
1 parent 8092856 commit 637ebb7

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

Sources/PillboxView/PillView.swift

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class PillView {
2121

2222
/// The height of the ``PillboxView/PillView/pillView``.
2323
///
24-
/// If a `UINavigationController` obstructs it, then add `45` to the `y` value when the ``PillboxView/PillView/pillView`` completes the animation sliding in. This will be addressed shortly in the future
24+
/// If a `UINavigationController` obstructs it, then set ``PillboxView/PillView/isNavigationControllerPresent`` to `true`
2525
public var height = 45
2626

2727
/// A `UIActivityIndicatorView` for the asynchronous task of the ``PillboxView/PillShowType/ongoingTask``.
@@ -73,6 +73,12 @@ public class PillView {
7373
/// This is set automatically, and cannot be changed. This could come handy when you would want to filter out a specific case from the ``PillboxView/PillView/activePillBoxViews``.
7474
public private(set) var showType: PillShowType? = nil
7575

76+
/// A Boolean value to allowing ``PillboxView/PillView`` to work around having a `UINavigationController` at the top of the screen.
77+
///
78+
/// The `UINavigationController` can block the top of the screen, thus obstructing the ``PillboxView/PillView/pillView``
79+
/// Set this to true to let the ``PillboxView/PillView/pillView`` ``PillboxView/PillView/reveal(animated:completionHandler:)`` 40 pixels higher (y-axis, lower down on the screen from the top).
80+
public var isNavigationControllerPresent = Bool()
81+
7682
/// The `Set` holds unique ``PillboxView/PillView`` shown on the screen at the given time.
7783
///
7884
/// When ``PillboxView/PillView`` exit the screen, they are removed from this `Set`. There are numerous use cases for this:
@@ -99,6 +105,14 @@ public class PillView {
99105
self.showType = showType
100106
}
101107

108+
/// Initialize this value overriding the ``PillboxView/PillView/isNavigationControllerPresent`` value
109+
/// - Parameter isNavigationControllerPresent: A Boolean value to allowing ``PillboxView/PillView`` to work around having a `UINavigationController` at the top of the screen.
110+
///
111+
/// The default value of this is false.
112+
public init(isNavigationControllerPresent: Bool) {
113+
self.isNavigationControllerPresent = isNavigationControllerPresent
114+
}
115+
102116
/// Initializes with different values than the default width and height values
103117
///
104118
/// - Parameters:
@@ -230,7 +244,7 @@ public class PillView {
230244
UIView.animate(withDuration: 1) {
231245

232246
self.pillView.frame = CGRect(x: Int(vcView.frame.midX),
233-
y: UIDevice.current.hasNotch ? 45: 25,
247+
y: UIDevice.current.hasNotch ? 45: 25 + (self.isNavigationControllerPresent ? 40 : 0),
234248
width: self.width, height: self.height)
235249

236250
self.pillView.center.x = vcView.center.x
@@ -292,7 +306,10 @@ public class PillView {
292306
pillView.addSubview(imageView)
293307

294308
UIView.animate(withDuration: 1) {
295-
self.pillView.frame = CGRect(x: 100, y: 45, width: self.width, height: self.height)
309+
self.pillView.frame = CGRect(x: 100,
310+
y: UIDevice.current.hasNotch ? 45: 25 + (self.isNavigationControllerPresent ? 40 : 0),
311+
width: self.width,
312+
height: self.height)
296313
self.pillView.center.x = vcView.center.x
297314
}
298315

Sources/PillboxView/VisualTransitions.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ extension PillView {
4545
DispatchQueue.main.asyncAfter(deadline: .now() + 1.5) {
4646
UIView.animate(withDuration: 1, delay: 0.25) {
4747
self.pillView.frame = CGRect(x: self.pillView.frame.minX,
48-
y: UIDevice.current.hasNotch ? 45: 25,
48+
y: UIDevice.current.hasNotch ? 45: 25 + (self.isNavigationControllerPresent ? 40 : 0),
4949
width: self.pillView.frame.width,
5050
height: self.pillView.frame.height)
5151

0 commit comments

Comments
 (0)