cyberta 5 жил өмнө
parent
commit
f504a4416d

+ 6 - 7
deltachat-ios/MessageKit/Layout/FileMessageSizeCalculator.swift

@@ -12,16 +12,16 @@ open class FileMessageSizeCalculator: MessageSizeCalculator {
         }
         }
     }
     }
 
 
-    public var incomingMessageLabelInsets = UIEdgeInsets(top: 0,
+    private var incomingMessageLabelInsets = UIEdgeInsets(top: 0,
                                                          left: FileMessageCell.insetHorizontalBig,
                                                          left: FileMessageCell.insetHorizontalBig,
                                                          bottom: FileMessageCell.insetBottom,
                                                          bottom: FileMessageCell.insetBottom,
                                                          right: FileMessageCell.insetHorizontalSmall)
                                                          right: FileMessageCell.insetHorizontalSmall)
-    public var outgoingMessageLabelInsets = UIEdgeInsets(top: 0,
+    private var outgoingMessageLabelInsets = UIEdgeInsets(top: 0,
                                                          left: FileMessageCell.insetHorizontalSmall,
                                                          left: FileMessageCell.insetHorizontalSmall,
                                                          bottom: FileMessageCell.insetBottom,
                                                          bottom: FileMessageCell.insetBottom,
                                                          right: FileMessageCell.insetHorizontalBig)
                                                          right: FileMessageCell.insetHorizontalBig)
 
 
-    public var messageLabelFont = UIFont.preferredFont(forTextStyle: .body)
+    private var messageLabelFont = UIFont.preferredFont(forTextStyle: .body)
 
 
     internal func messageLabelInsets(for message: MessageType) -> UIEdgeInsets {
     internal func messageLabelInsets(for message: MessageType) -> UIEdgeInsets {
         let dataSource = messagesLayout.messagesDataSource
         let dataSource = messagesLayout.messagesDataSource
@@ -39,7 +39,7 @@ open class FileMessageSizeCalculator: MessageSizeCalculator {
                     messageContainerSize.height += messageTextHeight + self.messageLabelInsets(for: message).bottom
                     messageContainerSize.height += messageTextHeight + self.messageLabelInsets(for: message).bottom
                 }
                 }
             default:
             default:
-                fatalError("only fileText types can be calculated by FileMessageSizeCalculator")
+                safe_fatalError("only fileText types can be calculated by FileMessageSizeCalculator")
             }
             }
             return messageContainerSize
             return messageContainerSize
         }
         }
@@ -49,7 +49,8 @@ open class FileMessageSizeCalculator: MessageSizeCalculator {
             let maxImageWidth = item.image != nil ? messageContainerMaxWidth(for: message) : defaultFileMessageCellWidth
             let maxImageWidth = item.image != nil ? messageContainerMaxWidth(for: message) : defaultFileMessageCellWidth
             return sizeForMediaItem(maxImageWidth, item)
             return sizeForMediaItem(maxImageWidth, item)
         default:
         default:
-            fatalError("messageContainerSize received unhandled MessageDataType: \(message.kind)")
+            safe_fatalError("messageContainerSize received unhandled MessageDataType: \(message.kind)")
+            return .zero
         }
         }
     }
     }
 
 
@@ -69,6 +70,4 @@ open class FileMessageSizeCalculator: MessageSizeCalculator {
             break
             break
         }
         }
     }
     }
-
-
 }
 }

+ 21 - 18
deltachat-ios/MessageKit/Views/Cells/FileMessageCell.swift

