swipe gesture / code reorg

pull/1/head
Michael Kirk 7 years ago
parent 41c1c2fcd5
commit 2606ac47f8

@ -170,13 +170,42 @@ class MessageActionsViewController: UIViewController, MessageActionSheetDelegate
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(didTapBackground)) let tapGesture = UITapGestureRecognizer(target: self, action: #selector(didTapBackground))
self.view.addGestureRecognizer(tapGesture) self.view.addGestureRecognizer(tapGesture)
}
var snapshotView: UIView? let swipeGesture = UISwipeGestureRecognizer(target: self, action: #selector(didSwipeBackground))
swipeGesture.direction = .down
self.view.addGestureRecognizer(swipeGesture)
}
override func viewDidAppear(_ animated: Bool) { override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(true) super.viewDidAppear(true)
self.animatePresentation()
}
// MARK: Present / Dismiss animations
var presentationFocusOffset: CGFloat?
var snapshotView: UIView?
private func addSnapshotFocusedView() -> UIView? {
guard let snapshotView = self.focusedView.snapshotView(afterScreenUpdates: false) else {
owsFail("\(self.logTag) in \(#function) snapshotView was unexpectedly nil")
return nil
}
view.addSubview(snapshotView)
guard let focusedViewSuperview = focusedView.superview else {
owsFail("\(self.logTag) in \(#function) focusedViewSuperview was unexpectedly nil")
return nil
}
let convertedFrame = view.convert(focusedView.frame, from: focusedViewSuperview)
snapshotView.frame = convertedFrame
return snapshotView
}
private func animatePresentation() {
// TODO first time only? // TODO first time only?
guard let actionSheetViewVerticalConstraint = self.actionSheetViewVerticalConstraint else { guard let actionSheetViewVerticalConstraint = self.actionSheetViewVerticalConstraint else {
@ -203,8 +232,7 @@ class MessageActionsViewController: UIViewController, MessageActionSheetDelegate
self.view.backgroundColor = UIColor.black.withAlphaComponent(0.4) self.view.backgroundColor = UIColor.black.withAlphaComponent(0.4)
} }
// layout actionsheet and snapshot view with initial frame self.actionSheetView.superview?.layoutIfNeeded()
self.view.layoutIfNeeded()
let oldFocusFrame = self.view.convert(focusedView.frame, from: focusedViewSuperview) let oldFocusFrame = self.view.convert(focusedView.frame, from: focusedViewSuperview)
NSLayoutConstraint.deactivate([actionSheetViewVerticalConstraint]) NSLayoutConstraint.deactivate([actionSheetViewVerticalConstraint])
@ -232,32 +260,7 @@ class MessageActionsViewController: UIViewController, MessageActionSheetDelegate
completion: nil) completion: nil)
} }
var presentationFocusOffset: CGFloat? private func animateDismiss(action: MessageAction?) {
private func addSnapshotFocusedView() -> UIView? {
guard let snapshotView = self.focusedView.snapshotView(afterScreenUpdates: false) else {
owsFail("\(self.logTag) in \(#function) snapshotView was unexpectedly nil")
return nil
}
view.addSubview(snapshotView)
guard let focusedViewSuperview = focusedView.superview else {
owsFail("\(self.logTag) in \(#function) focusedViewSuperview was unexpectedly nil")
return nil
}
let convertedFrame = view.convert(focusedView.frame, from: focusedViewSuperview)
snapshotView.frame = convertedFrame
return snapshotView
}
@objc
func didTapBackground() {
animateDismiss(action: nil)
}
func animateDismiss(action: MessageAction?) {
guard let actionSheetViewVerticalConstraint = self.actionSheetViewVerticalConstraint else { guard let actionSheetViewVerticalConstraint = self.actionSheetViewVerticalConstraint else {
owsFail("\(self.logTag) in \(#function) actionSheetVerticalConstraint was unexpectedly nil") owsFail("\(self.logTag) in \(#function) actionSheetVerticalConstraint was unexpectedly nil")
self.delegate?.messageActionsDidHide(self) self.delegate?.messageActionsDidHide(self)
@ -301,6 +304,18 @@ class MessageActionsViewController: UIViewController, MessageActionSheetDelegate
}) })
} }
// MARK: Actions
@objc
func didTapBackground() {
animateDismiss(action: nil)
}
@objc
func didSwipeBackground(gesture: UISwipeGestureRecognizer) {
animateDismiss(action: nil)
}
// MARK: MessageActionSheetDelegate // MARK: MessageActionSheetDelegate
func actionSheet(_ actionSheet: MessageActionSheetView, didSelectAction action: MessageAction) { func actionSheet(_ actionSheet: MessageActionSheetView, didSelectAction action: MessageAction) {
@ -445,6 +460,7 @@ class MessageActionSheetView: UIView, MessageActionViewDelegate {
} }
// MARK: // MARK:
private func updateMask() { private func updateMask() {
let cornerRadius: CGFloat = 16 let cornerRadius: CGFloat = 16
let path: UIBezierPath = UIBezierPath(roundedRect: bounds, byRoundingCorners: [.topLeft, .topRight], cornerRadii: CGSize(width: cornerRadius, height: cornerRadius)) let path: UIBezierPath = UIBezierPath(roundedRect: bounds, byRoundingCorners: [.topLeft, .topRight], cornerRadii: CGSize(width: cornerRadius, height: cornerRadius))

Loading…
Cancel
Save