Skip to content

Commit

Permalink
Merge pull request #8 from soramitsu/feature/modallDismissable
Browse files Browse the repository at this point in the history
update ModalSheetPresentationController
  • Loading branch information
ifoatov authored Sep 16, 2020
2 parents 0855c56 + eccad71 commit f9e772b
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 30 deletions.
48 changes: 24 additions & 24 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
PODS:
- SoraUI (1.9.0):
- SoraUI/AdaptiveDesign (= 1.9.0)
- SoraUI/Animator (= 1.9.0)
- SoraUI/Camera (= 1.9.0)
- SoraUI/Controls (= 1.9.0)
- SoraUI/DetailsView (= 1.9.0)
- SoraUI/EmptyState (= 1.9.0)
- SoraUI/LoadingView (= 1.9.0)
- SoraUI/ModalPresentation (= 1.9.0)
- SoraUI/PageLoader (= 1.9.0)
- SoraUI/PinView (= 1.9.0)
- SoraUI/Skrull (= 1.9.0)
- SoraUI/AdaptiveDesign (1.9.0)
- SoraUI/Animator (1.9.0)
- SoraUI/Camera (1.9.0)
- SoraUI/Controls (1.9.0)
- SoraUI/DetailsView (1.9.0):
- SoraUI (1.9.1):
- SoraUI/AdaptiveDesign (= 1.9.1)
- SoraUI/Animator (= 1.9.1)
- SoraUI/Camera (= 1.9.1)
- SoraUI/Controls (= 1.9.1)
- SoraUI/DetailsView (= 1.9.1)
- SoraUI/EmptyState (= 1.9.1)
- SoraUI/LoadingView (= 1.9.1)
- SoraUI/ModalPresentation (= 1.9.1)
- SoraUI/PageLoader (= 1.9.1)
- SoraUI/PinView (= 1.9.1)
- SoraUI/Skrull (= 1.9.1)
- SoraUI/AdaptiveDesign (1.9.1)
- SoraUI/Animator (1.9.1)
- SoraUI/Camera (1.9.1)
- SoraUI/Controls (1.9.1)
- SoraUI/DetailsView (1.9.1):
- SoraUI/Controls
- SoraUI/EmptyState (1.9.0):
- SoraUI/EmptyState (1.9.1):
- SoraUI/Animator
- SoraUI/LoadingView (1.9.0):
- SoraUI/LoadingView (1.9.1):
- SoraUI/Controls
- SoraUI/ModalPresentation (1.9.0):
- SoraUI/ModalPresentation (1.9.1):
- SoraUI/Animator
- SoraUI/Controls
- SoraUI/PageLoader (1.9.0)
- SoraUI/PinView (1.9.0):
- SoraUI/PageLoader (1.9.1)
- SoraUI/PinView (1.9.1):
- SoraUI/Controls
- SoraUI/Skrull (1.9.0)
- SoraUI/Skrull (1.9.1)

DEPENDENCIES:
- SoraUI (from `../`)
Expand All @@ -37,7 +37,7 @@ EXTERNAL SOURCES:
:path: "../"

SPEC CHECKSUMS:
SoraUI: 9dc8789ef397640bc6d1de021476e8fdce503671
SoraUI: 57c166bce5a249727343a1e28d6148284f631afc

PODFILE CHECKSUM: bb766dae3a5ddd7acf3a123997936163f86b09c0

Expand Down
2 changes: 1 addition & 1 deletion SoraUI.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'SoraUI'
s.version = '1.9.0'
s.version = '1.9.1'
s.summary = 'UI Library for design and layout process simplification.'

s.description = 'Library contains views and controls that simplifies design and layout implementation manually in code or utilizing interface build.'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,20 @@ public protocol ModalPresenterDelegate: class {
func presenterDidHide(_ presenter: ModalPresenterProtocol)
}

public protocol ModalSheetPresenterDelegate: ModalPresenterDelegate {
func presenterCanDrag(_ presenter: ModalPresenterProtocol) -> Bool
}

public extension ModalPresenterDelegate {
func presenterShouldHide(_ presenter: ModalPresenterProtocol) -> Bool {
return true
}

func presenterDidHide(_ presenter: ModalPresenterProtocol) {}
}

public extension ModalSheetPresenterDelegate {
func presenterCanDrag(_ presenter: ModalPresenterProtocol) -> Bool {
return true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ class ModalSheetPresentationController: UIPresentationController {
(presentedView as? ModalPresenterDelegate) ??
(presentedViewController.view as? ModalPresenterDelegate)
}

var sheetPresenterDelegate: ModalSheetPresenterDelegate? {
return presenterDelegate as? ModalSheetPresenterDelegate
}

var inputView: ModalViewProtocol? {
(presentedViewController as? ModalViewProtocol) ??
Expand Down Expand Up @@ -132,11 +136,12 @@ class ModalSheetPresentationController: UIPresentationController {

let layoutFrame: CGRect
let bottomOffset: CGFloat

var maximumHeight = containerView.frame.size.height
if #available(iOS 11.0, *) {
if configuration.extendUnderSafeArea {
layoutFrame = containerView.bounds
bottomOffset = containerView.safeAreaInsets.bottom
maximumHeight -= containerView.safeAreaInsets.top
} else {
layoutFrame = containerView.safeAreaLayoutGuide.layoutFrame
bottomOffset = 0.0
Expand All @@ -145,15 +150,17 @@ class ModalSheetPresentationController: UIPresentationController {
layoutFrame = containerView.bounds
bottomOffset = 0.0
}

maximumHeight -= bottomOffset

let preferredSize = presentedViewController.preferredContentSize
let layoutWidth = preferredSize.width > 0.0 ? preferredSize.width : layoutFrame.width
let layoutHeight = preferredSize.height > 0.0 ? preferredSize.height + bottomOffset : layoutFrame.height
let height = min(layoutHeight, maximumHeight)

return CGRect(x: layoutFrame.minX,
y: layoutFrame.maxY - layoutHeight,
y: layoutFrame.maxY - height,
width: layoutWidth,
height: layoutHeight)
height: height)
}

// MARK: Animation
Expand Down Expand Up @@ -202,7 +209,9 @@ class ModalSheetPresentationController: UIPresentationController {

switch panGestureRecognizer.state {
case .began, .changed:

if sheetPresenterDelegate?.presenterCanDrag(self) == false {
return
}
if let interactiveDismissal = interactiveDismissal {
let progress = min(1.0, max(0.0, (translation.y - initialTranslation.y) / max(1.0, view.bounds.size.height)))

Expand Down

0 comments on commit f9e772b

Please sign in to comment.