Browse Source

support large text in document gallery view (#1588)

* support large text in document gallery view

* reduce initial DocumentGalleryFileCell size back to 60

* allow a little bit more space between title and subtitle - doesn't change cell size
cyBerta 3 years ago
parent
commit
c7e3ccd840

+ 8 - 1
deltachat-ios/Controller/DocumentGalleryController.swift

@@ -13,7 +13,7 @@ class DocumentGalleryController: UIViewController {
         table.register(DocumentGalleryFileCell.self, forCellReuseIdentifier: DocumentGalleryFileCell.reuseIdentifier)
         table.dataSource = self
         table.delegate = self
-        table.rowHeight = 60
+        table.rowHeight = DocumentGalleryFileCell.cellHeight
         return table
     }()
 
@@ -178,6 +178,13 @@ extension DocumentGalleryController: UITableViewDelegate, UITableViewDataSource
             }
         )
     }
+
+    override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
+        if previousTraitCollection?.preferredContentSizeCategory !=
+            traitCollection.preferredContentSizeCategory {
+            tableView.rowHeight = DocumentGalleryFileCell.cellHeight
+        }
+    }
 }
 
 // MARK: - coordinator

+ 14 - 5
deltachat-ios/View/Cell/DocumentGalleryFileCell.swift

@@ -5,6 +5,14 @@ class DocumentGalleryFileCell: UITableViewCell {
 
     static let reuseIdentifier = "document_gallery_file_cell"
 
+    static var cellHeight: CGFloat {
+        let textHeight = UIFont.preferredFont(forTextStyle: .headline).pointSize + UIFont.preferredFont(forTextStyle: .subheadline).pointSize + 24
+        if textHeight > 60 {
+            return textHeight
+        }
+        return 60
+    }
+
     private let fileImageView: UIImageView = {
         let imageView = UIImageView()
         imageView.contentMode = .scaleAspectFit
@@ -15,20 +23,21 @@ class DocumentGalleryFileCell: UITableViewCell {
         let stackView = UIStackView(arrangedSubviews: [title, subtitle])
         stackView.axis = NSLayoutConstraint.Axis.vertical
         stackView.translatesAutoresizingMaskIntoConstraints = false
-        stackView.clipsToBounds = true
+        stackView.distribution = .fillProportionally
+        stackView.contentMode = .center
         return stackView
     }()
 
     private lazy var title: UILabel = {
         let title = UILabel()
-        title.font = UIFont.systemFont(ofSize: 16, weight: .regular)
+        title.font = UIFont.preferredFont(forTextStyle: .headline)
         title.translatesAutoresizingMaskIntoConstraints = false
         return title
     }()
 
     private lazy var subtitle: UILabel = {
         let subtitle = UILabel()
-        subtitle.font = UIFont.italicSystemFont(ofSize: 12)
+        subtitle.font = UIFont.preferredItalicFont(for: .subheadline)
         subtitle.translatesAutoresizingMaskIntoConstraints = false
         return subtitle
     }()
@@ -60,8 +69,8 @@ class DocumentGalleryFileCell: UITableViewCell {
         fileImageView.widthAnchor.constraint(equalToConstant: 50).isActive = true
         stackView.constraintToTrailingOf(fileImageView, paddingLeading: 12).isActive = true
         stackView.constraintAlignTrailingTo(contentView, paddingTrailing: 12).isActive = true
-        stackView.constraintAlignTopTo(contentView, paddingTop: 12).isActive = true
-        stackView.constraintAlignBottomTo(contentView, paddingBottom: 12).isActive = true
+        stackView.constraintAlignTopTo(contentView, paddingTop: 6).isActive = true
+        stackView.constraintAlignBottomTo(contentView, paddingBottom: 6).isActive = true
 
     }