@@ -3,9 +3,9 @@ import UIKit
 // A subclass of `MessageContentCell` used to display mixed media messages.
 // A subclass of `MessageContentCell` used to display mixed media messages.
 open class FileMessageCell: MessageContentCell {
 open class FileMessageCell: MessageContentCell {
 
 
-    public static let insetBottom: CGFloat = 12
-    public static let insetHorizontalBig: CGFloat = 23
-    public static let insetHorizontalSmall: CGFloat = 12
+    static let insetBottom: CGFloat = 12
+    static let insetHorizontalBig: CGFloat = 23
+    static let insetHorizontalSmall: CGFloat = 12
 
 
     // MARK: - Properties
     // MARK: - Properties
     var fileViewLeadingPadding: CGFloat = 0 {
     var fileViewLeadingPadding: CGFloat = 0 {
@@ -18,7 +18,6 @@ open class FileMessageCell: MessageContentCell {
         return fileView.constraintAlignLeadingTo(messageContainerView, paddingLeading: 0)
         return fileView.constraintAlignLeadingTo(messageContainerView, paddingLeading: 0)
     }()
     }()
 
 
-
     /// The `MessageCellDelegate` for the cell.
     /// The `MessageCellDelegate` for the cell.
     open override weak var delegate: MessageCellDelegate? {
     open override weak var delegate: MessageCellDelegate? {
         didSet {
         didSet {
@@ -29,8 +28,12 @@ open class FileMessageCell: MessageContentCell {
     /// The label used to display the message's text.
     /// The label used to display the message's text.
     open var messageLabel = MessageLabel()
     open var messageLabel = MessageLabel()
 
 
-    lazy var fileView: FileView = {
-        let fileView = FileView()
+    private lazy var fileView: FileView = {
+        let marginInsets = NSDirectionalEdgeInsets(top: FileMessageCell.insetHorizontalSmall,
+                                                   leading: FileMessageCell.insetHorizontalSmall,
+                                                   bottom: FileMessageCell.insetHorizontalSmall,
+                                                   trailing: FileMessageCell.insetHorizontalSmall)
+        let fileView = FileView(directionalLayoutMargins: marginInsets)
         fileView.translatesAutoresizingMaskIntoConstraints = false
         fileView.translatesAutoresizingMaskIntoConstraints = false
         return fileView
         return fileView
     }()
     }()
@@ -54,7 +57,7 @@ open class FileMessageCell: MessageContentCell {
                                     height: getMessageLabelHeight())
                                     height: getMessageLabelHeight())
     }
     }
 
 
-    func getMessageLabelHeight() -> CGFloat {
+    private func getMessageLabelHeight() -> CGFloat {
         if let text = messageLabel.attributedText, !text.string.isEmpty {
         if let text = messageLabel.attributedText, !text.string.isEmpty {
             let height = (text.height(withConstrainedWidth:
             let height = (text.height(withConstrainedWidth:
                 messageContainerView.frame.width -
                 messageContainerView.frame.width -
@@ -108,22 +111,22 @@ open class FileMessageCell: MessageContentCell {
         setupConstraints(for: message.kind)
         setupConstraints(for: message.kind)
     }
     }
 
 
-    func configureFileView(for mediaItem: MediaItem) {
+    private func configureFileView(for mediaItem: MediaItem) {
         fileView.configureFor(mediaItem: mediaItem)
         fileView.configureFor(mediaItem: mediaItem)
     }
     }
 
 
-    func configureMessageLabel(for mediaItem: MediaItem,
-                               with displayDelegate: MessagesDisplayDelegate,
-                               message: MessageType,
-                               at indexPath: IndexPath,
-                               in messagesCollectionView: MessagesCollectionView) {
+    private func configureMessageLabel(for mediaItem: MediaItem,
+                                       with displayDelegate: MessagesDisplayDelegate,
+                                       message: MessageType,
+                                       at indexPath: IndexPath,
+                                       in messagesCollectionView: MessagesCollectionView) {
         let enabledDetectors = displayDelegate.enabledDetectors(for: message, at: indexPath, in: messagesCollectionView)
         let enabledDetectors = displayDelegate.enabledDetectors(for: message, at: indexPath, in: messagesCollectionView)
         messageLabel.configure {
         messageLabel.configure {
-           messageLabel.enabledDetectors = enabledDetectors
-           for detector in enabledDetectors {
-               let attributes = displayDelegate.detectorAttributes(for: detector, and: message, at: indexPath)
-               messageLabel.setAttributes(attributes, detector: detector)
-           }
+            messageLabel.enabledDetectors = enabledDetectors
+            for detector in enabledDetectors {
+                let attributes = displayDelegate.detectorAttributes(for: detector, and: message, at: indexPath)
+                messageLabel.setAttributes(attributes, detector: detector)
+            }
             messageLabel.attributedText = mediaItem.text?[MediaItemConstants.messageText]
             messageLabel.attributedText = mediaItem.text?[MediaItemConstants.messageText]
         }
         }
     }
     }

+ 2 - 5
deltachat-ios/MessageKit/Views/FileView.swift

@@ -36,16 +36,13 @@ class FileView: UIView {
         stackView.axis = .vertical
         stackView.axis = .vertical
         stackView.alignment = .leading
         stackView.alignment = .leading
         stackView.isLayoutMarginsRelativeArrangement = true
         stackView.isLayoutMarginsRelativeArrangement = true
-        stackView.directionalLayoutMargins = NSDirectionalEdgeInsets(top: FileMessageCell.insetHorizontalSmall,
-                                                                     leading: FileMessageCell.insetHorizontalSmall,
-                                                                     bottom: FileMessageCell.insetHorizontalSmall,
-                                                                     trailing: FileMessageCell.insetHorizontalSmall)
         return stackView
         return stackView
     }()
     }()
 
 
-    init() {
+    init(directionalLayoutMargins: NSDirectionalEdgeInsets) {
         super.init(frame: .zero)
         super.init(frame: .zero)
         translatesAutoresizingMaskIntoConstraints = false
         translatesAutoresizingMaskIntoConstraints = false
+        verticalStackView.directionalLayoutMargins = directionalLayoutMargins
         addSubview(fileBadgeView)
         addSubview(fileBadgeView)
         addSubview(verticalStackView)
         addSubview(verticalStackView)
         addConstraints([
         addConstraints([