Browse Source

revert PaddingLabel usage, it's implementation causes cut off texts, if the label has padding. Replaced by PaddingTextView

cyberta 4 years ago
parent
commit
6c1ca35ae5

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

@@ -124,8 +124,8 @@
 		30E8F2442449C64100CE2C90 /* ChatListCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30E8F2432449C64100CE2C90 /* ChatListCell.swift */; };
 		30E8F2512449EA0E00CE2C90 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 3060119E22DDE24000C1CE6F /* Localizable.strings */; };
 		30E8F253244DAD0E00CE2C90 /* SendingController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30E8F252244DAD0E00CE2C90 /* SendingController.swift */; };
-		30F4BFEE252E3E020006B9B3 /* PaddingLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30F4BFED252E3E020006B9B3 /* PaddingLabel.swift */; };
-		30F4C002252E43510006B9B3 /* PaddingLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30F4BFED252E3E020006B9B3 /* PaddingLabel.swift */; };
+		30EF7308252F6A3300E2C54A /* PaddingTextView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30F4BFED252E3E020006B9B3 /* PaddingTextView.swift */; };
+		30EF7309252F6A3400E2C54A /* PaddingTextView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30F4BFED252E3E020006B9B3 /* PaddingTextView.swift */; };
 		30F8817624DA97DA0023780E /* BackgroundContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30F8817524DA97DA0023780E /* BackgroundContainer.swift */; };
 		30F9B9EC235F2116006E7ACF /* MessageCounter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30F9B9EB235F2116006E7ACF /* MessageCounter.swift */; };
 		30FDB70524D1C1000066C48D /* ChatViewControllerNew.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30FDB6F824D1C1000066C48D /* ChatViewControllerNew.swift */; };
@@ -422,7 +422,7 @@
 		30E8F2412448B77600CE2C90 /* ChatListController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatListController.swift; sourceTree = "<group>"; };
 		30E8F2432449C64100CE2C90 /* ChatListCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatListCell.swift; sourceTree = "<group>"; };
 		30E8F252244DAD0E00CE2C90 /* SendingController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SendingController.swift; sourceTree = "<group>"; };
-		30F4BFED252E3E020006B9B3 /* PaddingLabel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PaddingLabel.swift; sourceTree = "<group>"; };
+		30F4BFED252E3E020006B9B3 /* PaddingTextView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PaddingTextView.swift; sourceTree = "<group>"; };
 		30F8817524DA97DA0023780E /* BackgroundContainer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BackgroundContainer.swift; sourceTree = "<group>"; };
 		30F9B9EB235F2116006E7ACF /* MessageCounter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageCounter.swift; sourceTree = "<group>"; };
 		30FDB6F824D1C1000066C48D /* ChatViewControllerNew.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChatViewControllerNew.swift; sourceTree = "<group>"; };
@@ -1060,7 +1060,7 @@
 				AEFBE22E23FEF23D0045327A /* ProviderInfoCell.swift */,
 				AEB54C7E246DBA610004624C /* FlexLabel.swift */,
 				AED62BCD247687E6009E220D /* LocationStreamingIndicator.swift */,
-				30F4BFED252E3E020006B9B3 /* PaddingLabel.swift */,
+				30F4BFED252E3E020006B9B3 /* PaddingTextView.swift */,
 			);
 			path = View;
 			sourceTree = "<group>";
@@ -1424,12 +1424,12 @@
 				302589FF2452FA280086C1CD /* ShareAttachment.swift in Sources */,
 				3057029F24C6445000D84EFC /* EmptyStateLabel.swift in Sources */,
 				305702A224C6455400D84EFC /* TypeAlias.swift in Sources */,
+				30EF7309252F6A3400E2C54A /* PaddingTextView.swift in Sources */,
 				30E8F2442449C64100CE2C90 /* ChatListCell.swift in Sources */,
 				30E8F2132447285600CE2C90 /* ShareViewController.swift in Sources */,
 				30E8F253244DAD0E00CE2C90 /* SendingController.swift in Sources */,
 				3057028C24C5E7B600D84EFC /* ContactCellViewModel.swift in Sources */,
 				30E8F2422448B77600CE2C90 /* ChatListController.swift in Sources */,
-				30F4C002252E43510006B9B3 /* PaddingLabel.swift in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
@@ -1473,7 +1473,6 @@
 				AE8DD451249D1DFB009A4BC1 /* FileTableViewCell.swift in Sources */,
 				3040F45E234DFBC000FA34D5 /* Audio.swift in Sources */,
 				305961FE2346125100C80F33 /* InsetLabel.swift in Sources */,
-				30F4BFEE252E3E020006B9B3 /* PaddingLabel.swift in Sources */,
 				3095A351237DD1F700AB07F7 /* MediaPicker.swift in Sources */,
 				B21005DB23383664004C70C5 /* SettingsClassicViewController.swift in Sources */,
 				305961F62346125100C80F33 /* MessageContentCell.swift in Sources */,
