UI improvements

This commit is contained in:
Niels Andriesse 2021-08-18 09:56:28 +10:00
parent 34e630b5bf
commit c1a61e897b
3 changed files with 46 additions and 6 deletions

View File

@ -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)
}
}

View File

@ -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

View File

@ -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
}
}