Bladeren bron

reduce a quote drafts max number of lines in horizontal layout

cyberta 4 jaren geleden
bovenliggende
commit
3069985b64
1 gewijzigde bestanden met toevoegingen van 20 en 1 verwijderingen
  1. 20 1
      deltachat-ios/Chat/Views/QuotePreview.swift

+ 20 - 1
deltachat-ios/Chat/Views/QuotePreview.swift

@@ -5,6 +5,7 @@ import DcCore
 public class QuotePreview: DraftPreview {
 
     public weak var delegate: DraftPreviewDelegate?
+    private var compactView = false
 
     lazy var quoteView: QuoteView = {
         let view = QuoteView()
@@ -27,7 +28,8 @@ public class QuotePreview: DraftPreview {
     override public func configure(draft: DraftModel) {
         if let quoteText = draft.quoteText {
             quoteView.quote.text = quoteText
-            quoteView.quote.numberOfLines = draft.draftAttachment != nil ? 1 : 3
+            compactView = draft.draftAttachment != nil
+            calculateQuoteHeight(compactView: compactView)
             if let quoteMessage = draft.quoteMessage {
                 let contact = quoteMessage.fromContact
                 quoteView.senderTitle.text = contact.displayName
@@ -41,4 +43,21 @@ public class QuotePreview: DraftPreview {
             isHidden = true
         }
     }
+
+    func calculateQuoteHeight(compactView: Bool) {
+        let vertical = traitCollection.verticalSizeClass == .regular
+        if vertical {
+            quoteView.quote.numberOfLines = compactView ? 1 : 3
+        } else {
+            quoteView.quote.numberOfLines = 1
+        }
+    }
+
+    public override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
+        super.traitCollectionDidChange(previousTraitCollection)
+        if (self.traitCollection.verticalSizeClass != previousTraitCollection?.verticalSizeClass)
+                || (self.traitCollection.horizontalSizeClass != previousTraitCollection?.horizontalSizeClass) {
+            calculateQuoteHeight(compactView: compactView)
+        }
+    }
 }