@@ -50,7 +50,7 @@ class SPStorkPresentationController: UIPresentationController, UIGestureRecogniz
5050 private var snapshotViewTopConstraint : NSLayoutConstraint ?
5151 private var snapshotViewWidthConstraint : NSLayoutConstraint ?
5252 private var snapshotViewAspectRatioConstraint : NSLayoutConstraint ?
53-
53+
5454 var workConfirmation : Bool = false
5555 private var workGester : Bool = false
5656 private var startDismissing : Bool = false
@@ -107,7 +107,7 @@ class SPStorkPresentationController: UIPresentationController, UIGestureRecogniz
107107
108108 if self . showIndicator {
109109 self . indicatorView. color = self . indicatorColor
110- let tap = UITapGestureRecognizer . init ( target: self , action: #selector( self . dismissAction ) )
110+ let tap = UITapGestureRecognizer . init ( target: self , action: #selector( self . tapIndicator ) )
111111 tap. cancelsTouchesInView = false
112112 self . indicatorView. addGestureRecognizer ( tap)
113113 presentedView. addSubview ( self . indicatorView)
@@ -122,7 +122,7 @@ class SPStorkPresentationController: UIPresentationController, UIGestureRecogniz
122122 self . gradeView. alpha = 0
123123
124124 if self . showCloseButton {
125- self . closeButton. addTarget ( self , action: #selector( self . dismissAction ) , for: . touchUpInside)
125+ self . closeButton. addTarget ( self , action: #selector( self . tapCloseButton ) , for: . touchUpInside)
126126 presentedView. addSubview ( self . closeButton)
127127 }
128128 self . updateLayoutCloseButton ( )
@@ -209,7 +209,7 @@ class SPStorkPresentationController: UIPresentationController, UIGestureRecogniz
209209 self . updateSnapshotAspectRatio ( )
210210
211211 if self . tapAroundToDismissEnabled {
212- self . tap = UITapGestureRecognizer . init ( target: self , action: #selector( self . dismissAction ) )
212+ self . tap = UITapGestureRecognizer . init ( target: self , action: #selector( self . tapArround ) )
213213 self . tap? . cancelsTouchesInView = false
214214 self . snapshotViewContainer. addGestureRecognizer ( self . tap!)
215215 }
@@ -223,21 +223,13 @@ class SPStorkPresentationController: UIPresentationController, UIGestureRecogniz
223223 }
224224 }
225225
226- @objc func dismissAction( ) {
227- self . presentingViewController. view. endEditing ( true )
228- self . presentedViewController. view. endEditing ( true )
229- self . presentedViewController. dismiss ( animated: true , completion: {
230- self . storkDelegate? . didDismissStorkByTap ? ( )
231- } )
232- }
233-
234226 override func dismissalTransitionWillBegin( ) {
235227 super. dismissalTransitionWillBegin ( )
236228 guard let containerView = containerView else { return }
237229 self . startDismissing = true
238230
239231 let initialFrame : CGRect = presentingViewController. isPresentedAsStork ? presentingViewController. view. frame : containerView. bounds
240-
232+
241233 let initialTransform = CGAffineTransform . identity
242234 . translatedBy ( x: 0 , y: - initialFrame. origin. y)
243235 . translatedBy ( x: 0 , y: self . topSpace)
@@ -314,6 +306,56 @@ class SPStorkPresentationController: UIPresentationController, UIGestureRecogniz
314306
315307extension SPStorkPresentationController {
316308
309+ @objc func tapIndicator( ) {
310+ self . dismissWithConfirmation ( prepare: nil , completion: {
311+ self . storkDelegate? . didDismissStorkByTap ? ( )
312+ } )
313+ }
314+
315+ @objc func tapArround( ) {
316+ self . dismissWithConfirmation ( prepare: nil , completion: {
317+ self . storkDelegate? . didDismissStorkByTap ? ( )
318+ } )
319+ }
320+
321+ @objc func tapCloseButton( ) {
322+ self . dismissWithConfirmation ( prepare: nil , completion: {
323+ self . storkDelegate? . didDismissStorkByTap ? ( )
324+ } )
325+ }
326+
327+ public func dismissWithConfirmation( prepare: ( ( ) -> ( ) ) ? , completion: ( ( ) -> ( ) ) ? ) {
328+
329+ let dismiss = {
330+ self . presentingViewController. view. endEditing ( true )
331+ self . presentedViewController. view. endEditing ( true )
332+ self . presentedViewController. dismiss ( animated: true , completion: {
333+ completion ? ( )
334+ } )
335+ }
336+
337+ guard let confirmDelegate = self . confirmDelegate else {
338+ dismiss ( )
339+ return
340+ }
341+
342+ if self . workConfirmation { return }
343+
344+ if confirmDelegate. needConfirm {
345+ prepare ? ( )
346+ self . workConfirmation = true
347+ confirmDelegate. confirm ( { ( isConfirmed) in
348+ self . workConfirmation = false
349+ self . afterReleaseDismissing = false
350+ if isConfirmed {
351+ dismiss ( )
352+ }
353+ } )
354+ } else {
355+ dismiss ( )
356+ }
357+ }
358+
317359 @objc func handlePan( gestureRecognizer: UIPanGestureRecognizer ) {
318360 guard gestureRecognizer. isEqual ( self . pan) , self . swipeToDismissEnabled else { return }
319361
@@ -337,7 +379,7 @@ extension SPStorkPresentationController {
337379 self . workGester = false
338380 let translation = gestureRecognizer. translation ( in: presentedView) . y
339381
340- let returnToDefault = {
382+ let toDefault = {
341383 self . indicatorView. style = . arrow
342384 UIView . animate (
343385 withDuration: 0.6 ,
@@ -352,36 +394,12 @@ extension SPStorkPresentationController {
352394 } )
353395 }
354396
355- let dismissBySwipe = {
356- self . presentedViewController . dismiss ( animated : true , completion: {
397+ if translation >= self . translateForDismiss {
398+ self . dismissWithConfirmation ( prepare : toDefault , completion: {
357399 self . storkDelegate? . didDismissStorkBySwipe ? ( )
358400 } )
359- }
360-
361- if translation >= self . translateForDismiss {
362-
363- guard let confirmDelegate = self . confirmDelegate else {
364- dismissBySwipe ( )
365- return
366- }
367-
368- if self . workConfirmation { return }
369-
370- if confirmDelegate. needConfirm {
371- returnToDefault ( )
372- self . workConfirmation = true
373- confirmDelegate. confirm ( { ( isConfirmed) in
374- self . workConfirmation = false
375- self . afterReleaseDismissing = false
376- if isConfirmed {
377- dismissBySwipe ( )
378- }
379- } )
380- } else {
381- dismissBySwipe ( )
382- }
383401 } else {
384- returnToDefault ( )
402+ toDefault ( )
385403 }
386404 default :
387405 break
@@ -432,7 +450,7 @@ extension SPStorkPresentationController {
432450
433451 let elasticThreshold : CGFloat = 120
434452 let translationFactor : CGFloat = 1 / 2
435-
453+
436454 if translation >= 0 {
437455 let translationForModal : CGFloat = {
438456 if translation >= elasticThreshold {
0 commit comments