fix input panel issue & make local video view draggable

pull/560/head
ryanzhao 4 years ago
parent daee269a7a
commit e8500d75a7

@ -8,6 +8,7 @@ final class CallVC : UIViewController, WebRTCSessionDelegate {
let mode: Mode let mode: Mode
let webRTCSession: WebRTCSession let webRTCSession: WebRTCSession
var isMuted = false var isMuted = false
var conversationVC: ConversationVC? = nil
lazy var cameraManager: CameraManager = { lazy var cameraManager: CameraManager = {
let result = CameraManager() let result = CameraManager()
@ -25,6 +26,7 @@ final class CallVC : UIViewController, WebRTCSessionDelegate {
result.contentMode = .scaleAspectFill result.contentMode = .scaleAspectFill
result.set(.width, to: 80) result.set(.width, to: 80)
result.set(.height, to: 173) result.set(.height, to: 173)
result.addGestureRecognizer(UIPanGestureRecognizer(target: self, action: #selector(handlePanGesture)))
return result return result
}() }()
@ -47,13 +49,13 @@ final class CallVC : UIViewController, WebRTCSessionDelegate {
return result return result
}() }()
private lazy var closeButton: UIButton = { private lazy var minimizeButton: UIButton = {
let result = UIButton(type: .custom) let result = UIButton(type: .custom)
let image = UIImage(named: "X")!.withTint(.white) let image = UIImage(named: "Minimize")!.withTint(.white)
result.setImage(image, for: UIControl.State.normal) result.setImage(image, for: UIControl.State.normal)
result.set(.width, to: 60) result.set(.width, to: 60)
result.set(.height, to: 60) result.set(.height, to: 60)
result.addTarget(self, action: #selector(close), for: UIControl.Event.touchUpInside) result.addTarget(self, action: #selector(minimize), for: UIControl.Event.touchUpInside)
return result return result
}() }()
@ -83,7 +85,7 @@ final class CallVC : UIViewController, WebRTCSessionDelegate {
private lazy var switchAudioButton: UIButton = { private lazy var switchAudioButton: UIButton = {
let result = UIButton(type: .custom) let result = UIButton(type: .custom)
let image = UIImage(named: "AudioOn")!.withTint(.white) let image = UIImage(named: "AudioOff")!.withTint(.white)
result.setImage(image, for: UIControl.State.normal) result.setImage(image, for: UIControl.State.normal)
result.set(.width, to: 60) result.set(.width, to: 60)
result.set(.height, to: 60) result.set(.height, to: 60)
@ -170,14 +172,14 @@ final class CallVC : UIViewController, WebRTCSessionDelegate {
fadeView.translatesAutoresizingMaskIntoConstraints = false fadeView.translatesAutoresizingMaskIntoConstraints = false
fadeView.pin([ UIView.HorizontalEdge.left, UIView.VerticalEdge.top, UIView.HorizontalEdge.right ], to: view) fadeView.pin([ UIView.HorizontalEdge.left, UIView.VerticalEdge.top, UIView.HorizontalEdge.right ], to: view)
// Close button // Close button
view.addSubview(closeButton) view.addSubview(minimizeButton)
closeButton.translatesAutoresizingMaskIntoConstraints = false minimizeButton.translatesAutoresizingMaskIntoConstraints = false
closeButton.pin(.left, to: .left, of: view) minimizeButton.pin(.left, to: .left, of: view)
closeButton.pin(.top, to: .top, of: view, withInset: 32) minimizeButton.pin(.top, to: .top, of: view, withInset: 32)
// Title label // Title label
view.addSubview(titleLabel) view.addSubview(titleLabel)
titleLabel.translatesAutoresizingMaskIntoConstraints = false titleLabel.translatesAutoresizingMaskIntoConstraints = false
titleLabel.center(.vertical, in: closeButton) titleLabel.center(.vertical, in: minimizeButton)
titleLabel.center(.horizontal, in: view) titleLabel.center(.horizontal, in: view)
// End call button // End call button
view.addSubview(hangUpButton) view.addSubview(hangUpButton)
@ -220,6 +222,7 @@ final class CallVC : UIViewController, WebRTCSessionDelegate {
self.remoteVideoView.alpha = 0 self.remoteVideoView.alpha = 0
} }
Timer.scheduledTimer(withTimeInterval: 2, repeats: false) { _ in Timer.scheduledTimer(withTimeInterval: 2, repeats: false) { _ in
self.conversationVC?.showInputAccessoryView()
self.presentingViewController?.dismiss(animated: true, completion: nil) self.presentingViewController?.dismiss(animated: true, completion: nil)
} }
} }
@ -228,9 +231,14 @@ final class CallVC : UIViewController, WebRTCSessionDelegate {
Storage.write { transaction in Storage.write { transaction in
WebRTCSession.current?.endCall(with: self.sessionID, using: transaction) WebRTCSession.current?.endCall(with: self.sessionID, using: transaction)
} }
self.conversationVC?.showInputAccessoryView()
presentingViewController?.dismiss(animated: true, completion: nil) presentingViewController?.dismiss(animated: true, completion: nil)
} }
@objc private func minimize() {
}
@objc private func switchCamera() { @objc private func switchCamera() {
cameraManager.switchCamera() cameraManager.switchCamera()
} }
@ -238,16 +246,43 @@ final class CallVC : UIViewController, WebRTCSessionDelegate {
@objc private func switchAudio() { @objc private func switchAudio() {
if isMuted { if isMuted {
switchAudioButton.backgroundColor = UIColor(hex: 0x1F1F1F) switchAudioButton.backgroundColor = UIColor(hex: 0x1F1F1F)
let image = UIImage(named: "AudioOn")!.withTint(.white)
switchAudioButton.setImage(image, for: UIControl.State.normal)
isMuted = false isMuted = false
webRTCSession.unmute() webRTCSession.unmute()
} else { } else {
switchAudioButton.backgroundColor = Colors.destructive switchAudioButton.backgroundColor = Colors.destructive
let image = UIImage(named: "AudioOff")!.withTint(.white)
switchAudioButton.setImage(image, for: UIControl.State.normal)
isMuted = true isMuted = true
webRTCSession.mute() webRTCSession.mute()
} }
} }
@objc private func handlePanGesture(gesture: UIPanGestureRecognizer) {
let location = gesture.location(in: self.view)
if let draggedView = gesture.view {
draggedView.center = location
if gesture.state == .ended {
let sideMargin = 40 + Values.verySmallSpacing
if draggedView.frame.midX >= self.view.layer.frame.width / 2 {
UIView.animate(withDuration: 0.5, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 1, options: .curveEaseIn, animations: {
draggedView.center.x = self.view.layer.frame.width - sideMargin
}, completion: nil)
}else{
UIView.animate(withDuration: 0.5, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 1, options: .curveEaseIn, animations: {
draggedView.center.x = sideMargin
}, completion: nil)
}
let topMargin = UIApplication.shared.keyWindow!.safeAreaInsets.top + Values.veryLargeSpacing
if draggedView.frame.minY <= topMargin {
UIView.animate(withDuration: 0.5, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 1, options: .curveEaseIn, animations: {
draggedView.center.y = topMargin + draggedView.frame.size.height / 2
}, completion: nil)
}
let bottomMargin = UIApplication.shared.keyWindow!.safeAreaInsets.bottom
if draggedView.frame.maxY >= self.view.layer.frame.height {
UIView.animate(withDuration: 0.5, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 1, options: .curveEaseIn, animations: {
draggedView.center.y = self.view.layer.frame.height - draggedView.frame.size.height / 2 - bottomMargin
}, completion: nil)
}
}
}
}
} }

@ -26,11 +26,15 @@ extension ConversationVC : InputViewDelegate, MessageCellDelegate, ContextMenuAc
messagesTableView.scrollToRow(at: indexPath, at: .top, animated: true) messagesTableView.scrollToRow(at: indexPath, at: .top, animated: true)
} }
@objc func startCall() { // MARK: Call
@objc func startCall(_ sender: Any) {
guard let contactSessionID = (thread as? TSContactThread)?.contactSessionID() else { return } guard let contactSessionID = (thread as? TSContactThread)?.contactSessionID() else { return }
let callVC = CallVC(for: contactSessionID, mode: .offer) let callVC = CallVC(for: contactSessionID, mode: .offer)
callVC.conversationVC = self
callVC.modalPresentationStyle = .overFullScreen callVC.modalPresentationStyle = .overFullScreen
callVC.modalTransitionStyle = .crossDissolve callVC.modalTransitionStyle = .crossDissolve
self.inputAccessoryView?.isHidden = true
self.inputAccessoryView?.alpha = 0
present(callVC, animated: true, completion: nil) present(callVC, animated: true, completion: nil)
} }

@ -253,6 +253,7 @@ final class ConversationVC : BaseVC, ConversationViewModelDelegate, OWSConversat
super.viewDidAppear(animated) super.viewDidAppear(animated)
didFinishInitialLayout = true didFinishInitialLayout = true
markAllAsRead() markAllAsRead()
self.becomeFirstResponder()
} }
override func viewWillDisappear(_ animated: Bool) { override func viewWillDisappear(_ animated: Bool) {
@ -261,7 +262,7 @@ final class ConversationVC : BaseVC, ConversationViewModelDelegate, OWSConversat
Storage.write { transaction in Storage.write { transaction in
self.thread.setDraft(text, transaction: transaction) self.thread.setDraft(text, transaction: transaction)
} }
inputAccessoryView?.resignFirstResponder() self.resignFirstResponder()
} }
override func viewDidDisappear(_ animated: Bool) { override func viewDidDisappear(_ animated: Bool) {

@ -1,7 +1,7 @@
{ {
"images" : [ "images" : [
{ {
"filename" : "Shape.pdf", "filename" : "minimize.pdf",
"idiom" : "universal" "idiom" : "universal"
} }
], ],
Loading…
Cancel
Save