From 485396b62da9307092662887d4af71d31781e388 Mon Sep 17 00:00:00 2001 From: Nathan Tannar Date: Tue, 25 Sep 2018 22:17:52 -0700 Subject: [PATCH 1/9] Update Tests to match new style --- Tests/InputTextViewTests.swift | 5 +---- Tests/MessageInputBarTests.swift | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/Tests/InputTextViewTests.swift b/Tests/InputTextViewTests.swift index f700adb..7ec31b5 100644 --- a/Tests/InputTextViewTests.swift +++ b/Tests/InputTextViewTests.swift @@ -80,11 +80,8 @@ class InputTextViewTests: XCTestCase { func testSetup() { textView.setup() XCTAssertEqual(textView.font, UIFont.preferredFont(forTextStyle: .body)) - XCTAssertEqual(textView.textContainerInset, UIEdgeInsets(top: 4, left: 4, bottom: 4, right: 4)) + XCTAssertEqual(textView.textContainerInset, UIEdgeInsets(top: 8, left: 0, bottom: 8, right: 0)) XCTAssertFalse(textView.isScrollEnabled) - XCTAssertEqual(textView.layer.cornerRadius, 5.0) - XCTAssertEqual(textView.layer.borderWidth, 1.25) - XCTAssertEqual(textView.layer.borderColor, UIColor.lightGray.cgColor) XCTAssertTrue(textView.subviews.contains(textView.placeholderLabel)) } diff --git a/Tests/MessageInputBarTests.swift b/Tests/MessageInputBarTests.swift index cc72105..43b31b5 100644 --- a/Tests/MessageInputBarTests.swift +++ b/Tests/MessageInputBarTests.swift @@ -114,7 +114,7 @@ class MessageInputBarTests: XCTestCase { } func testSendButtonFont_isHeadlineAfterInit() { - XCTAssertEqual(sut.sendButton.titleLabel?.font, UIFont.preferredFont(forTextStyle: .headline)) + XCTAssertEqual(sut.sendButton.titleLabel?.font, UIFont.systemFont(ofSize: 15, weight: .bold)) } } From 86a4ef3ae7ca4b96c9cd059c3a177429e696358c Mon Sep 17 00:00:00 2001 From: Nathan Tannar Date: Tue, 25 Sep 2018 22:36:34 -0700 Subject: [PATCH 2/9] Revert InputTextView Placeholder label layout --- Sources/Views/InputTextView.swift | 33 +++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/Sources/Views/InputTextView.swift b/Sources/Views/InputTextView.swift index 9a8bce2..74fb17e 100644 --- a/Sources/Views/InputTextView.swift +++ b/Sources/Views/InputTextView.swift @@ -88,7 +88,7 @@ open class InputTextView: UITextView { /// The `UIEdgeInsets` the placeholderLabel has within the `InputTextView` open var placeholderLabelInsets: UIEdgeInsets = UIEdgeInsets(top: 4, left: 4, bottom: 4, right: 4) { didSet { - layoutSubviews() + updateConstraintsForPlaceholderLabel() } } @@ -163,9 +163,26 @@ open class InputTextView: UITextView { left: .leastNonzeroMagnitude, bottom: .leastNonzeroMagnitude, right: .leastNonzeroMagnitude) - addSubview(placeholderLabel) + setupPlaceholderLabel() setupObservers() } + + /// Adds the placeholderLabel to the view and sets up its initial constraints + private func setupPlaceholderLabel() { + + addSubview(placeholderLabel) + placeholderLabelConstraintSet = NSLayoutConstraintSet( + top: placeholderLabel.topAnchor.constraint(equalTo: topAnchor, constant: placeholderLabelInsets.top), + bottom: placeholderLabel.bottomAnchor.constraint(equalTo: bottomAnchor, constant: -placeholderLabelInsets.bottom), + left: placeholderLabel.leftAnchor.constraint(equalTo: leftAnchor, constant: placeholderLabelInsets.left), + right: placeholderLabel.rightAnchor.constraint(equalTo: rightAnchor, constant: -placeholderLabelInsets.right), + centerX: placeholderLabel.centerXAnchor.constraint(equalTo: centerXAnchor), + centerY: placeholderLabel.centerYAnchor.constraint(equalTo: centerYAnchor) + ) + placeholderLabelConstraintSet?.centerX?.priority = .defaultLow + placeholderLabelConstraintSet?.centerY?.priority = .defaultLow + placeholderLabelConstraintSet?.activate() + } /// Adds the required notification observers private func setupObservers() { @@ -178,12 +195,16 @@ open class InputTextView: UITextView { name: .UITextViewTextDidChange, object: nil) } - /// Layout subviews based on edge insets - open override func layoutSubviews() { - super.layoutSubviews() - placeholderLabel.frame = UIEdgeInsetsInsetRect(bounds, placeholderLabelInsets) + /// Updates the placeholderLabels constraint constants to match the placeholderLabelInsets + private func updateConstraintsForPlaceholderLabel() { + + placeholderLabelConstraintSet?.top?.constant = placeholderLabelInsets.top + placeholderLabelConstraintSet?.bottom?.constant = -placeholderLabelInsets.bottom + placeholderLabelConstraintSet?.left?.constant = placeholderLabelInsets.left + placeholderLabelConstraintSet?.right?.constant = -placeholderLabelInsets.right } + // MARK: - Notification private func postTextViewDidChangeNotification() { From a8495249cc38adfb05b03bdba82dcce020ab889c Mon Sep 17 00:00:00 2001 From: Nathan Tannar Date: Sat, 29 Sep 2018 11:59:57 -0700 Subject: [PATCH 3/9] Fix issues discovered in InputBarAccessoryView --- Plugins/AutocompleteManager/AutocompleteManager.swift | 3 +++ Sources/MessageInputBar.swift | 1 + 2 files changed, 4 insertions(+) diff --git a/Plugins/AutocompleteManager/AutocompleteManager.swift b/Plugins/AutocompleteManager/AutocompleteManager.swift index 0dc5258..08f7e8a 100755 --- a/Plugins/AutocompleteManager/AutocompleteManager.swift +++ b/Plugins/AutocompleteManager/AutocompleteManager.swift @@ -312,6 +312,9 @@ open class AutocompleteManager: NSObject, InputPlugin, UITextViewDelegate, UITab if appendSpaceOnCompletion { newAttributedText.append(NSAttributedString(string: " ", attributes: typingTextAttributes)) } + // Set to blank string to stop system autocomplete from clobbering replacement + textView.attributedText = NSAttributedString() + textView.attributedText = newAttributedText } diff --git a/Sources/MessageInputBar.swift b/Sources/MessageInputBar.swift index fed6566..4761be9 100644 --- a/Sources/MessageInputBar.swift +++ b/Sources/MessageInputBar.swift @@ -484,6 +484,7 @@ open class MessageInputBar: UIView { textViewHeightAnchor?.isActive = true inputTextView.isScrollEnabled = true isOverMaxTextViewHeight = true + inputTextView.layoutIfNeeded() } inputTextViewHeight = maxTextViewHeight } else { From e3a52aec45e4bbfa7fe8e2b8b2371607e16a093f Mon Sep 17 00:00:00 2001 From: Nathan Tannar Date: Tue, 25 Sep 2018 22:30:32 -0700 Subject: [PATCH 4/9] Convert to Swift 4.2 --- .swift-version | 2 +- Example/Example.xcodeproj/project.pbxproj | 4 ++-- Example/Example/AppDelegate.swift | 4 +--- Example/Example/ExampleViewController.swift | 4 ++-- .../Example/Style Examples/SlackInputBar.swift | 4 ++-- Example/Example/TableViewController.swift | 2 +- Example/Podfile.lock | 12 ++++++------ MessageInputBar.podspec | 4 ++-- MessageInputBar.xcodeproj/project.pbxproj | 8 ++++---- .../AttachmentManager/Views/AttachmentCell.swift | 2 +- .../Views/ImageAttachmentCell.swift | 2 +- .../AutocompleteManager/AutocompleteManager.swift | 15 ++++++--------- .../NSAttributedStringKey+Extensions.swift | 6 +++--- .../Views/AutocompleteCell.swift | 4 ++-- .../NSMutableAttributedString+Extensions.swift | 12 ++++++------ Sources/Info.plist | 2 +- Sources/MessageInputBar.swift | 10 +++++----- Sources/Views/InputStackView.swift | 2 +- Sources/Views/InputTextView.swift | 12 ++++++------ Tests/InputBarItemTests.swift | 2 +- 20 files changed, 54 insertions(+), 59 deletions(-) diff --git a/.swift-version b/.swift-version index 5186d07..bf77d54 100644 --- a/.swift-version +++ b/.swift-version @@ -1 +1 @@ -4.0 +4.2 diff --git a/Example/Example.xcodeproj/project.pbxproj b/Example/Example.xcodeproj/project.pbxproj index 70cc0f1..2d897b9 100644 --- a/Example/Example.xcodeproj/project.pbxproj +++ b/Example/Example.xcodeproj/project.pbxproj @@ -387,7 +387,7 @@ ); PRODUCT_BUNDLE_IDENTIFIER = com.messagekit.MessageInputBar.Example; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Debug; @@ -406,7 +406,7 @@ ); PRODUCT_BUNDLE_IDENTIFIER = com.messagekit.MessageInputBar.Example; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Release; diff --git a/Example/Example/AppDelegate.swift b/Example/Example/AppDelegate.swift index 4288aa0..d7e8f87 100644 --- a/Example/Example/AppDelegate.swift +++ b/Example/Example/AppDelegate.swift @@ -29,11 +29,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? - func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch. - UIApplication.shared.statusBarStyle = .lightContent - window = UIWindow() window?.backgroundColor = .white let splitViewController = SplitViewController() diff --git a/Example/Example/ExampleViewController.swift b/Example/Example/ExampleViewController.swift index 42f35d8..57fe418 100644 --- a/Example/Example/ExampleViewController.swift +++ b/Example/Example/ExampleViewController.swift @@ -229,10 +229,10 @@ extension ExampleViewController: AutocompleteManagerDelegate, AutocompleteManage extension ExampleViewController: UIImagePickerControllerDelegate, UINavigationControllerDelegate { - func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) { + private func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) { dismiss(animated: true, completion: { - if let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage { + if let pickedImage = info[UIImagePickerController.InfoKey.originalImage.rawValue] as? UIImage { let handled = self.attachmentManager.handleInput(of: pickedImage) if !handled { // throw error diff --git a/Example/Example/Style Examples/SlackInputBar.swift b/Example/Example/Style Examples/SlackInputBar.swift index c021a22..b010a9c 100644 --- a/Example/Example/Style Examples/SlackInputBar.swift +++ b/Example/Example/Style Examples/SlackInputBar.swift @@ -129,10 +129,10 @@ class SlackInputBar: MessageInputBar { extension SlackInputBar: UIImagePickerControllerDelegate, UINavigationControllerDelegate { - func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) { + private func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) { picker.dismiss(animated: true, completion: { - if let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage { + if let pickedImage = info[UIImagePickerController.InfoKey.originalImage.rawValue] as? UIImage { self.plugins.forEach { _ = $0.handleInput(of: pickedImage) } } }) diff --git a/Example/Example/TableViewController.swift b/Example/Example/TableViewController.swift index 43ff73f..9a9d1b0 100644 --- a/Example/Example/TableViewController.swift +++ b/Example/Example/TableViewController.swift @@ -37,7 +37,7 @@ final class TableViewController: UITableViewController { navigationItem.backBarButtonItem = UIBarButtonItem(title: "Styles", style: .plain, target: nil, action: nil) navigationController?.navigationBar.tintColor = .white navigationController?.navigationBar.barTintColor = UIColor(red: 69/255, green: 193/255, blue: 89/255, alpha: 1) - navigationController?.navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.white, NSAttributedStringKey.font: UIFont.systemFont(ofSize: 20, weight: UIFont.Weight.bold) ] + navigationController?.navigationBar.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white, NSAttributedString.Key.font: UIFont.systemFont(ofSize: 20, weight: UIFont.Weight.bold) ] } override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? { diff --git a/Example/Podfile.lock b/Example/Podfile.lock index 5c78415..2f85bd5 100644 --- a/Example/Podfile.lock +++ b/Example/Podfile.lock @@ -1,11 +1,11 @@ PODS: - - MessageInputBar (0.2.2): - - MessageInputBar/Core (= 0.2.2) - - MessageInputBar/AttachmentManager (0.2.2): + - MessageInputBar (0.4.0): + - MessageInputBar/Core (= 0.4.0) + - MessageInputBar/AttachmentManager (0.4.0): - MessageInputBar/Core - - MessageInputBar/AutocompleteManager (0.2.2): + - MessageInputBar/AutocompleteManager (0.4.0): - MessageInputBar/Core - - MessageInputBar/Core (0.2.2) + - MessageInputBar/Core (0.4.0) DEPENDENCIES: - MessageInputBar (from `../`) @@ -17,7 +17,7 @@ EXTERNAL SOURCES: :path: "../" SPEC CHECKSUMS: - MessageInputBar: 420071067412a5b21b3e9cf74ee4f921e42e8b5b + MessageInputBar: 89b524f5dea5599acbeb9ce17ab269eb3683d683 PODFILE CHECKSUM: 59ceff645e2e779969697ee2390f43a1a67332f9 diff --git a/MessageInputBar.podspec b/MessageInputBar.podspec index e9d6089..28646f6 100644 --- a/MessageInputBar.podspec +++ b/MessageInputBar.podspec @@ -8,9 +8,9 @@ Pod::Spec.new do |s| s.requires_arc = true # 2 - Version - s.version = '0.3.0' + s.version = '0.4.0' s.pod_target_xcconfig = { - "SWIFT_VERSION" => "4.0", + "SWIFT_VERSION" => "4.2", } s.ios.deployment_target = '9.0' s.source = { :git => 'https://github.com/MessageKit/MessageInputBar.git', :tag => s.version } diff --git a/MessageInputBar.xcodeproj/project.pbxproj b/MessageInputBar.xcodeproj/project.pbxproj index 0b9152d..0afb62d 100644 --- a/MessageInputBar.xcodeproj/project.pbxproj +++ b/MessageInputBar.xcodeproj/project.pbxproj @@ -593,7 +593,7 @@ PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Debug; @@ -619,7 +619,7 @@ PRODUCT_BUNDLE_IDENTIFIER = com.messagekit.MessageInputBar; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; SKIP_INSTALL = YES; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Release; @@ -637,7 +637,7 @@ ); PRODUCT_BUNDLE_IDENTIFIER = com.messagekit.MessageInputBarTests; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Debug; @@ -655,7 +655,7 @@ ); PRODUCT_BUNDLE_IDENTIFIER = com.messagekit.MessageInputBarTests; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Release; diff --git a/Plugins/AttachmentManager/Views/AttachmentCell.swift b/Plugins/AttachmentManager/Views/AttachmentCell.swift index 0335569..7a6fbd7 100755 --- a/Plugins/AttachmentManager/Views/AttachmentCell.swift +++ b/Plugins/AttachmentManager/Views/AttachmentCell.swift @@ -32,7 +32,7 @@ open class AttachmentCell: UICollectionViewCell { return "AttachmentCell" } - open let containerView: UIView = { + public let containerView: UIView = { let view = UIView() view.translatesAutoresizingMaskIntoConstraints = false view.backgroundColor = .groupTableViewBackground diff --git a/Plugins/AttachmentManager/Views/ImageAttachmentCell.swift b/Plugins/AttachmentManager/Views/ImageAttachmentCell.swift index 4824c7b..8a2671e 100755 --- a/Plugins/AttachmentManager/Views/ImageAttachmentCell.swift +++ b/Plugins/AttachmentManager/Views/ImageAttachmentCell.swift @@ -32,7 +32,7 @@ open class ImageAttachmentCell: AttachmentCell { return "ImageAttachmentCell" } - open let imageView: UIImageView = { + public let imageView: UIImageView = { let imageView = UIImageView() imageView.contentMode = .scaleAspectFill return imageView diff --git a/Plugins/AutocompleteManager/AutocompleteManager.swift b/Plugins/AutocompleteManager/AutocompleteManager.swift index 08f7e8a..dd4cee7 100755 --- a/Plugins/AutocompleteManager/AutocompleteManager.swift +++ b/Plugins/AutocompleteManager/AutocompleteManager.swift @@ -74,10 +74,10 @@ open class AutocompleteManager: NSObject, InputPlugin, UITextViewDelegate, UITab open var maxSpaceCountDuringCompletion: Int = 0 /// The default text attributes - open var defaultTextAttributes: [NSAttributedStringKey: Any] = + open var defaultTextAttributes: [NSAttributedString.Key: Any] = [.font: UIFont.preferredFont(forTextStyle: .body), .foregroundColor: UIColor.black] - /// The NSAttributedStringKey.paragraphStyle value applied to attributed strings + /// The NSAttributedString.Key.paragraphStyle value applied to attributed strings public let paragraphStyle: NSMutableParagraphStyle = { let style = NSMutableParagraphStyle() style.paragraphSpacingBefore = 2 @@ -95,10 +95,10 @@ open class AutocompleteManager: NSObject, InputPlugin, UITextViewDelegate, UITab public private(set) var autocompleteDelimiterSets: Set = [.whitespaces, .newlines] /// The text attributes applied to highlighted substrings for each prefix - public private(set) var autocompleteTextAttributes = [String: [NSAttributedStringKey: Any]]() + public private(set) var autocompleteTextAttributes = [String: [NSAttributedString.Key: Any]]() /// A reference to `defaultTextAttributes` that adds the NSAttributedAutocompleteKey - private var typingTextAttributes: [NSAttributedStringKey: Any] { + private var typingTextAttributes: [NSAttributedString.Key: Any] { var attributes = defaultTextAttributes attributes[.autocompleted] = false attributes[.autocompletedContext] = nil @@ -189,7 +189,7 @@ open class AutocompleteManager: NSObject, InputPlugin, UITextViewDelegate, UITab /// - Parameters: /// - prefix: The prefix such as: @, # or ! /// - attributedTextAttributes: The attributes to apply to the NSAttributedString - open func register(prefix: String, with attributedTextAttributes: [NSAttributedStringKey:Any]? = nil) { + open func register(prefix: String, with attributedTextAttributes: [NSAttributedString.Key:Any]? = nil) { autocompletePrefixes.insert(prefix) autocompleteTextAttributes[prefix] = attributedTextAttributes autocompleteTextAttributes[prefix]?[.paragraphStyle] = paragraphStyle @@ -279,10 +279,7 @@ open class AutocompleteManager: NSObject, InputPlugin, UITextViewDelegate, UITab /// Resets the `InputTextView`'s typingAttributes to `defaultTextAttributes` private func preserveTypingAttributes() { - - var typingAttributes = [String: Any]() - typingTextAttributes.forEach { typingAttributes[$0.key.rawValue] = $0.value } - textView?.typingAttributes = typingAttributes + textView?.typingAttributes = typingTextAttributes } diff --git a/Plugins/AutocompleteManager/Extensions/NSAttributedStringKey+Extensions.swift b/Plugins/AutocompleteManager/Extensions/NSAttributedStringKey+Extensions.swift index 45e4a69..4372295 100644 --- a/Plugins/AutocompleteManager/Extensions/NSAttributedStringKey+Extensions.swift +++ b/Plugins/AutocompleteManager/Extensions/NSAttributedStringKey+Extensions.swift @@ -24,13 +24,13 @@ import UIKit -public extension NSAttributedStringKey { +public extension NSAttributedString.Key { /// A key used for referencing which substrings were autocompleted /// by MessageInputBar.AutocompleteManager - static let autocompleted = NSAttributedStringKey("com.messagekit.autocompletekey") + static let autocompleted = NSAttributedString.Key("com.messagekit.autocompletekey") /// A key used for referencing the context of autocompleted substrings /// by MessageInputBar.AutocompleteManager - static let autocompletedContext = NSAttributedStringKey("com.messagekit.autocompletekey.context") + static let autocompletedContext = NSAttributedString.Key("com.messagekit.autocompletekey.context") } diff --git a/Plugins/AutocompleteManager/Views/AutocompleteCell.swift b/Plugins/AutocompleteManager/Views/AutocompleteCell.swift index 5b296b8..fb9530f 100755 --- a/Plugins/AutocompleteManager/Views/AutocompleteCell.swift +++ b/Plugins/AutocompleteManager/Views/AutocompleteCell.swift @@ -33,13 +33,13 @@ open class AutocompleteCell: UITableViewCell { } /// A boarder line anchored to the top of the view - open let separatorLine = SeparatorLine() + public let separatorLine = SeparatorLine() open var imageViewEdgeInsets: UIEdgeInsets = .zero // MARK: - Initialization - override init(style: UITableViewCellStyle, reuseIdentifier: String?) { + override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { super.init(style: .subtitle, reuseIdentifier: reuseIdentifier) setup() } diff --git a/Sources/Extensions/NSMutableAttributedString+Extensions.swift b/Sources/Extensions/NSMutableAttributedString+Extensions.swift index 9d26ab1..85cd508 100755 --- a/Sources/Extensions/NSMutableAttributedString+Extensions.swift +++ b/Sources/Extensions/NSMutableAttributedString+Extensions.swift @@ -28,9 +28,9 @@ extension NSMutableAttributedString { @discardableResult internal func bold(_ text: String, fontSize: CGFloat = UIFont.preferredFont(forTextStyle: .body).pointSize, textColor: UIColor = .black) -> NSMutableAttributedString { - let attrs: [NSAttributedStringKey:AnyObject] = [ - NSAttributedStringKey.font : UIFont.boldSystemFont(ofSize: fontSize), - NSAttributedStringKey.foregroundColor : textColor + let attrs: [NSAttributedString.Key:AnyObject] = [ + NSAttributedString.Key.font : UIFont.boldSystemFont(ofSize: fontSize), + NSAttributedString.Key.foregroundColor : textColor ] let boldString = NSMutableAttributedString(string: text, attributes: attrs) self.append(boldString) @@ -39,9 +39,9 @@ extension NSMutableAttributedString { @discardableResult internal func normal(_ text: String, fontSize: CGFloat = UIFont.preferredFont(forTextStyle: .body).pointSize, textColor: UIColor = .black) -> NSMutableAttributedString { - let attrs:[NSAttributedStringKey:AnyObject] = [ - NSAttributedStringKey.font : UIFont.systemFont(ofSize: fontSize), - NSAttributedStringKey.foregroundColor : textColor + let attrs:[NSAttributedString.Key:AnyObject] = [ + NSAttributedString.Key.font : UIFont.systemFont(ofSize: fontSize), + NSAttributedString.Key.foregroundColor : textColor ] let normal = NSMutableAttributedString(string: text, attributes: attrs) self.append(normal) diff --git a/Sources/Info.plist b/Sources/Info.plist index 1007fd9..fff2849 100644 --- a/Sources/Info.plist +++ b/Sources/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 1.0 + 0.4.0 CFBundleVersion $(CURRENT_PROJECT_VERSION) NSPrincipalClass diff --git a/Sources/MessageInputBar.swift b/Sources/MessageInputBar.swift index 4761be9..e1b80f7 100644 --- a/Sources/MessageInputBar.swift +++ b/Sources/MessageInputBar.swift @@ -325,16 +325,16 @@ open class MessageInputBar: UIView { private func setupObservers() { NotificationCenter.default.addObserver(self, selector: #selector(MessageInputBar.orientationDidChange), - name: .UIDeviceOrientationDidChange, object: nil) + name: UIDevice.orientationDidChangeNotification, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(MessageInputBar.inputTextViewDidChange), - name: NSNotification.Name.UITextViewTextDidChange, object: inputTextView) + name: UITextView.textDidChangeNotification, object: inputTextView) NotificationCenter.default.addObserver(self, selector: #selector(MessageInputBar.inputTextViewDidBeginEditing), - name: NSNotification.Name.UITextViewTextDidBeginEditing, object: inputTextView) + name: UITextView.textDidBeginEditingNotification, object: inputTextView) NotificationCenter.default.addObserver(self, selector: #selector(MessageInputBar.inputTextViewDidEndEditing), - name: NSNotification.Name.UITextViewTextDidEndEditing, object: inputTextView) + name: UITextView.textDidEndEditingNotification, object: inputTextView) } /// Adds all of the subviews @@ -426,7 +426,7 @@ open class MessageInputBar: UIView { guard UIScreen.main.nativeBounds.height == 2436 else { return } if let window = window { windowAnchor?.isActive = false - windowAnchor = contentView.bottomAnchor.constraintLessThanOrEqualToSystemSpacingBelow(window.safeAreaLayoutGuide.bottomAnchor, multiplier: 1) + windowAnchor = contentView.bottomAnchor.constraint(lessThanOrEqualToSystemSpacingBelow: window.safeAreaLayoutGuide.bottomAnchor, multiplier: 1) windowAnchor?.constant = -padding.bottom windowAnchor?.priority = UILayoutPriority(rawValue: 750) windowAnchor?.isActive = true diff --git a/Sources/Views/InputStackView.swift b/Sources/Views/InputStackView.swift index aac3727..897f2bf 100644 --- a/Sources/Views/InputStackView.swift +++ b/Sources/Views/InputStackView.swift @@ -46,7 +46,7 @@ open class InputStackView: UIStackView { // MARK: Initialization - public convenience init(axis: UILayoutConstraintAxis, spacing: CGFloat) { + public convenience init(axis: NSLayoutConstraint.Axis, spacing: CGFloat) { self.init(frame: .zero) self.axis = axis self.spacing = spacing diff --git a/Sources/Views/InputTextView.swift b/Sources/Views/InputTextView.swift index 74fb17e..dc53a41 100644 --- a/Sources/Views/InputTextView.swift +++ b/Sources/Views/InputTextView.swift @@ -189,10 +189,10 @@ open class InputTextView: UITextView { NotificationCenter.default.addObserver(self, selector: #selector(InputTextView.redrawTextAttachments), - name: .UIDeviceOrientationDidChange, object: nil) + name: UIDevice.orientationDidChangeNotification, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(InputTextView.textViewTextDidChange), - name: .UITextViewTextDidChange, object: nil) + name: UITextView.textDidChangeNotification, object: nil) } /// Updates the placeholderLabels constraint constants to match the placeholderLabelInsets @@ -208,7 +208,7 @@ open class InputTextView: UITextView { // MARK: - Notification private func postTextViewDidChangeNotification() { - NotificationCenter.default.post(name: .UITextViewTextDidChange, object: self) + NotificationCenter.default.post(name: UITextView.textDidChangeNotification, object: self) } @objc @@ -260,9 +260,9 @@ open class InputTextView: UITextView { newAttributedStingComponent.append(NSAttributedString(string: "\n")) // The attributes that should be applied to the new NSAttributedString to match the current attributes - let attributes: [NSAttributedStringKey: Any] = [ - NSAttributedStringKey.font: font ?? UIFont.preferredFont(forTextStyle: .body), - NSAttributedStringKey.foregroundColor: textColor ?? .black + let attributes: [NSAttributedString.Key: Any] = [ + NSAttributedString.Key.font: font ?? UIFont.preferredFont(forTextStyle: .body), + NSAttributedString.Key.foregroundColor: textColor ?? .black ] newAttributedStingComponent.addAttributes(attributes, range: NSRange(location: 0, length: newAttributedStingComponent.length)) diff --git a/Tests/InputBarItemTests.swift b/Tests/InputBarItemTests.swift index e6da658..c5337da 100644 --- a/Tests/InputBarItemTests.swift +++ b/Tests/InputBarItemTests.swift @@ -56,7 +56,7 @@ class InputBarItemTests: XCTestCase { func testImagePropertyGettersAndSetters() { button.image = UIImage() XCTAssertNotNil(button.image) - XCTAssertEqual(UIImagePNGRepresentation(button.image!), UIImagePNGRepresentation(UIImage())) + XCTAssertEqual(button.image!.pngData(), UIImage().pngData()) } func testIsHighlightedProperty() { From 0d2ea1b85a708f37d6b720a3b316e63a39ace4b8 Mon Sep 17 00:00:00 2001 From: Nathan Tannar Date: Sat, 29 Sep 2018 12:04:02 -0700 Subject: [PATCH 5/9] Add note to README --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index f84e89a..74f056a 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,8 @@ github "MessageKit/MessageInputBar" - **iOS 9** or later - **Swift 4** or later +> Version 0.4.0 onwards is only Swift 4.2 compatible + ## Contributing From faebe27f2dd8f39ea145e75b7296ef48133c099a Mon Sep 17 00:00:00 2001 From: Nathan Tannar Date: Thu, 4 Oct 2018 10:37:28 -0700 Subject: [PATCH 6/9] Fix Default Placeholder Padding --- MessageInputBar.podspec | 2 +- Sources/Views/InputTextView.swift | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/MessageInputBar.podspec b/MessageInputBar.podspec index 28646f6..e5cc4c5 100644 --- a/MessageInputBar.podspec +++ b/MessageInputBar.podspec @@ -8,7 +8,7 @@ Pod::Spec.new do |s| s.requires_arc = true # 2 - Version - s.version = '0.4.0' + s.version = '0.4.1' s.pod_target_xcconfig = { "SWIFT_VERSION" => "4.2", } diff --git a/Sources/Views/InputTextView.swift b/Sources/Views/InputTextView.swift index dc53a41..294f387 100644 --- a/Sources/Views/InputTextView.swift +++ b/Sources/Views/InputTextView.swift @@ -86,7 +86,7 @@ open class InputTextView: UITextView { } /// The `UIEdgeInsets` the placeholderLabel has within the `InputTextView` - open var placeholderLabelInsets: UIEdgeInsets = UIEdgeInsets(top: 4, left: 4, bottom: 4, right: 4) { + open var placeholderLabelInsets: UIEdgeInsets = UIEdgeInsets(top: 8, left: 4, bottom: 8, right: 4) { didSet { updateConstraintsForPlaceholderLabel() } From b2fdc8398ffb52726faa05828105f8459cca8e4b Mon Sep 17 00:00:00 2001 From: Keith Black Date: Mon, 7 Jan 2019 21:41:34 -0600 Subject: [PATCH 7/9] Fixed crash when inserting text and multiple images. --- Sources/Views/InputTextView.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Views/InputTextView.swift b/Sources/Views/InputTextView.swift index 294f387..1a0dddf 100644 --- a/Sources/Views/InputTextView.swift +++ b/Sources/Views/InputTextView.swift @@ -347,7 +347,7 @@ open class InputTextView: UITextView { attachments.forEach { (attachment) in let (range, image) = attachment if curLocation < range.location { - let textRange = NSMakeRange(curLocation, range.location) + let textRange = NSMakeRange(curLocation, range.location-curLocation) let text = attributedText.attributedSubstring(from: textRange).string.trimmingCharacters(in: .whitespacesAndNewlines) if !text.isEmpty { components.append(text) From 20d2bdaab469877a2a40df2657507ec15d917520 Mon Sep 17 00:00:00 2001 From: briantom Date: Tue, 12 Feb 2019 21:50:58 -0800 Subject: [PATCH 8/9] updated podspecs swift language version to 4.2 --- MessageInputBar.podspec | 3 +++ 1 file changed, 3 insertions(+) diff --git a/MessageInputBar.podspec b/MessageInputBar.podspec index e5cc4c5..43c5d37 100644 --- a/MessageInputBar.podspec +++ b/MessageInputBar.podspec @@ -12,6 +12,9 @@ Pod::Spec.new do |s| s.pod_target_xcconfig = { "SWIFT_VERSION" => "4.2", } + + s.swift_version = '4.2' + s.ios.deployment_target = '9.0' s.source = { :git => 'https://github.com/MessageKit/MessageInputBar.git', :tag => s.version } From 13a508b093b5bff5c94517d60fb7ec2bb53a18eb Mon Sep 17 00:00:00 2001 From: Nicolas Fogg Date: Tue, 26 Mar 2019 13:03:59 +1100 Subject: [PATCH 9/9] Use the source image orientation when creating an image text attachment --- Sources/Views/InputTextView.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Views/InputTextView.swift b/Sources/Views/InputTextView.swift index 1a0dddf..4fa62e5 100644 --- a/Sources/Views/InputTextView.swift +++ b/Sources/Views/InputTextView.swift @@ -288,7 +288,7 @@ open class InputTextView: UITextView { guard let cgImage = image.cgImage else { return NSTextAttachment() } let scale = image.size.width / (frame.width - 2 * (textContainerInset.left + textContainerInset.right)) let textAttachment = NSTextAttachment() - textAttachment.image = UIImage(cgImage: cgImage, scale: scale, orientation: .up) + textAttachment.image = UIImage(cgImage: cgImage, scale: scale, orientation: image.imageOrientation) return textAttachment }