@@ -1525,6 +1524,7 @@
 				AEF53BD5248904BF00D309C1 /* GalleryTimeLabel.swift in Sources */,
 				AEE6EC482283045D00EDC689 /* EditSettingsController.swift in Sources */,
 				30E348DF24F3F819005C93D1 /* ChatTableView.swift in Sources */,
+				30EF7308252F6A3300E2C54A /* PaddingTextView.swift in Sources */,
 				30E348E124F53772005C93D1 /* NewImageTextCell.swift in Sources */,
 				3008CB7624F95B6D00E6A617 /* NewAudioController.swift in Sources */,
 				305961DF2346125100C80F33 /* MessageCellDelegate.swift in Sources */,

+ 10 - 10
deltachat-ios/Chat/Views/Cells/BaseMessageCell.swift

@@ -82,14 +82,14 @@ public class BaseMessageCell: UITableViewCell {
         return view
     }()
 
-    lazy var topLabel: UILabel = {
-        let label = PaddingLabel(top: 0, left: 4, bottom: 0, right: 4)
-        label.translatesAutoresizingMaskIntoConstraints = false
-        label.text = "title"
-        label.font = UIFont.preferredFont(for: .caption1, weight: .regular)
-        label.layer.cornerRadius = 4
-        label.clipsToBounds = true
-        return label
+    lazy var topLabel: PaddingTextView = {
+        let view = PaddingTextView(top: 0, left: 4, bottom: 0, right: 4)
+        view.translatesAutoresizingMaskIntoConstraints = false
+        view.text = "title"
+        view.font = UIFont.preferredFont(for: .caption1, weight: .regular)
+        view.layer.cornerRadius = 4
+        view.clipsToBounds = true
+        return view
     }()
 
     lazy var mainContentView: UIStackView = {
@@ -99,8 +99,8 @@ public class BaseMessageCell: UITableViewCell {
         return view
     }()
 
-    lazy var bottomLabel: UILabel = {
-        let label = PaddingLabel(top: 0, left: 4, bottom: 0, right: 4)
+    lazy var bottomLabel: PaddingTextView = {
+        let label = PaddingTextView(top: 0, left: 4, bottom: 0, right: 4)
         label.translatesAutoresizingMaskIntoConstraints = false
         label.font = UIFont.preferredFont(for: .caption1, weight: .regular)
         label.setContentHuggingPriority(.defaultHigh, for: .horizontal)

+ 2 - 4
deltachat-ios/Chat/Views/Cells/NewAudioMessageCell.swift

@@ -17,11 +17,9 @@ public class NewAudioMessageCell: BaseMessageCell {
         return view
     }()
 
-    lazy var messageLabel: UILabel = {
-        let label = PaddingLabel(top: 0, left: 12, bottom: 0, right: 12)
+    lazy var messageLabel: PaddingTextView = {
+        let label = PaddingTextView(top: 0, left: 12, bottom: 0, right: 12)
         label.translatesAutoresizingMaskIntoConstraints = false
-        label.numberOfLines = 0
-        label.lineBreakMode = .byWordWrapping
         label.font = UIFont.preferredFont(for: .body, weight: .regular)
         return label
     }()

+ 2 - 4
deltachat-ios/Chat/Views/Cells/NewImageTextCell.swift

@@ -8,11 +8,9 @@ class NewImageTextCell: BaseMessageCell {
     var imageHeightConstraint: NSLayoutConstraint?
     var imageWidthConstraint: NSLayoutConstraint?
 
-    lazy var messageLabel: UILabel = {
-        let label = PaddingLabel(top: 0, left: 12, bottom: 0, right: 12)
+    lazy var messageLabel: PaddingTextView = {
+        let label = PaddingTextView(top: 0, left: 12, bottom: 0, right: 12)
         label.translatesAutoresizingMaskIntoConstraints = false
-        label.numberOfLines = 0
-        label.lineBreakMode = .byWordWrapping
         label.setContentHuggingPriority(.defaultLow, for: .vertical)
         label.font = UIFont.preferredFont(for: .body, weight: .regular)
         return label

+ 6 - 8
deltachat-ios/Chat/Views/Cells/NewTextMessageCell.swift

@@ -4,18 +4,16 @@ import UIKit
 
 class NewTextMessageCell: BaseMessageCell {
 
-    lazy var messageLabel: UILabel = {
-        let label = PaddingLabel(top: 0, left: 12, bottom: 0, right: 12)
-        label.translatesAutoresizingMaskIntoConstraints = false
-        label.numberOfLines = 0
-        label.lineBreakMode = .byWordWrapping
-        label.font = UIFont.preferredFont(for: .body, weight: .regular)
-        return label
+    lazy var messageLabel: PaddingTextView = {
+        let paddingView = PaddingTextView(top: 0, left: 12, bottom: 0, right: 12)
+        paddingView.translatesAutoresizingMaskIntoConstraints = false
+        paddingView.font = UIFont.preferredFont(for: .body, weight: .regular)
+        return paddingView
     }()
 
     override func setupSubviews() {
         super.setupSubviews()
-        mainContentView.addArrangedSubview(messageLabel)        
+        mainContentView.addArrangedSubview(messageLabel)
     }
 
     override func update(msg: DcMsg, messageStyle: UIRectCorner, isAvatarVisible: Bool, isGroup: Bool) {

+ 26 - 0
deltachat-ios/View/FlexLabel.swift

@@ -55,4 +55,30 @@ class FlexLabel: UIView {
         label.bottomAnchor.constraint(equalTo: layoutMarginsGuide.bottomAnchor).isActive = true
         label.widthAnchor.constraint(lessThanOrEqualTo: widthAnchor, multiplier: 0.95).isActive = true
     }
+
+    ///FIXME: - replace this implementation, it's cutting off long texts, check PaddingTextView
+    class PaddingLabel: UILabel {
+
+        let insets: UIEdgeInsets
+        init(top: CGFloat, left: CGFloat, bottom: CGFloat, right: CGFloat) {
+            self.insets = UIEdgeInsets(top: top, left: left, bottom: bottom, right: right)
+            super.init(frame: .zero)
+        }
+
+        required init?(coder: NSCoder) {
+            fatalError("init(coder:) has not been implemented")
+        }
+
+        override func drawText(in rect: CGRect) {
+            super.drawText(in: rect.inset(by: insets))
+        }
+
+        override var intrinsicContentSize: CGSize {
+            let size = super.intrinsicContentSize
+            return CGSize(
+                width: size.width + insets.left + insets.right,
+                height: size.height + insets.top + insets.bottom
+            )
+        }
+    }
 }

+ 0 - 25
deltachat-ios/View/PaddingLabel.swift

@@ -1,25 +0,0 @@
-import UIKit
-public class PaddingLabel: UILabel {
-    let insets: UIEdgeInsets
-
-    init(top: CGFloat, left: CGFloat, bottom: CGFloat, right: CGFloat) {
-        self.insets = UIEdgeInsets(top: top, left: left, bottom: bottom, right: right)
-        super.init(frame: .zero)
-    }
-
-    required init?(coder: NSCoder) {
-        fatalError("init(coder:) has not been implemented")
-    }
-
-    public override func drawText(in rect: CGRect) {
-        super.drawText(in: rect.inset(by: insets))
-    }
-
-    public override var intrinsicContentSize: CGSize {
-        let size = super.intrinsicContentSize
-        return CGSize(
-            width: size.width + insets.left + insets.right,
-            height: size.height + insets.top + insets.bottom
-        )
-    }
-}

+ 69 - 0
deltachat-ios/View/PaddingTextView.swift

@@ -0,0 +1,69 @@
+import UIKit
+public class PaddingTextView: UIView {
+
+    public lazy var label: UILabel = {
+        let label = UILabel()
+        label.translatesAutoresizingMaskIntoConstraints = false
+        label.numberOfLines = 0
+        label.lineBreakMode = .byWordWrapping
+        return label
+    }()
+
+    let insets: UIEdgeInsets
+
+    public var text: String? {
+        set {
+            label.text = newValue
+        }
+        get {
+            return label.text
+        }
+    }
+
+    public var attributedText: NSAttributedString? {
+        set {
+            label.attributedText = newValue
+        }
+        get {
+            return label.attributedText
+        }
+    }
+
+    public var numberOfLines: Int {
+        set {
+            label.numberOfLines = newValue
+        }
+        get {
+            return label.numberOfLines
+        }
+    }
+
+    public var font: UIFont {
+        set {
+            label.font = newValue
+        }
+        get {
+            return label.font
+        }
+    }
+
+    init(top: CGFloat, left: CGFloat, bottom: CGFloat, right: CGFloat) {
+        self.insets = UIEdgeInsets(top: top, left: left, bottom: bottom, right: right)
+        super.init(frame: .zero)
+        setupView()
+    }
+
+    func setupView() {
+        addSubview(label)
+        addConstraints([
+            label.constraintAlignLeadingTo(self, paddingLeading: insets.left),
+            label.constraintAlignTrailingTo(self, paddingTrailing: insets.right),
+            label.constraintAlignTopTo(self, paddingTop: insets.top),
+            label.constraintAlignBottomTo(self, paddingBottom: insets.bottom)
+        ])
+    }
+
+    required init?(coder: NSCoder) {
+        fatalError("init(coder:) has not been implemented")
+    }
+}