From d3471bafe9f8a3ee5517e5c7d312d96694348eec Mon Sep 17 00:00:00 2001 From: Andrey Gluhih Date: Tue, 14 Jul 2020 14:33:37 +0300 Subject: [PATCH] Add ability to choose inset and visiablity for scroll view --- .../PanModalPresentationController.swift | 4 ++-- .../Presentable/PanModalPresentable+Defaults.swift | 8 ++++++++ PanModal/Presentable/PanModalPresentable.swift | 14 ++++++++++++++ .../User Groups/UserGroupViewController.swift | 1 - 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/PanModal/Controller/PanModalPresentationController.swift b/PanModal/Controller/PanModalPresentationController.swift index 885b3d07..b9d4b7d4 100644 --- a/PanModal/Controller/PanModalPresentationController.swift +++ b/PanModal/Controller/PanModalPresentationController.swift @@ -446,7 +446,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` @@ -771,7 +771,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..21193f90 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..6ecc5c2a 100644 --- a/PanModal/Presentable/PanModalPresentable.swift +++ b/PanModal/Presentable/PanModalPresentable.swift @@ -233,5 +233,19 @@ 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 true. + */ + var bottomScrollInset: CGFloat? { get } } #endif diff --git a/Sample/View Controllers/User Groups/UserGroupViewController.swift b/Sample/View Controllers/User Groups/UserGroupViewController.swift index e06ad5c5..0800116b 100644 --- a/Sample/View Controllers/User Groups/UserGroupViewController.swift +++ b/Sample/View Controllers/User Groups/UserGroupViewController.swift @@ -118,5 +118,4 @@ class UserGroupViewController: UITableViewController, PanModalPresentable { isShortFormEnabled = false panModalSetNeedsLayoutUpdate() } - }