mirror of https://github.com/oxen-io/session-ios
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
1.7 KiB
Swift
62 lines
1.7 KiB
Swift
//
|
|
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
@objc
|
|
protocol MessageActionsDelegate: class {
|
|
func messageActionsDidHide(_ messageActionsViewController: MessageActionsViewController)
|
|
}
|
|
|
|
@objc
|
|
class MessageActionsViewController: UIViewController {
|
|
|
|
@objc
|
|
weak var delegate: MessageActionsDelegate?
|
|
|
|
let focusedView: UIView
|
|
|
|
@objc
|
|
required init(focusedView: UIView) {
|
|
self.focusedView = focusedView
|
|
|
|
super.init(nibName: nil, bundle: nil)
|
|
}
|
|
|
|
required init?(coder aDecoder: NSCoder) {
|
|
fatalError("init(coder:) has not been implemented")
|
|
}
|
|
|
|
override func loadView() {
|
|
self.view = UIView()
|
|
view.backgroundColor = UIColor.black.withAlphaComponent(0.4)
|
|
|
|
highlightFocusedView()
|
|
|
|
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(didTapBackground))
|
|
self.view.addGestureRecognizer(tapGesture)
|
|
}
|
|
|
|
private func highlightFocusedView() {
|
|
guard let snapshotView = self.focusedView.snapshotView(afterScreenUpdates: false) else {
|
|
owsFail("\(self.logTag) in \(#function) snapshotView was unexpectedly nil")
|
|
return
|
|
}
|
|
view.addSubview(snapshotView)
|
|
|
|
guard let focusedViewSuperview = focusedView.superview else {
|
|
owsFail("\(self.logTag) in \(#function) focusedViewSuperview was unexpectedly nil")
|
|
return
|
|
}
|
|
|
|
let convertedFrame = view.convert(focusedView.frame, from: focusedViewSuperview)
|
|
snapshotView.frame = convertedFrame
|
|
}
|
|
|
|
@objc
|
|
func didTapBackground() {
|
|
self.delegate?.messageActionsDidHide(self)
|
|
}
|
|
}
|