Skip to content

Commit ee5f9ee

Browse files
committed
Update to 1.7.4
Add `dismissWithConfirmation` method for custom buttons.
1 parent 8348cd6 commit ee5f9ee

7 files changed

Lines changed: 31 additions & 15 deletions

File tree

Example/stork-controller/Frameworks/SPStorkController/SPStorkController.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public enum SPStorkController {
3535
presentationController.setIndicator(style: scrollView.isTracking ? .line : .arrow)
3636
if translation >= presentationController.translateForDismiss * 0.4 {
3737
if !scrollView.isTracking && !scrollView.isDragging {
38-
presentationController.dismissWithConfirmation(prepare: nil, completion: {
38+
self.dismissWithConfirmation(controller: controller, completion: {
3939
presentationController.storkDelegate?.didDismissStorkBySwipe?()
4040
})
4141
return
@@ -58,6 +58,14 @@ public enum SPStorkController {
5858
}
5959
}
6060

61+
static public func dismissWithConfirmation(controller: UIViewController, completion: (()->())?) {
62+
if let controller = self.presentationController(for: controller) {
63+
controller.dismissWithConfirmation(prepare: nil, completion: {
64+
print("Custom completion for confirmation. Confirmation is optional.")
65+
})
66+
}
67+
}
68+
6169
static public var topScrollIndicatorInset: CGFloat {
6270
return 6
6371
}

Example/stork-controller/ModalTableViewController.swift

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,7 @@ class ModalTableViewController: UIViewController {
4949
}
5050

5151
@objc func dismissAction() {
52-
if let storkPresentationController = self.presentationController as? SPStorkPresentationController {
53-
storkPresentationController.dismissWithConfirmation(prepare: nil, completion: {
54-
print("Custom completion for confirmation. Confirmation is optional.")
55-
})
56-
}
52+
SPStorkController.dismissWithConfirmation(controller: self, completion: nil)
5753
}
5854
}
5955

Example/stork-controller/ModalViewController.swift

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,7 @@ class ModalViewController: UIViewController {
2020
}
2121

2222
@objc func dismissAction() {
23-
if let storkPresentationController = self.presentationController as? SPStorkPresentationController {
24-
storkPresentationController.dismissWithConfirmation(prepare: nil, completion: {
25-
print("Custom completion for confirmation. Confirmation is optional.")
26-
})
27-
}
23+
SPStorkController.dismissWithConfirmation(controller: self, completion: nil)
2824
}
2925

3026
override func viewWillAppear(_ animated: Bool) {

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ Please, also use `SPStorkController.scrollViewDidScroll` function in scroll dele
277277

278278
### Confirm
279279

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

282282
```swift
283283
@objc public protocol SPStorkControllerConfirmDelegate: class {
@@ -288,7 +288,15 @@ For confirm closing by swipe, use `SPStorkControllerConfirmDelegate`. Implenet p
288288
}
289289
```
290290

291-
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.
291+
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.
292+
293+
If you use custom buttons, in the target use this code:
294+
295+
```swift
296+
SPStorkController.dismissWithConfirmation(controller: self, completion: nil)
297+
```
298+
299+
It call `confirm` func and check result of confirmation. See example project for more details.
292300

293301
### Delegate
294302

SPStorkController.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Pod::Spec.new do |s|
22

33
s.name = "SPStorkController"
4-
s.version = "1.7.2"
4+
s.version = "1.7.4"
55
s.summary = "Very similar to the controllers displayed in Apple Music, Podcasts and Mail Apple's applications."
66
s.homepage = "https://github.com/IvanVorobei/SPStorkController"
77
s.source = { :git => "https://github.com/IvanVorobei/SPStorkController.git", :tag => s.version }

Source/SPStorkController/SPStorkController.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public enum SPStorkController {
3535
presentationController.setIndicator(style: scrollView.isTracking ? .line : .arrow)
3636
if translation >= presentationController.translateForDismiss * 0.4 {
3737
if !scrollView.isTracking && !scrollView.isDragging {
38-
presentationController.dismissWithConfirmation(prepare: nil, completion: {
38+
self.dismissWithConfirmation(controller: controller, completion: {
3939
presentationController.storkDelegate?.didDismissStorkBySwipe?()
4040
})
4141
return
@@ -58,6 +58,14 @@ public enum SPStorkController {
5858
}
5959
}
6060

61+
static public func dismissWithConfirmation(controller: UIViewController, completion: (()->())?) {
62+
if let controller = self.presentationController(for: controller) {
63+
controller.dismissWithConfirmation(prepare: nil, completion: {
64+
print("Custom completion for confirmation. Confirmation is optional.")
65+
})
66+
}
67+
}
68+
6169
static public var topScrollIndicatorInset: CGFloat {
6270
return 6
6371
}

0 commit comments

Comments
 (0)