Prechádzať zdrojové kódy

bugfix: in chatview title was overlapping navbar items

Bastian van de Wetering 6 rokov pred
rodič
commit
128b701bf7

+ 4 - 4
deltachat-ios.xcodeproj/project.pbxproj

@@ -21,7 +21,6 @@
 		78E45E3C21D3D03700D4B15E /* TextFieldTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78E45E3B21D3D03700D4B15E /* TextFieldTableViewCell.swift */; };
 		78E45E3E21D3D28C00D4B15E /* DCNavigationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78E45E3D21D3D28C00D4B15E /* DCNavigationController.swift */; };
 		78E45E4021D3D70700D4B15E /* ContactListController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78E45E3F21D3D70700D4B15E /* ContactListController.swift */; };
-		78E45E4221D3DB4000D4B15E /* UIViewController+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78E45E4121D3DB4000D4B15E /* UIViewController+Extension.swift */; };
 		78E45E4421D3F14A00D4B15E /* UIImage+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78E45E4321D3F14A00D4B15E /* UIImage+Extension.swift */; };
 		78E45E4C21D404AE00D4B15E /* CustomMessageCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78E45E4B21D404AE00D4B15E /* CustomMessageCell.swift */; };
 		78ED838321D5379000243125 /* TextFieldCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78ED838221D5379000243125 /* TextFieldCell.swift */; };
@@ -55,6 +54,7 @@
 		AE851ACE227CA54400ED86F0 /* InitialsBadge.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE851ACD227CA54300ED86F0 /* InitialsBadge.swift */; };
 		AE851AD0227DF50900ED86F0 /* GroupChatDetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE851ACF227DF50900ED86F0 /* GroupChatDetailViewController.swift */; };
 		AE9DAF0D22C1215D004C9591 /* EditContactController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE9DAF0C22C1215D004C9591 /* EditContactController.swift */; };
+		AE9DAF0F22C278C6004C9591 /* ChatTitleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE9DAF0E22C278C6004C9591 /* ChatTitleView.swift */; };
 		AEACE2DD1FB323CA00DCDD78 /* ChatViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEACE2DC1FB323CA00DCDD78 /* ChatViewController.swift */; };
 		AEACE2DF1FB3246400DCDD78 /* Message.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEACE2DE1FB3246400DCDD78 /* Message.swift */; };
 		AEACE2E31FB32B5C00DCDD78 /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEACE2E21FB32B5C00DCDD78 /* Constants.swift */; };
@@ -96,7 +96,6 @@
 		78E45E3B21D3D03700D4B15E /* TextFieldTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextFieldTableViewCell.swift; sourceTree = "<group>"; };
 		78E45E3D21D3D28C00D4B15E /* DCNavigationController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DCNavigationController.swift; sourceTree = "<group>"; };
 		78E45E3F21D3D70700D4B15E /* ContactListController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContactListController.swift; sourceTree = "<group>"; };
-		78E45E4121D3DB4000D4B15E /* UIViewController+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIViewController+Extension.swift"; sourceTree = "<group>"; };
 		78E45E4321D3F14A00D4B15E /* UIImage+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIImage+Extension.swift"; sourceTree = "<group>"; };
 		78E45E4B21D404AE00D4B15E /* CustomMessageCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomMessageCell.swift; sourceTree = "<group>"; };
 		78ED838221D5379000243125 /* TextFieldCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextFieldCell.swift; sourceTree = "<group>"; };
@@ -137,6 +136,7 @@
 		AE851ACD227CA54300ED86F0 /* InitialsBadge.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InitialsBadge.swift; sourceTree = "<group>"; };
 		AE851ACF227DF50900ED86F0 /* GroupChatDetailViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GroupChatDetailViewController.swift; sourceTree = "<group>"; };
 		AE9DAF0C22C1215D004C9591 /* EditContactController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditContactController.swift; sourceTree = "<group>"; };
+		AE9DAF0E22C278C6004C9591 /* ChatTitleView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatTitleView.swift; sourceTree = "<group>"; };
 		AEACE2DC1FB323CA00DCDD78 /* ChatViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatViewController.swift; sourceTree = "<group>"; };
 		AEACE2DE1FB3246400DCDD78 /* Message.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Message.swift; sourceTree = "<group>"; };
 		AEACE2E21FB32B5C00DCDD78 /* Constants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Constants.swift; sourceTree = "<group>"; };
@@ -314,7 +314,6 @@
 			children = (
 				AEACE2E21FB32B5C00DCDD78 /* Constants.swift */,
 				78E45E4321D3F14A00D4B15E /* UIImage+Extension.swift */,
