ActionSheetController: added dismissed API

This commit is contained in:
Peter 2019-02-08 20:08:42 +04:00
parent 275fd01964
commit e065d5af3f
2 changed files with 10 additions and 7 deletions

View File

@ -17,6 +17,8 @@ open class ActionSheetController: ViewController {
private var isDismissed: Bool = false
public var dismissed: ((Bool) -> Void)?
public init(theme: ActionSheetControllerTheme) {
self.theme = theme
@ -30,7 +32,7 @@ open class ActionSheetController: ViewController {
public func dismissAnimated() {
if !self.isDismissed {
self.isDismissed = true
self.actionSheetNode.animateOut()
self.actionSheetNode.animateOut(cancelled: false)
}
}
@ -38,7 +40,8 @@ open class ActionSheetController: ViewController {
self.displayNode = ActionSheetControllerNode(theme: self.theme)
self.displayNodeDidLoad()
self.actionSheetNode.dismiss = { [weak self] in
self.actionSheetNode.dismiss = { [weak self] cancelled in
self?.dismissed?(cancelled)
self?.presentingViewController?.dismiss(animated: false)
}

View File

@ -28,7 +28,7 @@ final class ActionSheetControllerNode: ASDisplayNode, UIScrollViewDelegate {
private let scrollView: UIScrollView
var dismiss: () -> Void = { }
var dismiss: (Bool) -> Void = { _ in }
private var validLayout: ContainerViewLayout?
@ -127,7 +127,7 @@ final class ActionSheetControllerNode: ASDisplayNode, UIScrollViewDelegate {
})
}
func animateOut() {
func animateOut(cancelled: Bool) {
let tempDimView = UIView()
tempDimView.backgroundColor = self.theme.dimColor
tempDimView.frame = self.bounds.offsetBy(dx: 0.0, dy: -self.bounds.size.height)
@ -141,7 +141,7 @@ final class ActionSheetControllerNode: ASDisplayNode, UIScrollViewDelegate {
self.layer.animateBounds(from: self.bounds, to: self.bounds.offsetBy(dx: 0.0, dy: -self.bounds.size.height), duration: 0.35, timingFunction: kCAMediaTimingFunctionEaseOut, removeOnCompletion: false, completion: { [weak self, weak tempDimView] _ in
tempDimView?.removeFromSuperview()
self?.dismiss()
self?.dismiss(cancelled)
})
}
@ -152,7 +152,7 @@ final class ActionSheetControllerNode: ASDisplayNode, UIScrollViewDelegate {
@objc func dimNodeTap(_ recognizer: UITapGestureRecognizer) {
if case .ended = recognizer.state {
self.animateOut()
self.animateOut(cancelled: true)
}
}
@ -174,7 +174,7 @@ final class ActionSheetControllerNode: ASDisplayNode, UIScrollViewDelegate {
let additionalTopHeight = max(0.0, -contentOffset.y)
if additionalTopHeight >= 30.0 {
self.animateOut()
self.animateOut(cancelled: true)
}
}