From c844b3428e7532e92f88a3933e81fd9b86f72ac6 Mon Sep 17 00:00:00 2001 From: Diego Sanchez Date: Tue, 14 Jun 2016 19:36:24 +0100 Subject: [PATCH 1/3] Adds more customizable options to the input bar Bar with icons gets customisable height Buttons get customizable intrinsic contentSize, so they can be bigger and easy to tap Buttons get customizable images for any UIControlState Send button gets customizable text colors for any UIControlState --- Chatto/Chatto.xcodeproj/project.pbxproj | 1 + .../ChattoAdditions.xcodeproj/project.pbxproj | 8 ++- .../Source/Input/ChatInputBar.swift | 37 +++++------- ChattoAdditions/Source/Input/ChatInputBar.xib | 11 ++-- .../Source/Input/ChatInputBarAppearance.swift | 48 +++++++++++---- .../Input/Photos/PhotosChatInputItem.swift | 40 ++++--------- .../Source/Input/TabInputButton.swift | 58 +++++++++++++++++++ .../Source/Input/Text/TextChatInputItem.swift | 28 ++++----- .../Source/DemoChatViewController.swift | 4 +- 9 files changed, 149 insertions(+), 86 deletions(-) create mode 100644 ChattoAdditions/Source/Input/TabInputButton.swift diff --git a/Chatto/Chatto.xcodeproj/project.pbxproj b/Chatto/Chatto.xcodeproj/project.pbxproj index 498d6dfd0..1eed8454c 100644 --- a/Chatto/Chatto.xcodeproj/project.pbxproj +++ b/Chatto/Chatto.xcodeproj/project.pbxproj @@ -460,6 +460,7 @@ IPHONEOS_DEPLOYMENT_TARGET = 8.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; + SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; VERSIONING_SYSTEM = "apple-generic"; diff --git a/ChattoAdditions/ChattoAdditions.xcodeproj/project.pbxproj b/ChattoAdditions/ChattoAdditions.xcodeproj/project.pbxproj index 2421ed6f7..159fd4cb6 100644 --- a/ChattoAdditions/ChattoAdditions.xcodeproj/project.pbxproj +++ b/ChattoAdditions/ChattoAdditions.xcodeproj/project.pbxproj @@ -76,6 +76,7 @@ C3C0CC8B1BFE49700052747C /* PhotosInputViewItemSizeCalculatorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3C0CC7D1BFE49700052747C /* PhotosInputViewItemSizeCalculatorTests.swift */; }; C3C0CC8C1BFE49700052747C /* TextChatInputItemTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3C0CC7E1BFE49700052747C /* TextChatInputItemTests.swift */; }; C3C0CC8D1BFE49700052747C /* ObservableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3C0CC7F1BFE49700052747C /* ObservableTests.swift */; }; + C3C9BC8F1D11540D00F3A54E /* TabInputButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3C9BC8E1D11540D00F3A54E /* TabInputButton.swift */; }; C3EFA6B01C03607A0063CE22 /* BaseMessagePresenterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3EFA6AF1C03607A0063CE22 /* BaseMessagePresenterTests.swift */; }; CA073E791C47F5B9009D5EBF /* Chatto.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CA073E781C47F5B9009D5EBF /* Chatto.framework */; }; F6D04BA71CA46C0200E803FA /* PhotosInputPlaceholderDataProviderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F6D04BA61CA46C0200E803FA /* PhotosInputPlaceholderDataProviderTests.swift */; }; @@ -165,6 +166,7 @@ C3C0CC7E1BFE49700052747C /* TextChatInputItemTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TextChatInputItemTests.swift; sourceTree = ""; }; C3C0CC7F1BFE49700052747C /* ObservableTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ObservableTests.swift; sourceTree = ""; }; C3C0CC961BFE4A2A0052747C /* ChattoAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ChattoAdditions.h; sourceTree = ""; }; + C3C9BC8E1D11540D00F3A54E /* TabInputButton.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TabInputButton.swift; sourceTree = ""; }; C3EFA6AF1C03607A0063CE22 /* BaseMessagePresenterTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BaseMessagePresenterTests.swift; sourceTree = ""; }; CA073E781C47F5B9009D5EBF /* Chatto.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Chatto.framework; path = "../../../../Library/Developer/Xcode/DerivedData/Chatto-gyrilfusfbpmohajjvmmctphuabr/Build/Products/Debug-iphoneos/Chatto.framework"; sourceTree = ""; }; F6D04BA61CA46C0200E803FA /* PhotosInputPlaceholderDataProviderTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PhotosInputPlaceholderDataProviderTests.swift; sourceTree = ""; }; @@ -326,15 +328,16 @@ isa = PBXGroup; children = ( C3C0CC041BFE496A0052747C /* ChatInputBar.swift */, + C3C0CC051BFE496A0052747C /* ChatInputBar.xib */, C3C0CC061BFE496A0052747C /* ChatInputBarAppearance.swift */, C3C0CC071BFE496A0052747C /* ChatInputBarPresenter.swift */, C3C0CC081BFE496A0052747C /* ChatInputItem.swift */, C3C0CC091BFE496A0052747C /* ChatInputItemView.swift */, C3C0CC0A1BFE496A0052747C /* ExpandableTextView.swift */, C3C0CC0B1BFE496A0052747C /* HorizontalStackScrollView.swift */, - C3C0CC161BFE496A0052747C /* ReusableXibView.swift */, - C3C0CC051BFE496A0052747C /* ChatInputBar.xib */, C3C0CC0C1BFE496A0052747C /* Photos */, + C3C0CC161BFE496A0052747C /* ReusableXibView.swift */, + C3C9BC8E1D11540D00F3A54E /* TabInputButton.swift */, C3C0CC171BFE496A0052747C /* Text */, ); path = Input; @@ -567,6 +570,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + C3C9BC8F1D11540D00F3A54E /* TabInputButton.swift in Sources */, C3C0CC311BFE496A0052747C /* ChatItemDecorationAttributes.swift in Sources */, C3C0CC3B1BFE496A0052747C /* PhotoMessageCollectionViewCellDefaultStyle.swift in Sources */, C38658B21BFE55620012F181 /* AnimationUtils.swift in Sources */, diff --git a/ChattoAdditions/Source/Input/ChatInputBar.swift b/ChattoAdditions/Source/Input/ChatInputBar.swift index 00b51c172..4d83cbcad 100644 --- a/ChattoAdditions/Source/Input/ChatInputBar.swift +++ b/ChattoAdditions/Source/Input/ChatInputBar.swift @@ -54,6 +54,7 @@ public class ChatInputBar: ReusableXibView { @IBOutlet var constraintsForVisibleSendButton: [NSLayoutConstraint]! @IBOutlet var constraintsForHiddenSendButton: [NSLayoutConstraint]! + @IBOutlet var tabBarContainerHeightConstraint: NSLayoutConstraint! class public func loadNib() -> ChatInputBar { let view = NSBundle(forClass: self).loadNibNamed(self.nibName(), owner: nil, options: nil).first as! ChatInputBar @@ -185,17 +186,21 @@ extension ChatInputBar: ChatInputItemViewDelegate { // MARK: - ChatInputBarAppearance extension ChatInputBar { public func setAppearance(appearance: ChatInputBarAppearance) { - self.textView.font = appearance.textFont - self.textView.textColor = appearance.textColor - self.textView.textContainerInset = appearance.textInsets - self.textView.setTextPlaceholderFont(appearance.textPlaceholderFont) - self.textView.setTextPlaceholderColor(appearance.textPlaceholderColor) - self.textView.setTextPlaceholder(appearance.textPlaceholder) - self.tabBarInterItemSpacing = appearance.tabBarInterItemSpacing - self.tabBarContentInsets = appearance.tabBarInsets - self.sendButton.contentEdgeInsets = appearance.sendButtonInsets - self.sendButton.setTitle(appearance.sendButtonTitle, forState: .Normal) - self.sendButton.titleLabel?.font = appearance.sendButtonFont + self.textView.font = appearance.textInputAppearance.font + self.textView.textColor = appearance.textInputAppearance.textColor + self.textView.textContainerInset = appearance.textInputAppearance.textInsets + self.textView.setTextPlaceholderFont(appearance.textInputAppearance.placeholderFont) + self.textView.setTextPlaceholderColor(appearance.textInputAppearance.placeholderColor) + self.textView.setTextPlaceholder(appearance.textInputAppearance.placeholderText) + self.tabBarInterItemSpacing = appearance.tabBarAppearance.interItemSpacing + self.tabBarContentInsets = appearance.tabBarAppearance.contentInsets + self.sendButton.contentEdgeInsets = appearance.sendButtonAppearance.insets + self.sendButton.setTitle(appearance.sendButtonAppearance.title, forState: .Normal) + appearance.sendButtonAppearance.titleColors.forEach { (state, color) in + self.sendButton.setTitleColor(color, forState: state) + } + self.sendButton.titleLabel?.font = appearance.sendButtonAppearance.font + self.tabBarContainerHeightConstraint.constant = appearance.tabBarAppearance.height } } @@ -249,13 +254,3 @@ extension ChatInputBar: UITextViewDelegate { return true } } - -class SingleViewContainerView: UIView { - override func intrinsicContentSize() -> CGSize { - if let subview = self.subviews.first { - return subview.intrinsicContentSize() - } else { - return CGSize.zero - } - } -} diff --git a/ChattoAdditions/Source/Input/ChatInputBar.xib b/ChattoAdditions/Source/Input/ChatInputBar.xib index de17f85d6..2262e6c17 100644 --- a/ChattoAdditions/Source/Input/ChatInputBar.xib +++ b/ChattoAdditions/Source/Input/ChatInputBar.xib @@ -1,8 +1,8 @@ - + - + @@ -21,11 +21,11 @@ - + -