Browse Source

move EmptyStateLabel and FlexLabel to DcCore b/c they will be reused

cyberta 4 years ago
parent
commit
003c862876

+ 8 - 0
DcCore/DcCore.xcodeproj/project.pbxproj

@@ -28,6 +28,8 @@
 		30E8F2482449C98600CE2C90 /* UIView+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30E8F2472449C98600CE2C90 /* UIView+Extensions.swift */; };
 		30E8F24B2449CF6500CE2C90 /* InitialsBadge.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30E8F24A2449CF6500CE2C90 /* InitialsBadge.swift */; };
 		30E8F24D2449D30200CE2C90 /* DcColors.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30E8F24C2449D30200CE2C90 /* DcColors.swift */; };
+		30FE253324BF2688005AC669 /* EmptyStateLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30FE253124BF2688005AC669 /* EmptyStateLabel.swift */; };
+		30FE253424BF2688005AC669 /* FlexLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30FE253224BF2688005AC669 /* FlexLabel.swift */; };
 /* End PBXBuildFile section */
 
 /* Begin PBXContainerItemProxy section */
@@ -65,6 +67,8 @@
 		30E8F2472449C98600CE2C90 /* UIView+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIView+Extensions.swift"; sourceTree = "<group>"; };
 		30E8F24A2449CF6500CE2C90 /* InitialsBadge.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InitialsBadge.swift; sourceTree = "<group>"; };
 		30E8F24C2449D30200CE2C90 /* DcColors.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DcColors.swift; sourceTree = "<group>"; };
+		30FE253124BF2688005AC669 /* EmptyStateLabel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EmptyStateLabel.swift; sourceTree = "<group>"; };
+		30FE253224BF2688005AC669 /* FlexLabel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FlexLabel.swift; sourceTree = "<group>"; };
 /* End PBXFileReference section */
 
 /* Begin PBXFrameworksBuildPhase section */
@@ -177,6 +181,8 @@
 		30E8F2492449CF2F00CE2C90 /* Views */ = {
 			isa = PBXGroup;
 			children = (
+				30FE253124BF2688005AC669 /* EmptyStateLabel.swift */,
+				30FE253224BF2688005AC669 /* FlexLabel.swift */,
 				30E8F24A2449CF6500CE2C90 /* InitialsBadge.swift */,
 			);
 			path = Views;
@@ -314,6 +320,7 @@
 			isa = PBXSourcesBuildPhase;
 			buildActionMask = 2147483647;
 			files = (
+				30FE253324BF2688005AC669 /* EmptyStateLabel.swift in Sources */,
 				30421988243F23E500516852 /* Constants.swift in Sources */,
 				30E8F24D2449D30200CE2C90 /* DcColors.swift in Sources */,
 				30421962243E26C800516852 /* Logger.swift in Sources */,
@@ -328,6 +335,7 @@
 				30421960243E257100516852 /* UIColor+Extensions.swift in Sources */,
 				30E8F2482449C98600CE2C90 /* UIView+Extensions.swift in Sources */,
 				308198AB24866229003BE20D /* UserDefaults+Extensions.swift in Sources */,
+				30FE253424BF2688005AC669 /* FlexLabel.swift in Sources */,
 				304F5E41244F2F3200462538 /* UIImage+Extensions.swift in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;

+ 39 - 0
DcCore/DcCore/Views/EmptyStateLabel.swift

@@ -0,0 +1,39 @@
+import UIKit
+
+public class EmptyStateLabel: FlexLabel {
+
+    public override var text: String? {
+        set {
+            guard let newValue = newValue else {
+                super.label.attributedText = nil
+                return
+            }
+
+            guard let style = NSMutableParagraphStyle.default.mutableCopy() as? NSMutableParagraphStyle else {
+                label.attributedText = NSAttributedString(string: newValue)
+                return
+            }
+            style.alignment = NSTextAlignment.natural
+            style.lineBreakMode = .byWordWrapping
+            attributedText = NSAttributedString(
+                string: newValue,
+                attributes: [.paragraphStyle: style]
+            )
+        }
+        get {
+            return super.label.text
+        }
+    }
+
+    public override init() {
+        super.init()
+        label.backgroundColor = DcColors.systemMessageBackgroundColor
+        label.textColor = DcColors.defaultTextColor
+        label.layer.cornerRadius = 10
+        label.clipsToBounds = true
+    }
+
+    required init?(coder: NSCoder) {
+        fatalError("init(coder:) has not been implemented")
+    }
+}

+ 83 - 0
DcCore/DcCore/Views/FlexLabel.swift

@@ -0,0 +1,83 @@
+import UIKit
+
+/// view that contains a label (horizontally centered) and
+/// allows it's label to grow/shrink within it's available space
+public class FlexLabel: UIView {
+
+    var text: String? {
+        set {
+            label.text = newValue
+        }
+        get {
+            return label.text
+        }
+    }
+
+    var textColor: UIColor {
+        set {
+            label.textColor = newValue
+        }
+        get {
+            return label.textColor
+        }
+    }
+
+    var attributedText: NSAttributedString? {
+        set {
+            label.attributedText = newValue
+        }
+        get {
+            return label.attributedText
+        }
+    }
+
+    lazy var label: UILabel = {
+        let label = PaddingLabel(top: 15, left: 15, bottom: 15, right: 15)
+        label.numberOfLines = 0
+        return label
+    }()
+
+    init() {
+        super.init(frame: .zero)
+        setupSubviews()
+    }
+
+    required init?(coder: NSCoder) {
+        fatalError("init(coder:) has not been implemented")
+    }
+
+    private func setupSubviews() {
+        addSubview(label)
+        label.translatesAutoresizingMaskIntoConstraints = false
+        label.centerYAnchor.constraint(equalTo: centerYAnchor, constant: 0).isActive = true
+        label.centerXAnchor.constraint(equalTo: centerXAnchor, constant: 0).isActive = true
+        label.topAnchor.constraint(equalTo: layoutMarginsGuide.topAnchor).isActive = true
+        label.bottomAnchor.constraint(equalTo: layoutMarginsGuide.bottomAnchor).isActive = true
+        label.widthAnchor.constraint(lessThanOrEqualTo: widthAnchor, multiplier: 0.95).isActive = true
+    }
+
+    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 - 0
deltachat-ios/View/EmptyStateLabel.swift → DcShare/View/EmptyStateLabel.swift


+ 0 - 0
deltachat-ios/View/FlexLabel.swift → DcShare/View/FlexLabel.swift


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

@@ -88,7 +88,6 @@
 		3059620C2346125100C80F33 /* MessageSizeCalculator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 305961CB2346125100C80F33 /* MessageSizeCalculator.swift */; };
 		3059620E234614E700C80F33 /* DcContact+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3059620D234614E700C80F33 /* DcContact+Extension.swift */; };
 		305962102346154D00C80F33 /* String+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3059620F2346154D00C80F33 /* String+Extension.swift */; };