-				78E45E4121D3DB4000D4B15E /* UIViewController+Extension.swift */,
 				AEACE2E41FB32E1900DCDD78 /* Utils.swift */,
 				AEE56D7F225504DB007DC082 /* Extensions.swift */,
 				AE38B3192267328200EC37A1 /* Colors.swift */,
@@ -337,6 +336,7 @@
 				AE25F08F22807AD800CDEA66 /* GroupNameCell.swift */,
 				AE728F14229D5C390047565B /* PhotoPickerAlertAction.swift */,
 				AE52EA18229EB53C00C586C9 /* ContactDetailHeader.swift */,
+				AE9DAF0E22C278C6004C9591 /* ChatTitleView.swift */,
 			);
 			path = View;
 			sourceTree = "<group>";
@@ -617,6 +617,7 @@
 				78ED839421D5AF8A00243125 /* QrCodeView.swift in Sources */,
 				AE851AC9227C77CF00ED86F0 /* Media.swift in Sources */,
 				AEACE2DF1FB3246400DCDD78 /* Message.swift in Sources */,
+				AE9DAF0F22C278C6004C9591 /* ChatTitleView.swift in Sources */,
 				AE4AEE3522B1030D000AA495 /* PreviewController.swift in Sources */,
 				7070FB9B2101ECBB000DC258 /* GroupNameController.swift in Sources */,
 				AE52EA19229EB53C00C586C9 /* ContactDetailHeader.swift in Sources */,
@@ -643,7 +644,6 @@
 				AEE6EC412282DF5700EDC689 /* MailboxViewController.swift in Sources */,
 				78ED838F21D5927A00243125 /* ProfileViewController.swift in Sources */,
 				AEE6EC482283045D00EDC689 /* EditSettingsController.swift in Sources */,
-				78E45E4221D3DB4000D4B15E /* UIViewController+Extension.swift in Sources */,
 				7A9FB1441FB061E2001FEA36 /* AppDelegate.swift in Sources */,
 				AEE56D7D2253ADB4007DC082 /* HudHandler.swift in Sources */,
 				AEACE2E51FB32E1900DCDD78 /* Utils.swift in Sources */,

+ 6 - 3
deltachat-ios/Controller/ChatViewController.swift

@@ -39,7 +39,6 @@ class ChatViewController: MessagesViewController {
 	}()
 
 	var disableWriting = false
-
 	var previewView: UIView?
 	var previewController: PreviewController?
 
@@ -50,11 +49,13 @@ class ChatViewController: MessagesViewController {
 		return messageInputBar
 	}
 
+	private var titleView = ChatTitleView()
+
 	init(chatId: Int, title: String? = nil) {
 		self.chatId = chatId
 		super.init(nibName: nil, bundle: nil)
 		if let title = title {
-			updateTitleView(title: title, subtitle: nil)
+			titleView.updateTitleView(title: title, subtitle: nil)
 		}
 		hidesBottomBarWhenPushed = true
 	}
