浏览代码

fix some lint issues

cyberta 5 年之前
父节点
当前提交
1d2c267fa5

+ 1 - 1
deltachat-ios/Extensions/UIView+Extensions.swift

@@ -171,7 +171,7 @@ internal extension UIView {
     }
 
     @discardableResult
-    internal func addConstraints(_ top: NSLayoutYAxisAnchor? = nil, left: NSLayoutXAxisAnchor? = nil, bottom: NSLayoutYAxisAnchor? = nil, right: NSLayoutXAxisAnchor? = nil, centerY: NSLayoutYAxisAnchor? = nil, centerX: NSLayoutXAxisAnchor? = nil, topConstant: CGFloat = 0, leftConstant: CGFloat = 0, bottomConstant: CGFloat = 0, rightConstant: CGFloat = 0, centerYConstant: CGFloat = 0, centerXConstant: CGFloat = 0, widthConstant: CGFloat = 0, heightConstant: CGFloat = 0) -> [NSLayoutConstraint] {
+    func addConstraints(_ top: NSLayoutYAxisAnchor? = nil, left: NSLayoutXAxisAnchor? = nil, bottom: NSLayoutYAxisAnchor? = nil, right: NSLayoutXAxisAnchor? = nil, centerY: NSLayoutYAxisAnchor? = nil, centerX: NSLayoutXAxisAnchor? = nil, topConstant: CGFloat = 0, leftConstant: CGFloat = 0, bottomConstant: CGFloat = 0, rightConstant: CGFloat = 0, centerYConstant: CGFloat = 0, centerXConstant: CGFloat = 0, widthConstant: CGFloat = 0, heightConstant: CGFloat = 0) -> [NSLayoutConstraint] {
 
         if self.superview == nil {
             return []

+ 13 - 7
deltachat-ios/MessageKit/Controllers/MessagesViewController+Keyboard.swift

@@ -29,13 +29,19 @@ internal extension MessagesViewController {
 
     // MARK: - Register / Unregister Observers
 
-    internal func addKeyboardObservers() {
-        NotificationCenter.default.addObserver(self, selector: #selector(MessagesViewController.handleKeyboardDidChangeState(_:)), name: UIResponder.keyboardWillChangeFrameNotification, object: nil)
-        NotificationCenter.default.addObserver(self, selector: #selector(MessagesViewController.handleTextViewDidBeginEditing(_:)), name: UITextView.textDidBeginEditingNotification, object: nil)
-        NotificationCenter.default.addObserver(self, selector: #selector(MessagesViewController.adjustScrollViewTopInset), name: UIDevice.orientationDidChangeNotification, object: nil)
+    func addKeyboardObservers() {
+        NotificationCenter.default.addObserver(self,
+                                               selector: #selector(MessagesViewController.handleKeyboardDidChangeState(_:)),
+                                               name: UIResponder.keyboardWillChangeFrameNotification, object: nil)
+        NotificationCenter.default.addObserver(self,
+                                               selector: #selector(MessagesViewController.handleTextViewDidBeginEditing(_:)),
+                                               name: UITextView.textDidBeginEditingNotification, object: nil)
+        NotificationCenter.default.addObserver(self,
+                                               selector: #selector(MessagesViewController.adjustScrollViewTopInset),
+                                               name: UIDevice.orientationDidChangeNotification, object: nil)
     }
 
-    internal func removeKeyboardObservers() {
+    func removeKeyboardObservers() {
         NotificationCenter.default.removeObserver(self, name: UIResponder.keyboardWillChangeFrameNotification, object: nil)
         NotificationCenter.default.removeObserver(self, name: UITextView.textDidBeginEditingNotification, object: nil)
         NotificationCenter.default.removeObserver(self, name: UIDevice.orientationDidChangeNotification, object: nil)
@@ -95,7 +101,7 @@ internal extension MessagesViewController {
     // MARK: - Inset Computation
 
     @objc
-    internal func adjustScrollViewTopInset() {
+    func adjustScrollViewTopInset() {
         if #available(iOS 11.0, *) {
             // No need to add to the top contentInset
         } else {
@@ -121,7 +127,7 @@ internal extension MessagesViewController {
         }
     }
 
-    internal func requiredInitialScrollViewBottomInset() -> CGFloat {
+    func requiredInitialScrollViewBottomInset() -> CGFloat {
         guard let inputAccessoryView = inputAccessoryView else { return 0 }
         return max(0, inputAccessoryView.frame.height + additionalBottomInset - automaticallyAddedBottomInset)
     }

+ 10 - 5
deltachat-ios/MessageKit/Controllers/MessagesViewController+Menu.swift

@@ -29,11 +29,13 @@ internal extension MessagesViewController {
 
     // MARK: - Register / Unregister Observers
 
-    internal func addMenuControllerObservers() {
-        NotificationCenter.default.addObserver(self, selector: #selector(MessagesViewController.menuControllerWillShow(_:)), name: UIMenuController.willShowMenuNotification, object: nil)
+    func addMenuControllerObservers() {
+        NotificationCenter.default.addObserver(self,
+                                               selector: #selector(MessagesViewController.menuControllerWillShow(_:)),
+                                               name: UIMenuController.willShowMenuNotification, object: nil)
     }
 
-    internal func removeMenuControllerObservers() {
+    func removeMenuControllerObservers() {
         NotificationCenter.default.removeObserver(self, name: UIMenuController.willShowMenuNotification, object: nil)
     }
 
@@ -81,8 +83,11 @@ internal extension MessagesViewController {
         currentMenuController.arrowDirection = .default
 
         /// Message bubble intersects with navigationBar and keyboard
-        if selectedCellMessageBubblePlusMenuFrame.intersects(topNavigationBarFrame) && selectedCellMessageBubblePlusMenuFrame.intersects(messageInputBarFrame) {
-            let centerY = (selectedCellMessageBubblePlusMenuFrame.intersection(messageInputBarFrame).minY + selectedCellMessageBubblePlusMenuFrame.intersection(topNavigationBarFrame).maxY) / 2
+        if selectedCellMessageBubblePlusMenuFrame.intersects(topNavigationBarFrame) &&
+            selectedCellMessageBubblePlusMenuFrame.intersects(messageInputBarFrame) {
+
+            let centerY = (selectedCellMessageBubblePlusMenuFrame.intersection(messageInputBarFrame).minY +
+                selectedCellMessageBubblePlusMenuFrame.intersection(topNavigationBarFrame).maxY) / 2
             targetRect = CGRect(selectedCellMessageBubblePlusMenuFrame.midX, centerY, 1, 1)
         } /// Message bubble only intersects with navigationBar
         else if selectedCellMessageBubblePlusMenuFrame.intersects(topNavigationBarFrame) {

+ 4 - 2
deltachat-ios/MessageKit/Controllers/MessagesViewController.swift

@@ -145,7 +145,9 @@ UICollectionViewDelegateFlowLayout, UICollectionViewDataSource {
 
     private func setupDefaults() {
         extendedLayoutIncludesOpaqueBars = true
-        automaticallyAdjustsScrollViewInsets = false
+        if #available(iOS 11.0, *) {} else {
+            automaticallyAdjustsScrollViewInsets = false
+        }
         view.backgroundColor = .white
         messagesCollectionView.keyboardDismissMode = .interactive
         messagesCollectionView.alwaysBounceVertical = true
@@ -162,7 +164,7 @@ UICollectionViewDelegateFlowLayout, UICollectionViewDataSource {
 
     private func setupConstraints() {
         messagesCollectionView.translatesAutoresizingMaskIntoConstraints = false
-        
+
         let top = messagesCollectionView.topAnchor.constraint(equalTo: view.topAnchor, constant: topLayoutGuide.length)
         let bottom = messagesCollectionView.bottomAnchor.constraint(equalTo: view.bottomAnchor)
         if #available(iOS 11.0, *) {

+ 4 - 1
deltachat-ios/MessageKit/Layout/MessagesCollectionViewFlowLayout.swift

@@ -89,7 +89,10 @@ open class MessagesCollectionViewFlowLayout: UICollectionViewFlowLayout {
     }
     
     private func setupObserver() {
-        NotificationCenter.default.addObserver(self, selector: #selector(MessagesCollectionViewFlowLayout.handleOrientationChange(_:)), name: UIDevice.orientationDidChangeNotification, object: nil)
+        NotificationCenter.default.addObserver(self,
+                                               selector: #selector(MessagesCollectionViewFlowLayout.handleOrientationChange(_:)),
+                                               name: UIDevice.orientationDidChangeNotification,
+                                               object: nil)
     }
 
     // MARK: - Typing Indicator API

+ 1 - 1
deltachat-ios/MessageKit/Models/HorizontalEdgeInsets.swift

@@ -50,7 +50,7 @@ public extension HorizontalEdgeInsets {
 
 internal extension HorizontalEdgeInsets {
 
-    internal var horizontal: CGFloat {
+    var horizontal: CGFloat {
         return left + right
     }
 }

+ 0 - 1
deltachat-ios/MessageKit/Protocols/MessagesLayoutDelegate.swift

@@ -162,4 +162,3 @@ public extension MessagesLayoutDelegate {
         fatalError("Must return a CellSizeCalculator for MessageKind.custom(Any?)")
     }
 }
-

+ 5 - 1
deltachat-ios/MessageKit/Views/AvatarView.swift

@@ -122,7 +122,11 @@ open class AvatarView: UIImageView {
                                                             context: nil).height
         context.saveGState()
         context.clip(to: textRect)
-        initials.draw(in: CGRect(textRect.minX, textRect.minY + (textRect.height - textTextHeight) / 2, textRect.width, textTextHeight), withAttributes: textFontAttributes)
+        initials.draw(in: CGRect(textRect.minX,
+                                 textRect.minY + (textRect.height - textTextHeight) / 2,
+                                 textRect.width,
+                                 textTextHeight),
+                      withAttributes: textFontAttributes)
         context.restoreGState()
         guard let renderedImage = UIGraphicsGetImageFromCurrentImageContext() else { assertionFailure("Could not create image from context"); return UIImage()}
         return renderedImage

+ 9 - 2
deltachat-ios/MessageKit/Views/Cells/AudioMessageCell.swift

@@ -60,7 +60,11 @@ open class AudioMessageCell: MessageContentCell {
         playButton.constraint(equalTo: CGSize(width: 25, height: 25))
         playButton.addConstraints(left: messageContainerView.leftAnchor, centerY: messageContainerView.centerYAnchor, leftConstant: 5)
         durationLabel.addConstraints(right: messageContainerView.rightAnchor, centerY: messageContainerView.centerYAnchor, rightConstant: 15)
-        progressView.addConstraints(left: playButton.rightAnchor, right: durationLabel.leftAnchor, centerY: messageContainerView.centerYAnchor, leftConstant: 5, rightConstant: 5)
+        progressView.addConstraints(left: playButton.rightAnchor,
+                                    right: durationLabel.leftAnchor,
+                                    centerY: messageContainerView.centerYAnchor,
+                                    leftConstant: 5,
+                                    rightConstant: 5)
     }
 
     open override func setupSubviews() {
@@ -83,7 +87,10 @@ open class AudioMessageCell: MessageContentCell {
         let touchLocation = gesture.location(in: self)
         // compute play button touch area, currently play button size is (25, 25) which is hardly touchable
         // add 10 px around current button frame and test the touch against this new frame
-        let playButtonTouchArea = CGRect(playButton.frame.origin.x - 10.0, playButton.frame.origin.y - 10, playButton.frame.size.width + 20, playButton.frame.size.height + 20)
+        let playButtonTouchArea = CGRect(playButton.frame.origin.x - 10.0,
+                                         playButton.frame.origin.y - 10,
+                                         playButton.frame.size.width + 20,
+                                         playButton.frame.size.height + 20)
         let translateTouchLocation = convert(touchLocation, to: messageContainerView)
         if playButtonTouchArea.contains(translateTouchLocation) {
             delegate?.didTapPlayButton(in: self)

+ 5 - 1
deltachat-ios/MessageKit/Views/Cells/MessageContentCell.swift

@@ -261,7 +261,11 @@ open class MessageContentCell: MessageCollectionViewCell {
         case .cellLeading:
             origin.x = attributes.avatarSize.width + attributes.messageContainerPadding.left + avatarPadding
         case .cellTrailing:
-            origin.x = attributes.frame.width - attributes.avatarSize.width - attributes.messageContainerSize.width - attributes.messageContainerPadding.right - avatarPadding
+            origin.x = attributes.frame.width -
+                       attributes.avatarSize.width -
+                       attributes.messageContainerSize.width -
+                       attributes.messageContainerPadding.right -
+                       avatarPadding
         case .natural:
             fatalError(MessageKitError.avatarPositionUnresolved)
         }

+ 1 - 1
deltachat-ios/MessageKit/Views/MessageLabel.swift

@@ -461,7 +461,7 @@ open class MessageLabel: UILabel {
         return false
     }
 
-    // swiftlint:disable cyclomatic_complexity
+    /// swiftlint:disable cyclomatic_complexity
     private func handleGesture(for detectorType: DetectorType, value: MessageTextCheckingType) {
         switch value {
         case let .addressComponents(addressComponents):

+ 6 - 2
deltachat-ios/MessageKit/Views/MessagesCollectionView.swift

@@ -177,7 +177,9 @@ open class MessagesCollectionView: UICollectionView {
 
     /// Generically dequeues a header of the correct type allowing you to avoid scattering your code with guard-let-else-fatal
     public func dequeueReusableHeaderView<T: UICollectionReusableView>(_ viewClass: T.Type, for indexPath: IndexPath) -> T {
-        let view = dequeueReusableSupplementaryView(ofKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: String(describing: T.self), for: indexPath)
+        let view = dequeueReusableSupplementaryView(ofKind: UICollectionView.elementKindSectionHeader,
+                                                    withReuseIdentifier: String(describing: T.self),
+                                                    for: indexPath)
         guard let viewType = view as? T else {
             fatalError("Unable to dequeue \(String(describing: viewClass)) with reuseId of \(String(describing: T.self))")
         }
@@ -186,7 +188,9 @@ open class MessagesCollectionView: UICollectionView {
 
     /// Generically dequeues a footer of the correct type allowing you to avoid scattering your code with guard-let-else-fatal
     public func dequeueReusableFooterView<T: UICollectionReusableView>(_ viewClass: T.Type, for indexPath: IndexPath) -> T {
-        let view = dequeueReusableSupplementaryView(ofKind: UICollectionView.elementKindSectionFooter, withReuseIdentifier: String(describing: T.self), for: indexPath)
+        let view = dequeueReusableSupplementaryView(ofKind: UICollectionView.elementKindSectionFooter,
+                                                    withReuseIdentifier: String(describing: T.self),
+                                                    for: indexPath)
         guard let viewType = view as? T else {
             fatalError("Unable to dequeue \(String(describing: viewClass)) with reuseId of \(String(describing: T.self))")
         }

+ 0 - 1
deltachat-ios/MessageKit/Views/TypingBubble.swift

@@ -23,7 +23,6 @@
  */
 
 import UIKit
-import UIKit
 
 /// A subclass of `UIView` that mimics the iMessage typing bubble
 open class TypingBubble: UIView {