From 57f45813220c19f0b545384dab785a2442aa52d7 Mon Sep 17 00:00:00 2001 From: Keith Lamprecht <1894492+Nixon506E@users.noreply.github.com> Date: Mon, 22 Jul 2019 15:34:01 -0400 Subject: [PATCH 01/10] Designate new drawer position on transition Don't default to collapsed state when current drawer position isn't supported --- PulleyLib/PulleyViewController.swift | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/PulleyLib/PulleyViewController.swift b/PulleyLib/PulleyViewController.swift index 7d60436..2277520 100644 --- a/PulleyLib/PulleyViewController.swift +++ b/PulleyLib/PulleyViewController.swift @@ -1309,7 +1309,7 @@ open class PulleyViewController: UIViewController, PulleyDrawerViewControllerDel - parameter animated: Whether or not to animate the change. - parameter completion: A block object to be executed when the animation sequence ends. The Bool indicates whether or not the animations actually finished before the completion handler was called. */ - public func setDrawerContentViewController(controller: UIViewController, animated: Bool = true, completion: PulleyAnimationCompletionBlock?) + public func setDrawerContentViewController(controller: UIViewController, animated: Bool = true, toPosition: PulleyPosition? = nil, completion: PulleyAnimationCompletionBlock?) { // Account for transition issue in iOS 11 controller.view.frame = drawerContentContainer.bounds @@ -1320,17 +1320,25 @@ open class PulleyViewController: UIViewController, PulleyDrawerViewControllerDel UIView.transition(with: drawerContentContainer, duration: 0.5, options: .transitionCrossDissolve, animations: { [weak self] () -> Void in self?.drawerContentViewController = controller - self?.setDrawerPosition(position: self?.drawerPosition ?? .collapsed, animated: false) - }, completion: { (completed) in - - completion?(completed) + if let toPosition = toPosition { + self?.setDrawerPosition(position: toPosition, animated: false) + } else { + self?.setDrawerPosition(position: self?.drawerPosition ?? .collapsed, animated: false) + } + }, completion: { (completed) in + completion?(completed) }) } else { drawerContentViewController = controller - setDrawerPosition(position: drawerPosition, animated: false) + + if let toPosition = toPosition { + setDrawerPosition(position: toPosition, animated: false) + } else { + setDrawerPosition(position: drawerPosition, animated: false) + } completion?(true) } From 2aa87e2a40ad42b77da22e0e383cfbe6e9454703 Mon Sep 17 00:00:00 2001 From: Keith Lamprecht <1894492+Nixon506E@users.noreply.github.com> Date: Wed, 18 Sep 2019 10:44:46 -0400 Subject: [PATCH 02/10] Add UITableView Scroll Delegate --- PulleyLib/PulleyPassthroughTableView.swift | 30 ++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 PulleyLib/PulleyPassthroughTableView.swift diff --git a/PulleyLib/PulleyPassthroughTableView.swift b/PulleyLib/PulleyPassthroughTableView.swift new file mode 100644 index 0000000..91cc253 --- /dev/null +++ b/PulleyLib/PulleyPassthroughTableView.swift @@ -0,0 +1,30 @@ +// +// PulleyPassthroughTableView.swift +// Pulley +// +// Created by Keith Lamprecht on 9/18/19. +// +import UIKit + +protocol PulleyPassthroughTableViewDelegate: class { + + func shouldTouchPassthroughScrollView(scrollView: PulleyPassthroughTableView, point: CGPoint) -> Bool + func viewToReceiveTouch(scrollView: PulleyPassthroughTableView, point: CGPoint) -> UIView +} + +class PulleyPassthroughTableView: UITableView { + + weak var touchDelegate: PulleyPassthroughTableViewDelegate? + + override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? { + + if + let touchDelegate = touchDelegate, + touchDelegate.shouldTouchPassthroughScrollView(scrollView: self, point: point) + { + return touchDelegate.viewToReceiveTouch(scrollView: self, point: point).hitTest(touchDelegate.viewToReceiveTouch(scrollView: self, point: point).convert(point, from: self), with: event) + } + + return super.hitTest(point, with: event) + } +} From 33607f5f8c00cb09ad476c25b9658a0a0bd93766 Mon Sep 17 00:00:00 2001 From: Keith Lamprecht <1894492+Nixon506E@users.noreply.github.com> Date: Wed, 18 Sep 2019 10:55:20 -0400 Subject: [PATCH 03/10] Delete PulleyPassthroughTableView.swift --- PulleyLib/PulleyPassthroughTableView.swift | 30 ---------------------- 1 file changed, 30 deletions(-) delete mode 100644 PulleyLib/PulleyPassthroughTableView.swift diff --git a/PulleyLib/PulleyPassthroughTableView.swift b/PulleyLib/PulleyPassthroughTableView.swift deleted file mode 100644 index 91cc253..0000000 --- a/PulleyLib/PulleyPassthroughTableView.swift +++ /dev/null @@ -1,30 +0,0 @@ -// -// PulleyPassthroughTableView.swift -// Pulley -// -// Created by Keith Lamprecht on 9/18/19. -// -import UIKit - -protocol PulleyPassthroughTableViewDelegate: class { - - func shouldTouchPassthroughScrollView(scrollView: PulleyPassthroughTableView, point: CGPoint) -> Bool - func viewToReceiveTouch(scrollView: PulleyPassthroughTableView, point: CGPoint) -> UIView -} - -class PulleyPassthroughTableView: UITableView { - - weak var touchDelegate: PulleyPassthroughTableViewDelegate? - - override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? { - - if - let touchDelegate = touchDelegate, - touchDelegate.shouldTouchPassthroughScrollView(scrollView: self, point: point) - { - return touchDelegate.viewToReceiveTouch(scrollView: self, point: point).hitTest(touchDelegate.viewToReceiveTouch(scrollView: self, point: point).convert(point, from: self), with: event) - } - - return super.hitTest(point, with: event) - } -} From 48ae91699966dc9153d7a9fb764e2474dd2bb6ad Mon Sep 17 00:00:00 2001 From: Keith Lamprecht <1894492+Nixon506E@users.noreply.github.com> Date: Mon, 23 Sep 2019 10:10:30 -0400 Subject: [PATCH 04/10] Remove Supported Positions Change Animation --- PulleyLib/PulleyViewController.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PulleyLib/PulleyViewController.swift b/PulleyLib/PulleyViewController.swift index 2277520..cd9bacf 100644 --- a/PulleyLib/PulleyViewController.swift +++ b/PulleyLib/PulleyViewController.swift @@ -569,7 +569,7 @@ open class PulleyViewController: UIViewController, PulleyDrawerViewControllerDel if supportedPositions.contains(drawerPosition) { - setDrawerPosition(position: drawerPosition, animated: true) + setDrawerPosition(position: drawerPosition, animated: false) } else { From b26233ed8e844f0a193e1e2eafc2e5e5b214a56e Mon Sep 17 00:00:00 2001 From: ulmentflam Date: Wed, 30 Sep 2020 19:03:41 -0400 Subject: [PATCH 05/10] Making adjustments to the pr by Nixon506E to support backwards compatability and create an example --- Pulley/Main.storyboard | 137 ++++++++++++++++++ ...rimaryTransitionTargetViewController.swift | 9 ++ PulleyLib/PulleyViewController.swift | 35 +++-- 3 files changed, 166 insertions(+), 15 deletions(-) diff --git a/Pulley/Main.storyboard b/Pulley/Main.storyboard index 2aa327c..c2fc0d1 100644 --- a/Pulley/Main.storyboard +++ b/Pulley/Main.storyboard @@ -311,8 +311,145 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pulley/PrimaryTransitionTargetViewController.swift b/Pulley/PrimaryTransitionTargetViewController.swift index 832d918..332dc92 100644 --- a/Pulley/PrimaryTransitionTargetViewController.swift +++ b/Pulley/PrimaryTransitionTargetViewController.swift @@ -12,8 +12,17 @@ import Pulley class PrimaryTransitionTargetViewController: UIViewController { @IBAction func goBackButtonPressed(sender: AnyObject) { + // Uncomment the bellow code to create a secondary drawer content view controller + // and set it's initial position with setDrawerContentViewController(controller, position, animated, completion) + /* + let drawerContent = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "SecondaryDrawerContentViewController") + + self.pulleyViewController?.setDrawerContentViewController(controller: drawerContent, position: .open, animated: true, completion: nil) + */ + let primaryContent = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "PrimaryContentViewController") self.pulleyViewController?.setPrimaryContentViewController(controller: primaryContent, animated: true) + } } diff --git a/PulleyLib/PulleyViewController.swift b/PulleyLib/PulleyViewController.swift index da2ca7f..5d08fb5 100644 --- a/PulleyLib/PulleyViewController.swift +++ b/PulleyLib/PulleyViewController.swift @@ -595,7 +595,7 @@ open class PulleyViewController: UIViewController, PulleyDrawerViewControllerDel if supportedPositions.contains(drawerPosition) { - setDrawerPosition(position: drawerPosition, animated: false) + setDrawerPosition(position: drawerPosition, animated: true) } else { @@ -1336,10 +1336,11 @@ open class PulleyViewController: UIViewController, PulleyDrawerViewControllerDel Change the current drawer content view controller (The one inside the drawer) - parameter controller: The controller to replace it with + - parameter position: The initial position of the contoller - parameter animated: Whether or not to animate the change. - parameter completion: A block object to be executed when the animation sequence ends. The Bool indicates whether or not the animations actually finished before the completion handler was called. */ - public func setDrawerContentViewController(controller: UIViewController, animated: Bool = true, toPosition: PulleyPosition? = nil, completion: PulleyAnimationCompletionBlock?) + public func setDrawerContentViewController(controller: UIViewController, position: PulleyPosition? = nil, animated: Bool = true, completion: PulleyAnimationCompletionBlock?) { // Account for transition issue in iOS 11 controller.view.frame = drawerContentContainer.bounds @@ -1350,12 +1351,7 @@ open class PulleyViewController: UIViewController, PulleyDrawerViewControllerDel UIView.transition(with: drawerContentContainer, duration: 0.5, options: .transitionCrossDissolve, animations: { [weak self] () -> Void in self?.drawerContentViewController = controller - - if let toPosition = toPosition { - self?.setDrawerPosition(position: toPosition, animated: false) - } else { - self?.setDrawerPosition(position: self?.drawerPosition ?? .collapsed, animated: false) - } + self?.setDrawerPosition(position: position ?? (self?.drawerPosition ?? .collapsed), animated: false) }, completion: { (completed) in completion?(completed) }) @@ -1364,16 +1360,25 @@ open class PulleyViewController: UIViewController, PulleyDrawerViewControllerDel { drawerContentViewController = controller - if let toPosition = toPosition { - setDrawerPosition(position: toPosition, animated: false) - } else { - setDrawerPosition(position: drawerPosition, animated: false) - } - + setDrawerPosition(position: position ?? drawerPosition, animated: false) completion?(true) } } + /** + Change the current drawer content view controller (The one inside the drawer). This method exists for backwards compatibility. + + - parameter controller: The controller to replace it with + - parameter animated: Whether or not to animate the change. + - parameter completion: A block object to be executed when the animation sequence ends. The Bool indicates whether or not the animations actually finished before the completion handler was called. + */ + + public func setDrawerContentViewController(controller: UIViewController, animated: Bool = true, completion: PulleyAnimationCompletionBlock?) + { + setDrawerContentViewController(controller: controller, position: nil, animated: animated, completion: completion) + + } + /** Change the current drawer content view controller (The one inside the drawer). This method exists for backwards compatibility. @@ -1382,7 +1387,7 @@ open class PulleyViewController: UIViewController, PulleyDrawerViewControllerDel */ public func setDrawerContentViewController(controller: UIViewController, animated: Bool = true) { - setDrawerContentViewController(controller: controller, animated: animated, completion: nil) + setDrawerContentViewController(controller: controller, position: nil, animated: animated, completion: nil) } /** From 2512ddd19ad8fef06c113974b8744de191d593db Mon Sep 17 00:00:00 2001 From: ulmentflam Date: Thu, 8 Oct 2020 22:37:04 -0400 Subject: [PATCH 06/10] Adding .compact mode for iPhone SE size class devices --- Pulley/DrawerContentViewController.swift | 2 +- PulleyLib/PulleyViewController.swift | 106 +++++++++++++++++++---- 2 files changed, 91 insertions(+), 17 deletions(-) diff --git a/Pulley/DrawerContentViewController.swift b/Pulley/DrawerContentViewController.swift index a001ce2..2604071 100755 --- a/Pulley/DrawerContentViewController.swift +++ b/Pulley/DrawerContentViewController.swift @@ -142,7 +142,7 @@ extension DrawerContentViewController: PulleyDrawerViewControllerDelegate { func drawerDisplayModeDidChange(drawer: PulleyViewController) { print("Drawer: \(drawer.currentDisplayMode)") - gripperTopConstraint.isActive = drawer.currentDisplayMode == .drawer + gripperTopConstraint.isActive = (drawer.currentDisplayMode == .drawer || drawer.currentDisplayMode == .compact) } } diff --git a/PulleyLib/PulleyViewController.swift b/PulleyLib/PulleyViewController.swift index 13ba833..b7f15ca 100644 --- a/PulleyLib/PulleyViewController.swift +++ b/PulleyLib/PulleyViewController.swift @@ -160,10 +160,12 @@ public typealias PulleyAnimationCompletionBlock = ((_ finished: Bool) -> Void) /// /// - panel: Show as a floating panel (replaces: leftSide) /// - drawer: Show as a bottom drawer (replaces: bottomDrawer) +/// - compact: Show as a compacted bottom drawer (support for iPhone SE size class) /// - automatic: Determine it based on device / orientation / size class (like Maps.app) public enum PulleyDisplayMode { case panel case drawer + case compact case automatic } @@ -181,6 +183,14 @@ public enum PulleyPanelCornerPlacement { case bottomRight } +/// Represents the positioning of the drawer when the `displayMode` is set to either `PulleyDisplayMode.panel` or `PulleyDisplayMode.automatic`. +/// - bottomLeft: The drawer will placed in the bottom left corner +/// - bottomRight: The drawer will placed in the bottom right corner +public enum PulleyCompactCornerPlacement { + case bottomLeft + case bottomRight +} + /// Represents the 'snap' mode for Pulley. The default is 'nearest position'. You can use 'nearestPositionUnlessExceeded' to make the drawer feel lighter or heavier. /// /// - nearestPosition: Snap to the nearest position when scroll stops @@ -370,6 +380,26 @@ open class PulleyViewController: UIViewController, PulleyDrawerViewControllerDel } } + /// Depending on what corner placement is being used, different values from this struct will apply. For example, 'bottomRight' corner placement will utilize the .top, .right, and .bottom inset properties and it will ignore the .left property (use compactWidth property to specify width) + @IBInspectable public var compactInsets: UIEdgeInsets = UIEdgeInsets(top: 8.0, left: 8.0, bottom: 10.0, right: 8.0) { + didSet { + if oldValue != compactInsets, self.isViewLoaded + { + self.view.setNeedsLayout() + } + } + } + + /// The width of the drawer in compact displayMode + @IBInspectable public var compactWidth: CGFloat = 292.0 { + didSet { + if oldValue != compactWidth, self.isViewLoaded + { + self.view.setNeedsLayout() + } + } + } + /// The corner radius for the drawer. /// Note: This property is ignored if your drawerContentViewController's view.layer.mask has a custom mask applied using a CAShapeLayer. /// Note: Custom CAShapeLayer as your drawerContentViewController's view.layer mask will override Pulley's internal corner rounding and use that mask as the drawer mask. @@ -482,7 +512,7 @@ open class PulleyViewController: UIViewController, PulleyDrawerViewControllerDel } } - /// The Y positioning for Pulley. This property is only oberserved when `displayMode` is set to `.automatic` or `bottom`. Default value is `.topLeft`. + /// The Y positioning for Pulley. This property is only oberserved when `displayMode` is set to `.automatic` or `.pannel`. Default value is `.topLeft`. public var panelCornerPlacement: PulleyPanelCornerPlacement = .topLeft { didSet { if self.isViewLoaded @@ -491,6 +521,17 @@ open class PulleyViewController: UIViewController, PulleyDrawerViewControllerDel } } } + + /// The Y positioning for Pulley. This property is only oberserved when `displayMode` is set to `.automatic` or `.compact`. Default value is `.bottomLeft`. + public var compactCornerPlacement: PulleyCompactCornerPlacement = .bottomLeft { + didSet { + if self.isViewLoaded + { + self.view.setNeedsLayout() + } + } + } + /// This is here exclusively to support IBInspectable in Interface Builder because Interface Builder can't deal with enums. If you're doing this in code use the -initialDrawerPosition property instead. Available strings are: open, closed, partiallyRevealed, collapsed @IBInspectable public var initialDrawerPositionFromIB: String? { @@ -841,9 +882,16 @@ open class PulleyViewController: UIViewController, PulleyDrawerViewControllerDel let safeAreaBottomInset = pulleySafeAreaInsets.bottom let safeAreaLeftInset = pulleySafeAreaInsets.left let safeAreaRightInset = pulleySafeAreaInsets.right - - let displayModeForCurrentLayout: PulleyDisplayMode = displayMode != .automatic ? displayMode : ((self.view.bounds.width >= 600.0 || self.traitCollection.horizontalSizeClass == .regular) ? .panel : .drawer) + var automaticDisplayMode: PulleyDisplayMode = .drawer + if (self.view.bounds.width >= 600.0 && self.traitCollection.horizontalSizeClass == .compact) { + automaticDisplayMode = .compact + } + if (self.view.bounds.width >= 600.0 && self.traitCollection.horizontalSizeClass == .regular) { + automaticDisplayMode = .panel + } + + let displayModeForCurrentLayout: PulleyDisplayMode = displayMode != .automatic ? displayMode : automaticDisplayMode currentDisplayMode = displayModeForCurrentLayout @@ -928,35 +976,61 @@ open class PulleyViewController: UIViewController, PulleyDrawerViewControllerDel partialRevealHeight = drawerVCCompliant.partialRevealDrawerHeight?(bottomSafeArea: safeAreaBottomInset) ?? kPulleyDefaultPartialRevealHeight } - let lowestStop = [(self.view.bounds.size.height - panelInsets.bottom - safeAreaTopInset), collapsedHeight, partialRevealHeight].min() ?? 0 - - let xOrigin = (panelCornerPlacement == .bottomLeft || panelCornerPlacement == .topLeft) ? (safeAreaLeftInset + panelInsets.left) : (self.view.bounds.maxX - (safeAreaRightInset + panelInsets.right) - panelWidth) + var lowestStop: CGFloat = 0 + var xOrigin: CGFloat = 0 + var yOrigin: CGFloat = 0 + let width = displayModeForCurrentLayout == .compact ? compactWidth : panelWidth - let yOrigin = (panelCornerPlacement == .bottomLeft || panelCornerPlacement == .bottomRight) ? (panelInsets.top + safeAreaTopInset) : (panelInsets.top + safeAreaTopInset + bounceOverflowMargin) + if (displayModeForCurrentLayout == .compact) + { + lowestStop = [(self.view.bounds.size.height - compactInsets.bottom - safeAreaTopInset), collapsedHeight, partialRevealHeight].min() ?? 0 + xOrigin = (compactCornerPlacement == .bottomLeft) ? (safeAreaLeftInset + compactInsets.left) : (self.view.bounds.maxX - (safeAreaRightInset + compactInsets.right) - compactWidth) + + yOrigin = (compactInsets.top + safeAreaTopInset) + } + else + { + lowestStop = [(self.view.bounds.size.height - panelInsets.bottom - safeAreaTopInset), collapsedHeight, partialRevealHeight].min() ?? 0 + xOrigin = (panelCornerPlacement == .bottomLeft || panelCornerPlacement == .topLeft) ? (safeAreaLeftInset + panelInsets.left) : (self.view.bounds.maxX - (safeAreaRightInset + panelInsets.right) - panelWidth) + + yOrigin = (panelCornerPlacement == .bottomLeft || panelCornerPlacement == .bottomRight) ? (panelInsets.top + safeAreaTopInset) : (panelInsets.top + safeAreaTopInset + bounceOverflowMargin) + + } if supportedPositions.contains(.open) { // Layout scrollview - drawerScrollView.frame = CGRect(x: xOrigin, y: yOrigin, width: panelWidth, height: heightOfOpenDrawer) + drawerScrollView.frame = CGRect(x: xOrigin, y: yOrigin, width: width, height: heightOfOpenDrawer) } else { // Layout scrollview let adjustedTopInset: CGFloat = supportedPositions.contains(.partiallyRevealed) ? partialRevealHeight : collapsedHeight - drawerScrollView.frame = CGRect(x: xOrigin, y: yOrigin, width: panelWidth, height: adjustedTopInset) + drawerScrollView.frame = CGRect(x: xOrigin, y: yOrigin, width: width, height: adjustedTopInset) } syncDrawerContentViewSizeToMatchScrollPositionForSideDisplayMode() drawerScrollView.contentSize = CGSize(width: drawerScrollView.bounds.width, height: self.view.bounds.height + (self.view.bounds.height - lowestStop)) - switch panelCornerPlacement { - case .topLeft, .topRight: - drawerScrollView.transform = CGAffineTransform(scaleX: 1.0, y: -1.0) - case .bottomLeft, .bottomRight: - drawerScrollView.transform = CGAffineTransform(scaleX: 1.0, y: 1.0) + if (displayModeForCurrentLayout == .compact) + { + switch compactCornerPlacement { + case .bottomLeft, .bottomRight: + drawerScrollView.transform = CGAffineTransform(scaleX: 1.0, y: 1.0) + } } - + else + { + switch panelCornerPlacement { + case .topLeft, .topRight: + drawerScrollView.transform = CGAffineTransform(scaleX: 1.0, y: -1.0) + case .bottomLeft, .bottomRight: + drawerScrollView.transform = CGAffineTransform(scaleX: 1.0, y: 1.0) + } + + } + backgroundDimmingView.isHidden = true } @@ -1181,7 +1255,7 @@ open class PulleyViewController: UIViewController, PulleyDrawerViewControllerDel private func syncDrawerContentViewSizeToMatchScrollPositionForSideDisplayMode() { - guard currentDisplayMode == .panel else { + guard currentDisplayMode == .panel || currentDisplayMode == .compact else { return } From d9338bd4db1c696371af376139c5ef2b82748cda Mon Sep 17 00:00:00 2001 From: ulmentflam Date: Thu, 8 Oct 2020 23:54:31 -0400 Subject: [PATCH 07/10] Full support for iPhone SE .compact behavior, with a direct replica of the compact position for Apple Maps --- PulleyLib/PulleyViewController.swift | 29 +++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/PulleyLib/PulleyViewController.swift b/PulleyLib/PulleyViewController.swift index b7f15ca..4810895 100644 --- a/PulleyLib/PulleyViewController.swift +++ b/PulleyLib/PulleyViewController.swift @@ -90,6 +90,12 @@ public typealias PulleyAnimationCompletionBlock = ((_ finished: Bool) -> Void) .closed ] + public static let compact: [PulleyPosition] = [ + .collapsed, + .open, + .closed + ] + public let rawValue: Int public init(rawValue: Int) { @@ -641,7 +647,7 @@ open class PulleyViewController: UIViewController, PulleyDrawerViewControllerDel } guard supportedPositions.count > 0 else { - supportedPositions = PulleyPosition.all + supportedPositions = self.currentDisplayMode == .compact ? PulleyPosition.compact : PulleyPosition.all return } @@ -653,6 +659,10 @@ open class PulleyViewController: UIViewController, PulleyDrawerViewControllerDel { setDrawerPosition(position: drawerPosition, animated: true) } + else if (self.currentDisplayMode == .compact && drawerPosition == .partiallyRevealed && supportedPositions.contains(.open)) + { + setDrawerPosition(position: .open, animated: false) + } else { let lowestDrawerState: PulleyPosition = supportedPositions.filter({ $0 != .closed }).min { (pos1, pos2) -> Bool in @@ -675,6 +685,7 @@ open class PulleyViewController: UIViewController, PulleyDrawerViewControllerDel if self.isViewLoaded { self.view.setNeedsLayout() + self.setNeedsSupportedDrawerPositionsUpdate() } delegate?.drawerDisplayModeDidChange?(drawer: self) @@ -1208,8 +1219,8 @@ open class PulleyViewController: UIViewController, PulleyDrawerViewControllerDel return } - guard currentDisplayMode == .drawer else { - print("Pulley: Error: You can only bounce the drawer when it's in the .drawer display mode.") + guard currentDisplayMode == .drawer || currentDisplayMode == .compact else { + print("Pulley: Error: You can only bounce the drawer when it's in the .drawer or .compact display mode.") return } @@ -1482,11 +1493,15 @@ open class PulleyViewController: UIViewController, PulleyDrawerViewControllerDel { if let drawerVCCompliant = drawerContentViewController as? PulleyDrawerViewControllerDelegate { - supportedPositions = drawerVCCompliant.supportedDrawerPositions?() ?? PulleyPosition.all + if let setSupportedDrawerPositions = drawerVCCompliant.supportedDrawerPositions?() { + supportedPositions = self.currentDisplayMode == .compact ? setSupportedDrawerPositions.filter(PulleyPosition.compact.contains) : setSupportedDrawerPositions + } else { + supportedPositions = self.currentDisplayMode == .compact ? PulleyPosition.compact : PulleyPosition.all + } } else { - supportedPositions = PulleyPosition.all + supportedPositions = self.currentDisplayMode == .compact ? PulleyPosition.compact : PulleyPosition.all } } @@ -1566,9 +1581,9 @@ open class PulleyViewController: UIViewController, PulleyDrawerViewControllerDel open func supportedDrawerPositions() -> [PulleyPosition] { if let drawerVCCompliant = drawerContentViewController as? PulleyDrawerViewControllerDelegate, let supportedPositions = drawerVCCompliant.supportedDrawerPositions?() { - return supportedPositions + return (self.currentDisplayMode == .compact ? supportedPositions.filter(PulleyPosition.compact.contains) : supportedPositions) } else { - return PulleyPosition.all + return (self.currentDisplayMode == .compact ? PulleyPosition.compact : PulleyPosition.all) } } From d5747993228a19a4c0652fcca60805ddbebf5705 Mon Sep 17 00:00:00 2001 From: ulmentflam Date: Fri, 9 Oct 2020 00:15:32 -0400 Subject: [PATCH 08/10] Bumping Podspec version, thanks to https://github.com/52inc/Pulley/pull/347 for the motivation behind this feature --- Pulley.podspec | 2 +- README.md | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Pulley.podspec b/Pulley.podspec index cd4b92a..ce57a82 100644 --- a/Pulley.podspec +++ b/Pulley.podspec @@ -8,7 +8,7 @@ Pod::Spec.new do |s| s.name = 'Pulley' - s.version = ENV['LIB_VERSION'] || '2.8.5' + s.version = ENV['LIB_VERSION'] || '2.9.0' s.summary = 'A library to imitate the iOS 10 Maps UI.' # This description is used to generate tags and improve search results. diff --git a/README.md b/README.md index f531cc7..1a15cee 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,10 @@ A library to imitate the drawer in Maps for iOS 10/11. The master branch follows ### Update / Migration Info -**ATTENTION:** +**ATTENTION:** +Pulley 2.9.0 has new properties to support a new displayMode. The base functionality should work without any significant changes. The biggest change being the new displayMode of `.compact` to replicate Apple Maps Behavior on the iPhone SE size class devices. This is an exact replica of the behavior of the Apple Maps drawer, therefor when the `currentDisplayMode` of the `PulleyViewController` is `.compact` then the only `supportedDrawerPositions` for the view controller when in `.compact` mode are `.open`, `.closed`, and `.collapsed`. This mode also has new @IBInspectable properties, `compactInsets` and `compactWidth`. This mode behaves in a very similar way to `.panel` mode. See the pull request [here](https://github.com/52inc/Pulley/pull/347) for the motivation behind this feature. Also in this release, `setDrawerContentViewController(controller: UIViewController, position: PulleyPosition? = nil, animated: Bool = true, completion: PulleyAnimationCompletionBlock?)` has a new optional parameter `position` to set a new drawer position the drawer when a new `DrawerContentViewController` is set. See [this](https://github.com/52inc/Pulley/pull/349) pull request for the motivation behind this feature. + + Pulley 2.5.0 had significant renaming changes to support new features. Although property names have changed, the functionality should work without any significant changes (aside from renaming). See [this thread](https://github.com/52inc/Pulley/issues/252) for additional information. From 47ef7c8517030ef5e39650534c0abe81c2012875 Mon Sep 17 00:00:00 2001 From: ulmentflam Date: Fri, 9 Oct 2020 00:52:59 -0400 Subject: [PATCH 09/10] No need to bounce on .compact display mode, also fixing possiable backwards compatability issue. --- PulleyLib/PulleyViewController.swift | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/PulleyLib/PulleyViewController.swift b/PulleyLib/PulleyViewController.swift index 0c66c58..e7f198f 100644 --- a/PulleyLib/PulleyViewController.swift +++ b/PulleyLib/PulleyViewController.swift @@ -895,11 +895,13 @@ open class PulleyViewController: UIViewController, PulleyDrawerViewControllerDel let safeAreaRightInset = pulleySafeAreaInsets.right var automaticDisplayMode: PulleyDisplayMode = .drawer - if (self.view.bounds.width >= 600.0 && self.traitCollection.horizontalSizeClass == .compact) { - automaticDisplayMode = .compact - } - if (self.view.bounds.width >= 600.0 && self.traitCollection.horizontalSizeClass == .regular) { - automaticDisplayMode = .panel + if (self.view.bounds.width >= 600.0 ) { + switch self.traitCollection.horizontalSizeClass { + case .compact: + automaticDisplayMode = .compact + default: + automaticDisplayMode = .panel + } } let displayModeForCurrentLayout: PulleyDisplayMode = displayMode != .automatic ? displayMode : automaticDisplayMode @@ -1219,8 +1221,8 @@ open class PulleyViewController: UIViewController, PulleyDrawerViewControllerDel return } - guard currentDisplayMode == .drawer || currentDisplayMode == .compact else { - print("Pulley: Error: You can only bounce the drawer when it's in the .drawer or .compact display mode.") + guard currentDisplayMode == .drawer else { + print("Pulley: Error: You can only bounce the drawer when it's in the .drawer display mode.") return } From 203117ea4796a175a52744ddb01607093b735e01 Mon Sep 17 00:00:00 2001 From: ulmentflam Date: Fri, 9 Oct 2020 18:21:00 -0400 Subject: [PATCH 10/10] Making the height of the open drawer public --- PulleyLib/PulleyViewController.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PulleyLib/PulleyViewController.swift b/PulleyLib/PulleyViewController.swift index e7f198f..1b46995 100644 --- a/PulleyLib/PulleyViewController.swift +++ b/PulleyLib/PulleyViewController.swift @@ -700,7 +700,7 @@ open class PulleyViewController: UIViewController, PulleyDrawerViewControllerDel fileprivate var isChangingDrawerPosition: Bool = false /// The height of the open position for the drawer - private var heightOfOpenDrawer: CGFloat { + public var heightOfOpenDrawer: CGFloat { let safeAreaTopInset = pulleySafeAreaInsets.top let safeAreaBottomInset = pulleySafeAreaInsets.bottom