@@ -66,6 +67,8 @@ class ChatViewController: MessagesViewController {
 	override func viewDidLoad() {
 		messagesCollectionView.register(CustomMessageCell.self)
 		super.viewDidLoad()
+		navigationItem.titleView = titleView
+
 		view.backgroundColor = DCColors.chatBackgroundColor
 		if !MRConfig.configured {
 			// TODO: display message about nothing being configured
@@ -89,7 +92,7 @@ class ChatViewController: MessagesViewController {
 		navigationController?.navigationBar.addGestureRecognizer(navBarTap)
 
 		let chat = MRChat(id: chatId)
-		updateTitleView(title: chat.name, subtitle: chat.subtitle)
+		titleView.updateTitleView(title: chat.name, subtitle: chat.subtitle)
 
 		if let image = chat.profileImage {
 			navigationItem.rightBarButtonItem = UIBarButtonItem(image: image, style: .done, target: self, action: #selector(chatProfilePressed))

+ 0 - 48
deltachat-ios/Helper/UIViewController+Extension.swift

@@ -1,48 +0,0 @@
-//
-//  TableViewController.swift
-//  deltachat-ios
-//
-//  Created by Friedel Ziegelmayer on 26.12.18.
-//  Copyright © 2018 Jonas Reinsch. All rights reserved.
-//
-
-import UIKit
-
-extension UIViewController {
-  func updateTitleView(title: String, subtitle: String?, baseColor: UIColor = .darkText) {
-    let titleLabel = UILabel(frame: CGRect(x: 0, y: -2, width: 0, height: 0))
-    titleLabel.backgroundColor = UIColor.clear
-    titleLabel.textColor = baseColor
-    titleLabel.font = UIFont.systemFont(ofSize: 16, weight: .semibold)
-    titleLabel.text = title
-    titleLabel.textAlignment = .center
-    titleLabel.adjustsFontSizeToFitWidth = true
-    titleLabel.sizeToFit()
-
-    let subtitleLabel = UILabel(frame: CGRect(x: 0, y: 18, width: 0, height: 0))
-    subtitleLabel.textColor = baseColor.withAlphaComponent(0.95)
-    subtitleLabel.font = UIFont.systemFont(ofSize: 12)
-    subtitleLabel.text = subtitle
-    subtitleLabel.textAlignment = .center
-    subtitleLabel.adjustsFontSizeToFitWidth = true
-    subtitleLabel.sizeToFit()
-
-    let titleView = UIView(frame: CGRect(x: 0, y: 0, width: max(titleLabel.frame.size.width, subtitleLabel.frame.size.width), height: 30))
-    titleView.addSubview(titleLabel)
-    if subtitle != nil {
-      titleView.addSubview(subtitleLabel)
-    } else {
-      titleLabel.frame = titleView.frame
-    }
-    let widthDiff = subtitleLabel.frame.size.width - titleLabel.frame.size.width
-    if widthDiff < 0 {
-      let newX = widthDiff / 2
-      subtitleLabel.frame.origin.x = abs(newX)
-    } else {
-      let newX = widthDiff / 2
-      titleLabel.frame.origin.x = newX
-    }
-
-    navigationItem.titleView = titleView
-  }
-}

+ 60 - 0
deltachat-ios/View/ChatTitleView.swift

@@ -0,0 +1,60 @@
+//
+//  ChatTitleView.swift
+//  deltachat-ios
+//
+//  Created by Bastian van de Wetering on 25.06.19.
+//  Copyright © 2019 Jonas Reinsch. All rights reserved.
+//
+
+import UIKit
+
+class ChatTitleView: UIView {
+
+	private var titleLabel: UILabel = {
+		let titleLabel = UILabel()
+		titleLabel.backgroundColor = UIColor.clear
+		titleLabel.font = UIFont.systemFont(ofSize: 16, weight: .semibold)
+		titleLabel.textAlignment = .center
+		titleLabel.adjustsFontSizeToFitWidth = true
+		return titleLabel
+	}()
+
+	private var subtitleLabel: UILabel = {
+		let subtitleLabel = UILabel()
+		subtitleLabel.font = UIFont.systemFont(ofSize: 12)
+		subtitleLabel.textAlignment = .center
+		return subtitleLabel
+	}()
+
+	init() {
+		super.init(frame: .zero)
+		setupSubviews()
+	}
+
+	required init?(coder aDecoder: NSCoder) {
+		fatalError("init(coder:) has not been implemented")
+	}
+
+	private func setupSubviews() {
+		addSubview(titleLabel)
+		titleLabel.translatesAutoresizingMaskIntoConstraints = false
+		titleLabel.centerXAnchor.constraint(equalTo: centerXAnchor).isActive = true
+		titleLabel.leadingAnchor.constraint(equalTo: leadingAnchor).isActive = true
+		titleLabel.trailingAnchor.constraint(equalTo: trailingAnchor).isActive = true
+		titleLabel.topAnchor.constraint(equalTo: topAnchor).isActive = true
+
+		addSubview(subtitleLabel)
+		subtitleLabel.translatesAutoresizingMaskIntoConstraints = false
+		subtitleLabel.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 0).isActive = true
+		subtitleLabel.topAnchor.constraint(equalTo: titleLabel.bottomAnchor, constant: 0).isActive = true
+		subtitleLabel.trailingAnchor.constraint(equalTo: trailingAnchor, constant: 0).isActive = true
+		subtitleLabel.bottomAnchor.constraint(equalTo: bottomAnchor, constant: 0).isActive = true
+	}
+
+	func updateTitleView(title: String, subtitle: String?, baseColor: UIColor = .darkText) {
+		subtitleLabel.textColor = baseColor.withAlphaComponent(0.95)
+		titleLabel.textColor = baseColor
+		titleLabel.text = title
+		subtitleLabel.text = subtitle
+	}
+}