-		305FE03623A81B4C0053BE90 /* EmptyStateLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 305FE03523A81B4C0053BE90 /* EmptyStateLabel.swift */; };
 		3060119C22DDE24000C1CE6F /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 3060119E22DDE24000C1CE6F /* Localizable.strings */; };
 		306011B622E5E7FB00C1CE6F /* Localizable.stringsdict in Resources */ = {isa = PBXBuildFile; fileRef = 306011B422E5E7FB00C1CE6F /* Localizable.stringsdict */; };
 		306C32322445CDE9001D89F3 /* DcLogger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 306C32312445CDE9001D89F3 /* DcLogger.swift */; };
@@ -166,7 +165,6 @@
 		AEACE2DF1FB3246400DCDD78 /* Message.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEACE2DE1FB3246400DCDD78 /* Message.swift */; };
 		AEACE2E31FB32B5C00DCDD78 /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEACE2E21FB32B5C00DCDD78 /* Constants.swift */; };
 		AEACE2E51FB32E1900DCDD78 /* Utils.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEACE2E41FB32E1900DCDD78 /* Utils.swift */; };
-		AEB54C7F246DBA610004624C /* FlexLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEB54C7E246DBA610004624C /* FlexLabel.swift */; };
 		AEC67A1C241CE9E4007DDBE1 /* AppStateRestorer.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEC67A1B241CE9E4007DDBE1 /* AppStateRestorer.swift */; };
 		AEC67A1E241FCFE0007DDBE1 /* ChatListViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEC67A1D241FCFE0007DDBE1 /* ChatListViewModel.swift */; };
 		AECEF03E244F2D55006C90DA /* QrPageController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AECEF03D244F2D55006C90DA /* QrPageController.swift */; };
@@ -1430,7 +1428,6 @@
 				7A0052C81FBE6CB40048C3BF /* NewContactController.swift in Sources */,
 				AEE56D762253431E007DC082 /* AccountSetupController.swift in Sources */,
 				AE8F503524753DFE007FEE0B /* GalleryViewController.swift in Sources */,
-				305FE03623A81B4C0053BE90 /* EmptyStateLabel.swift in Sources */,
 				AEACE2DD1FB323CA00DCDD78 /* ChatViewController.swift in Sources */,
 				AEE6EC412282DF5700EDC689 /* MailboxViewController.swift in Sources */,
 				AEF53BD5248904BF00D309C1 /* GalleryTimeLabel.swift in Sources */,
@@ -1496,7 +1493,6 @@
 				305961F12346125100C80F33 /* ContactMessageCell.swift in Sources */,
 				AE851AD0227DF50900ED86F0 /* GroupChatDetailViewController.swift in Sources */,
 				305961D12346125100C80F33 /* Bundle+Extensions.swift in Sources */,
-				AEB54C7F246DBA610004624C /* FlexLabel.swift in Sources */,
 				305962002346125100C80F33 /* MessagesCollectionView.swift in Sources */,
 				7A451DB01FB1F84900177250 /* AppCoordinator.swift in Sources */,
 				AE38B31822672DFC00EC37A1 /* ActionCell.swift in Sources */,