Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9f4c1be56d |
BIN
Binary file not shown.
@@ -39,6 +39,7 @@ class Controller: UIViewController {
|
||||
let modal = ModalTableViewController()
|
||||
let transitionDelegate = SPStorkTransitioningDelegate()
|
||||
transitionDelegate.storkDelegate = self
|
||||
transitionDelegate.confirmDelegate = modal
|
||||
modal.transitioningDelegate = transitionDelegate
|
||||
modal.modalPresentationStyle = .custom
|
||||
self.present(modal, animated: true, completion: nil)
|
||||
|
||||
+2
-2
@@ -23,7 +23,7 @@ import UIKit
|
||||
|
||||
@objc public protocol SPStorkControllerConfirmDelegate: class {
|
||||
|
||||
@objc optional var needConfirm: Bool { get }
|
||||
var needConfirm: Bool { get }
|
||||
|
||||
@objc optional func confirm(_ completion: @escaping (_ isConfirmed: Bool)->())
|
||||
func confirm(_ completion: @escaping (_ isConfirmed: Bool)->())
|
||||
}
|
||||
|
||||
@@ -32,16 +32,35 @@ public enum SPStorkController {
|
||||
scrollView.subviews.forEach {
|
||||
$0.transform = CGAffineTransform(translationX: 0, y: -translation)
|
||||
}
|
||||
/* Maybe migrate to it in future. Bug with bottom safe area
|
||||
scrollView.transform = CGAffineTransform(translationX: 0, y: -translation)
|
||||
scrollView.scrollIndicatorInsets.top = (indicatorInset ?? 0) + translation
|
||||
*/
|
||||
presentationController.setIndicator(style: scrollView.isTracking ? .line : .arrow)
|
||||
if translation >= presentationController.translateForDismiss * 0.4 {
|
||||
if !scrollView.isTracking && !scrollView.isDragging {
|
||||
presentationController.presentedViewController.dismiss(animated: true, completion: {
|
||||
presentationController.storkDelegate?.didDismissStorkBySwipe?()
|
||||
})
|
||||
|
||||
let dismiss = {
|
||||
presentationController.presentedViewController.dismiss(animated: true, completion: {
|
||||
presentationController.storkDelegate?.didDismissStorkBySwipe?()
|
||||
})
|
||||
}
|
||||
|
||||
guard let confirmDelegate = presentationController.confirmDelegate else {
|
||||
dismiss()
|
||||
return
|
||||
}
|
||||
|
||||
if presentationController.workConfirmation { return }
|
||||
|
||||
if confirmDelegate.needConfirm {
|
||||
presentationController.workConfirmation = true
|
||||
confirmDelegate.confirm({ (isConfirmed) in
|
||||
presentationController.workConfirmation = false
|
||||
if isConfirmed {
|
||||
dismiss()
|
||||
}
|
||||
})
|
||||
} else {
|
||||
dismiss()
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
+20
-8
@@ -50,7 +50,8 @@ class SPStorkPresentationController: UIPresentationController, UIGestureRecogniz
|
||||
private var snapshotViewTopConstraint: NSLayoutConstraint?
|
||||
private var snapshotViewWidthConstraint: NSLayoutConstraint?
|
||||
private var snapshotViewAspectRatioConstraint: NSLayoutConstraint?
|
||||
|
||||
|
||||
var workConfirmation: Bool = false
|
||||
private var workGester: Bool = false
|
||||
private var startDismissing: Bool = false
|
||||
private var afterReleaseDismissing: Bool = false
|
||||
@@ -69,7 +70,7 @@ class SPStorkPresentationController: UIPresentationController, UIGestureRecogniz
|
||||
return factor
|
||||
}
|
||||
|
||||
private var feedbackGenerator: UIImpactFeedbackGenerator = UIImpactFeedbackGenerator(style: .light)
|
||||
private var feedbackGenerator = UIImpactFeedbackGenerator(style: .light)
|
||||
|
||||
override var presentedView: UIView? {
|
||||
let view = self.presentedViewController.view
|
||||
@@ -358,9 +359,20 @@ extension SPStorkPresentationController {
|
||||
}
|
||||
|
||||
if translation >= self.translateForDismiss {
|
||||
if self.confirmDelegate?.needConfirm ?? false {
|
||||
|
||||
guard let confirmDelegate = self.confirmDelegate else {
|
||||
dismissBySwipe()
|
||||
return
|
||||
}
|
||||
|
||||
if self.workConfirmation { return }
|
||||
|
||||
if confirmDelegate.needConfirm {
|
||||
returnToDefault()
|
||||
self.confirmDelegate?.confirm?({ (isConfirmed) in
|
||||
self.workConfirmation = true
|
||||
confirmDelegate.confirm({ (isConfirmed) in
|
||||
self.workConfirmation = false
|
||||
self.afterReleaseDismissing = false
|
||||
if isConfirmed {
|
||||
dismissBySwipe()
|
||||
}
|
||||
@@ -446,8 +458,10 @@ extension SPStorkPresentationController {
|
||||
let afterRealseDismissing = (translation >= self.translateForDismiss)
|
||||
if afterRealseDismissing != self.afterReleaseDismissing {
|
||||
self.afterReleaseDismissing = afterRealseDismissing
|
||||
if self.hapticMoments.contains(.willDismissIfRelease) {
|
||||
self.feedbackGenerator.impactOccurred()
|
||||
if !self.workConfirmation {
|
||||
if self.hapticMoments.contains(.willDismissIfRelease) {
|
||||
self.feedbackGenerator.impactOccurred()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -479,8 +493,6 @@ extension SPStorkPresentationController {
|
||||
private func updateLayoutIndicator() {
|
||||
self.indicatorView.style = .line
|
||||
self.indicatorView.sizeToFit()
|
||||
//self.indicatorView.frame.origin.y = 12
|
||||
//self.indicatorView.center.x = presentedView.frame.width / 2
|
||||
}
|
||||
|
||||
private func updateLayoutCloseButton() {
|
||||
|
||||
@@ -79,3 +79,21 @@ extension ModalTableViewController: UITableViewDelegate {
|
||||
}
|
||||
}
|
||||
|
||||
extension ModalTableViewController: SPStorkControllerConfirmDelegate {
|
||||
|
||||
var needConfirm: Bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func confirm(_ completion: @escaping (Bool) -> ()) {
|
||||
print("confirm")
|
||||
let alertController = UIAlertController(title: "Need dismiss?", message: "It test confirm option for SPStorkController", preferredStyle: .actionSheet)
|
||||
alertController.addDestructiveAction(title: "Confirm", complection: {
|
||||
completion(true)
|
||||
})
|
||||
alertController.addCancelAction(title: "Cancel") {
|
||||
completion(false)
|
||||
}
|
||||
self.present(alertController)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ extension ModalViewController: SPStorkControllerConfirmDelegate {
|
||||
|
||||
func confirm(_ completion: @escaping (Bool) -> ()) {
|
||||
let alertController = UIAlertController(title: "Need dismiss?", message: "It test confirm option for SPStorkController", preferredStyle: .actionSheet)
|
||||
alertController.addAction(title: "Confirm", complection: {
|
||||
alertController.addDestructiveAction(title: "Confirm", complection: {
|
||||
completion(true)
|
||||
})
|
||||
alertController.addCancelAction(title: "Cancel") {
|
||||
|
||||
@@ -282,9 +282,9 @@ For confirm closing by swipe, use `SPStorkControllerConfirmDelegate`. Implenet p
|
||||
```swift
|
||||
@objc public protocol SPStorkControllerConfirmDelegate: class {
|
||||
|
||||
@objc optional var needConfirm: Bool { get }
|
||||
var needConfirm: Bool { get }
|
||||
|
||||
@objc optional func confirm(_ completion: @escaping (_ isConfirmed: Bool)->())
|
||||
func confirm(_ completion: @escaping (_ isConfirmed: Bool)->())
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
Pod::Spec.new do |s|
|
||||
|
||||
s.name = "SPStorkController"
|
||||
s.version = "1.7"
|
||||
s.version = "1.7.1"
|
||||
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 }
|
||||
|
||||
@@ -23,7 +23,7 @@ import UIKit
|
||||
|
||||
@objc public protocol SPStorkControllerConfirmDelegate: class {
|
||||
|
||||
@objc optional var needConfirm: Bool { get }
|
||||
var needConfirm: Bool { get }
|
||||
|
||||
@objc optional func confirm(_ completion: @escaping (_ isConfirmed: Bool)->())
|
||||
func confirm(_ completion: @escaping (_ isConfirmed: Bool)->())
|
||||
}
|
||||
|
||||
@@ -32,16 +32,35 @@ public enum SPStorkController {
|
||||
scrollView.subviews.forEach {
|
||||
$0.transform = CGAffineTransform(translationX: 0, y: -translation)
|
||||
}
|
||||
/* Maybe migrate to it in future. Bug with bottom safe area
|
||||
scrollView.transform = CGAffineTransform(translationX: 0, y: -translation)
|
||||
scrollView.scrollIndicatorInsets.top = (indicatorInset ?? 0) + translation
|
||||
*/
|
||||
presentationController.setIndicator(style: scrollView.isTracking ? .line : .arrow)
|
||||
if translation >= presentationController.translateForDismiss * 0.4 {
|
||||
if !scrollView.isTracking && !scrollView.isDragging {
|
||||
presentationController.presentedViewController.dismiss(animated: true, completion: {
|
||||
presentationController.storkDelegate?.didDismissStorkBySwipe?()
|
||||
})
|
||||
|
||||
let dismiss = {
|
||||
presentationController.presentedViewController.dismiss(animated: true, completion: {
|
||||
presentationController.storkDelegate?.didDismissStorkBySwipe?()
|
||||
})
|
||||
}
|
||||
|
||||
guard let confirmDelegate = presentationController.confirmDelegate else {
|
||||
dismiss()
|
||||
return
|
||||
}
|
||||
|
||||
if presentationController.workConfirmation { return }
|
||||
|
||||
if confirmDelegate.needConfirm {
|
||||
presentationController.workConfirmation = true
|
||||
confirmDelegate.confirm({ (isConfirmed) in
|
||||
presentationController.workConfirmation = false
|
||||
if isConfirmed {
|
||||
dismiss()
|
||||
}
|
||||
})
|
||||
} else {
|
||||
dismiss()
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,7 +50,8 @@ class SPStorkPresentationController: UIPresentationController, UIGestureRecogniz
|
||||
private var snapshotViewTopConstraint: NSLayoutConstraint?
|
||||
private var snapshotViewWidthConstraint: NSLayoutConstraint?
|
||||
private var snapshotViewAspectRatioConstraint: NSLayoutConstraint?
|
||||
|
||||
|
||||
var workConfirmation: Bool = false
|
||||
private var workGester: Bool = false
|
||||
private var startDismissing: Bool = false
|
||||
private var afterReleaseDismissing: Bool = false
|
||||
@@ -69,7 +70,7 @@ class SPStorkPresentationController: UIPresentationController, UIGestureRecogniz
|
||||
return factor
|
||||
}
|
||||
|
||||
private var feedbackGenerator: UIImpactFeedbackGenerator = UIImpactFeedbackGenerator(style: .light)
|
||||
private var feedbackGenerator = UIImpactFeedbackGenerator(style: .light)
|
||||
|
||||
override var presentedView: UIView? {
|
||||
let view = self.presentedViewController.view
|
||||
@@ -358,9 +359,20 @@ extension SPStorkPresentationController {
|
||||
}
|
||||
|
||||
if translation >= self.translateForDismiss {
|
||||
if self.confirmDelegate?.needConfirm ?? false {
|
||||
|
||||
guard let confirmDelegate = self.confirmDelegate else {
|
||||
dismissBySwipe()
|
||||
return
|
||||
}
|
||||
|
||||
if self.workConfirmation { return }
|
||||
|
||||
if confirmDelegate.needConfirm {
|
||||
returnToDefault()
|
||||
self.confirmDelegate?.confirm?({ (isConfirmed) in
|
||||
self.workConfirmation = true
|
||||
confirmDelegate.confirm({ (isConfirmed) in
|
||||
self.workConfirmation = false
|
||||
self.afterReleaseDismissing = false
|
||||
if isConfirmed {
|
||||
dismissBySwipe()
|
||||
}
|
||||
@@ -446,8 +458,10 @@ extension SPStorkPresentationController {
|
||||
let afterRealseDismissing = (translation >= self.translateForDismiss)
|
||||
if afterRealseDismissing != self.afterReleaseDismissing {
|
||||
self.afterReleaseDismissing = afterRealseDismissing
|
||||
if self.hapticMoments.contains(.willDismissIfRelease) {
|
||||
self.feedbackGenerator.impactOccurred()
|
||||
if !self.workConfirmation {
|
||||
if self.hapticMoments.contains(.willDismissIfRelease) {
|
||||
self.feedbackGenerator.impactOccurred()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -479,8 +493,6 @@ extension SPStorkPresentationController {
|
||||
private func updateLayoutIndicator() {
|
||||
self.indicatorView.style = .line
|
||||
self.indicatorView.sizeToFit()
|
||||
//self.indicatorView.frame.origin.y = 12
|
||||
//self.indicatorView.center.x = presentedView.frame.width / 2
|
||||
}
|
||||
|
||||
private func updateLayoutCloseButton() {
|
||||
|
||||
Reference in New Issue
Block a user