From c1a61e897bf2b92bec226b87d7d8462feb4e8cf9 Mon Sep 17 00:00:00 2001 From: Niels Andriesse Date: Wed, 18 Aug 2021 09:56:28 +1000 Subject: [PATCH] UI improvements --- Session/Calls/CallVC.swift | 37 +++++++++++++++++++ .../ConversationVC+Interaction.swift | 4 +- Session/Meta/AppDelegate.swift | 11 +++--- 3 files changed, 46 insertions(+), 6 deletions(-) diff --git a/Session/Calls/CallVC.swift b/Session/Calls/CallVC.swift index e6cf13de2..7b840b0c7 100644 --- a/Session/Calls/CallVC.swift +++ b/Session/Calls/CallVC.swift @@ -18,6 +18,29 @@ final class CallVC : UIViewController, WebRTCSessionDelegate { return RTCCameraVideoCapturer(delegate: webRTCSession.localVideoSource) }() + // MARK: UI Components + private lazy var fadeView: UIView = { + let result = UIView() + let height: CGFloat = 64 + var frame = UIScreen.main.bounds + frame.size.height = height + let layer = CAGradientLayer() + layer.frame = frame + layer.colors = [ UIColor(hex: 0x000000).withAlphaComponent(0.4).cgColor, UIColor(hex: 0x000000).withAlphaComponent(0).cgColor ] + result.layer.insertSublayer(layer, at: 0) + result.set(.height, to: height) + return result + }() + + private lazy var closeButton: UIButton = { + let result = UIButton(type: .custom) + let image = UIImage(named: "X")!.withTint(.white) + result.setImage(image, for: UIControl.State.normal) + result.set(.width, to: 60) + result.set(.height, to: 60) + return result + }() + // MARK: Mode enum Mode { case offer @@ -69,6 +92,15 @@ final class CallVC : UIViewController, WebRTCSessionDelegate { localVideoView.pin(.right, to: .right, of: view, withInset: -Values.largeSpacing) let bottomMargin = UIApplication.shared.keyWindow!.safeAreaInsets.bottom + Values.largeSpacing localVideoView.pin(.bottom, to: .bottom, of: view, withInset: -bottomMargin) + // Fade view + view.addSubview(fadeView) + fadeView.translatesAutoresizingMaskIntoConstraints = false + fadeView.pin([ UIView.HorizontalEdge.left, UIView.VerticalEdge.top, UIView.HorizontalEdge.right ], to: view) + // Close button + view.addSubview(closeButton) + closeButton.translatesAutoresizingMaskIntoConstraints = false + closeButton.pin(.left, to: .left, of: view) + closeButton.pin(.top, to: .top, of: view, withInset: 32) } override func viewDidAppear(_ animated: Bool) { @@ -84,4 +116,9 @@ final class CallVC : UIViewController, WebRTCSessionDelegate { deinit { WebRTCSession.current = nil } + + // MARK: Interaction + @objc private func close() { + presentingViewController?.dismiss(animated: true, completion: nil) + } } diff --git a/Session/Conversations/ConversationVC+Interaction.swift b/Session/Conversations/ConversationVC+Interaction.swift index ad49ad20c..c8f59bb0d 100644 --- a/Session/Conversations/ConversationVC+Interaction.swift +++ b/Session/Conversations/ConversationVC+Interaction.swift @@ -29,7 +29,9 @@ extension ConversationVC : InputViewDelegate, MessageCellDelegate, ContextMenuAc @objc func startCall() { guard let contactSessionID = (thread as? TSContactThread)?.contactSessionID() else { return } let callVC = CallVC(for: contactSessionID, mode: .offer) - navigationController!.pushViewController(callVC, animated: true, completion: nil) + callVC.modalPresentationStyle = .overFullScreen + callVC.modalTransitionStyle = .crossDissolve + present(callVC, animated: true, completion: nil) } // MARK: Blocking diff --git a/Session/Meta/AppDelegate.swift b/Session/Meta/AppDelegate.swift index bd98133dc..8880a26e0 100644 --- a/Session/Meta/AppDelegate.swift +++ b/Session/Meta/AppDelegate.swift @@ -13,6 +13,8 @@ extension AppDelegate { alert.addAction(UIAlertAction(title: "Accept", style: .default, handler: { _ in let callVC = CallVC(for: message.sender!, mode: .answer(sdp: sdp)) presentingVC.dismiss(animated: true) { + callVC.modalPresentationStyle = .overFullScreen + callVC.modalTransitionStyle = .crossDissolve presentingVC.present(callVC, animated: true, completion: nil) } })) @@ -65,17 +67,16 @@ extension AppDelegate { @objc func getAppModeOrSystemDefault() -> AppMode { let userDefaults = UserDefaults.standard - - guard userDefaults.dictionaryRepresentation().keys.contains("appMode") else { + if userDefaults.dictionaryRepresentation().keys.contains("appMode") { + let mode = userDefaults.integer(forKey: "appMode") + return AppMode(rawValue: mode) ?? .light + } else { if #available(iOS 13.0, *) { return UITraitCollection.current.userInterfaceStyle == .dark ? .dark : .light } else { return .light } } - - let mode = userDefaults.integer(forKey: "appMode") - return AppMode(rawValue: mode) ?? .light } }