Skip to content

Commit

Permalink
Update to 1.7.4
Browse files Browse the repository at this point in the history
Add `dismissWithConfirmation` method for custom buttons.
  • Loading branch information
ivanvorobei committed Jul 10, 2019
1 parent 8348cd6 commit ee5f9ee
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 15 deletions.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public enum SPStorkController {
presentationController.setIndicator(style: scrollView.isTracking ? .line : .arrow)
if translation >= presentationController.translateForDismiss * 0.4 {
if !scrollView.isTracking && !scrollView.isDragging {
presentationController.dismissWithConfirmation(prepare: nil, completion: {
self.dismissWithConfirmation(controller: controller, completion: {
presentationController.storkDelegate?.didDismissStorkBySwipe?()
})
return
Expand All @@ -58,6 +58,14 @@ public enum SPStorkController {
}
}

static public func dismissWithConfirmation(controller: UIViewController, completion: (()->())?) {
if let controller = self.presentationController(for: controller) {
controller.dismissWithConfirmation(prepare: nil, completion: {
print("Custom completion for confirmation. Confirmation is optional.")
})
}
}

static public var topScrollIndicatorInset: CGFloat {
return 6
}
Expand Down
6 changes: 1 addition & 5 deletions Example/stork-controller/ModalTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,7 @@ class ModalTableViewController: UIViewController {
}

@objc func dismissAction() {
if let storkPresentationController = self.presentationController as? SPStorkPresentationController {
storkPresentationController.dismissWithConfirmation(prepare: nil, completion: {
print("Custom completion for confirmation. Confirmation is optional.")
})
}
SPStorkController.dismissWithConfirmation(controller: self, completion: nil)
}
}

Expand Down
6 changes: 1 addition & 5 deletions Example/stork-controller/ModalViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@ class ModalViewController: UIViewController {
}

@objc func dismissAction() {
if let storkPresentationController = self.presentationController as? SPStorkPresentationController {
storkPresentationController.dismissWithConfirmation(prepare: nil, completion: {
print("Custom completion for confirmation. Confirmation is optional.")
})
}
SPStorkController.dismissWithConfirmation(controller: self, completion: nil)
}

override func viewWillAppear(_ animated: Bool) {
Expand Down
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ Please, also use `SPStorkController.scrollViewDidScroll` function in scroll dele

### Confirm

For confirm closing by swipe, use `SPStorkControllerConfirmDelegate`. Implenet protocol:
For confirm closing by swipe, tap around, close button and indicator use `SPStorkControllerConfirmDelegate`. Implenet protocol:

```swift
@objc public protocol SPStorkControllerConfirmDelegate: class {
Expand All @@ -288,7 +288,15 @@ For confirm closing by swipe, use `SPStorkControllerConfirmDelegate`. Implenet p
}
```

and set `confirmDelegate` property to object, which protocol impleneted. Function `confirm` call if `needConfirm` set to `true` and controller try closing by swipe. Pass `isConfirmed` with result. Best options use `UIAlertController` with `.actionSheet` style for confirmation.
and set `confirmDelegate` property to object, which protocol impleneted. Function `confirm` call if `needConfirm` return true. Pass `isConfirmed` with result. Best options use `UIAlertController` with `.actionSheet` style for confirmation.

If you use custom buttons, in the target use this code:

```swift
SPStorkController.dismissWithConfirmation(controller: self, completion: nil)
```

It call `confirm` func and check result of confirmation. See example project for more details.

### Delegate

Expand Down
2 changes: 1 addition & 1 deletion SPStorkController.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = "SPStorkController"
s.version = "1.7.2"
s.version = "1.7.4"
s.summary = "Very similar to the controllers displayed in Apple Music, Podcasts and Mail Apple's applications."
s.homepage = "https://github.com/IvanVorobei/SPStorkController"
s.source = { :git => "https://github.com/IvanVorobei/SPStorkController.git", :tag => s.version }
Expand Down
10 changes: 9 additions & 1 deletion Source/SPStorkController/SPStorkController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public enum SPStorkController {
presentationController.setIndicator(style: scrollView.isTracking ? .line : .arrow)
if translation >= presentationController.translateForDismiss * 0.4 {
if !scrollView.isTracking && !scrollView.isDragging {
presentationController.dismissWithConfirmation(prepare: nil, completion: {
self.dismissWithConfirmation(controller: controller, completion: {
presentationController.storkDelegate?.didDismissStorkBySwipe?()
})
return
Expand All @@ -58,6 +58,14 @@ public enum SPStorkController {
}
}

static public func dismissWithConfirmation(controller: UIViewController, completion: (()->())?) {
if let controller = self.presentationController(for: controller) {
controller.dismissWithConfirmation(prepare: nil, completion: {
print("Custom completion for confirmation. Confirmation is optional.")
})
}
}

static public var topScrollIndicatorInset: CGFloat {
return 6
}
Expand Down

0 comments on commit ee5f9ee

Please sign in to comment.