From f4ad70eff5a9824a4d66e3609d74cf16460cf68f Mon Sep 17 00:00:00 2001 From: Simonas Daniliauskas Date: Wed, 4 Nov 2020 21:06:26 +0200 Subject: [PATCH 1/2] add ability to choose inset and visibility for scroll view --- .../Controller/PanModalPresentationController.swift | 4 ++-- .../Presentable/PanModalPresentable+Defaults.swift | 8 ++++++++ PanModal/Presentable/PanModalPresentable.swift | 12 ++++++++++++ Tests/PanModalTests.swift | 2 ++ 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/PanModal/Controller/PanModalPresentationController.swift b/PanModal/Controller/PanModalPresentationController.swift index 11fb2a6e..89fc83df 100644 --- a/PanModal/Controller/PanModalPresentationController.swift +++ b/PanModal/Controller/PanModalPresentationController.swift @@ -454,7 +454,7 @@ private extension PanModalPresentationController { Set the appropriate contentInset as the configuration within this class offsets it */ - scrollView.contentInset.bottom = presentingViewController.bottomLayoutGuide.length + scrollView.contentInset.bottom = presentable?.bottomScrollInset ?? presentingViewController.bottomLayoutGuide.length /** As we adjust the bounds during `handleScrollViewTopBounce` @@ -769,7 +769,7 @@ private extension PanModalPresentationController { */ func trackScrolling(_ scrollView: UIScrollView) { scrollViewYOffset = max(scrollView.contentOffset.y, 0) - scrollView.showsVerticalScrollIndicator = true + scrollView.showsVerticalScrollIndicator = presentable?.shouldShowScrollIndicator ?? true } /** diff --git a/PanModal/Presentable/PanModalPresentable+Defaults.swift b/PanModal/Presentable/PanModalPresentable+Defaults.swift index 76a0679f..9d567dc1 100644 --- a/PanModal/Presentable/PanModalPresentable+Defaults.swift +++ b/PanModal/Presentable/PanModalPresentable+Defaults.swift @@ -124,5 +124,13 @@ public extension PanModalPresentable where Self: UIViewController { func panModalDidDismiss() { } + + var shouldShowScrollIndicator: Bool { + return true + } + + var bottomScrollInset: CGFloat? { + return nil + } } #endif diff --git a/PanModal/Presentable/PanModalPresentable.swift b/PanModal/Presentable/PanModalPresentable.swift index 76c15015..81ad828b 100644 --- a/PanModal/Presentable/PanModalPresentable.swift +++ b/PanModal/Presentable/PanModalPresentable.swift @@ -233,5 +233,17 @@ public protocol PanModalPresentable: AnyObject { Default value is an empty implementation. */ func panModalDidDismiss() + + /** + A flag to determine should we show scroll indicator in normal state for scroll view + Default value is true. + */ + var shouldShowScrollIndicator: Bool { get } + + /** + The inset for scroll view which will override default one (bottomLayoutGuide.height) + Default value is bottomLayoutGuide.length + */ + var bottomScrollInset: CGFloat? { get } } #endif diff --git a/Tests/PanModalTests.swift b/Tests/PanModalTests.swift index 7652b55f..89258a17 100644 --- a/Tests/PanModalTests.swift +++ b/Tests/PanModalTests.swift @@ -60,6 +60,8 @@ class PanModalTests: XCTestCase { XCTAssertEqual(vc.shouldRoundTopCorners, false) XCTAssertEqual(vc.showDragIndicator, false) XCTAssertEqual(vc.shouldRoundTopCorners, false) + XCTAssertEqual(vc.shouldShowScrollIndicator, true) + XCTAssertEqual(vc.bottomScrollInset, nil) XCTAssertEqual(vc.cornerRadius, 8.0) XCTAssertEqual(vc.transitionDuration, PanModalAnimator.Constants.defaultTransitionDuration) XCTAssertEqual(vc.transitionAnimationOptions, [.curveEaseInOut, .allowUserInteraction, .beginFromCurrentState]) From d47a2f39a8b079bdba8c8e7e4ff4cfb862586977 Mon Sep 17 00:00:00 2001 From: Simonas Daniliauskas Date: Wed, 4 Nov 2020 21:07:44 +0200 Subject: [PATCH 2/2] update default value --- PanModal/Presentable/PanModalPresentable.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PanModal/Presentable/PanModalPresentable.swift b/PanModal/Presentable/PanModalPresentable.swift index 81ad828b..513f4437 100644 --- a/PanModal/Presentable/PanModalPresentable.swift +++ b/PanModal/Presentable/PanModalPresentable.swift @@ -242,7 +242,7 @@ public protocol PanModalPresentable: AnyObject { /** The inset for scroll view which will override default one (bottomLayoutGuide.height) - Default value is bottomLayoutGuide.length + Default value is nil */ var bottomScrollInset: CGFloat? { get } }