Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Input bar customization enhancements #154

Merged
merged 4 commits into from
Jun 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Chatto/Chatto.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
8 changes: 6 additions & 2 deletions ChattoAdditions/ChattoAdditions.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -165,6 +166,7 @@
C3C0CC7E1BFE49700052747C /* TextChatInputItemTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TextChatInputItemTests.swift; sourceTree = "<group>"; };
C3C0CC7F1BFE49700052747C /* ObservableTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ObservableTests.swift; sourceTree = "<group>"; };
C3C0CC961BFE4A2A0052747C /* ChattoAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ChattoAdditions.h; sourceTree = "<group>"; };
C3C9BC8E1D11540D00F3A54E /* TabInputButton.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TabInputButton.swift; sourceTree = "<group>"; };
C3EFA6AF1C03607A0063CE22 /* BaseMessagePresenterTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BaseMessagePresenterTests.swift; sourceTree = "<group>"; };
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 = "<group>"; };
F6D04BA61CA46C0200E803FA /* PhotosInputPlaceholderDataProviderTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PhotosInputPlaceholderDataProviderTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 */,
Expand Down
37 changes: 16 additions & 21 deletions ChattoAdditions/Source/Input/ChatInputBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
}

Expand Down Expand Up @@ -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
}
}
}
11 changes: 6 additions & 5 deletions ChattoAdditions/Source/Input/ChatInputBar.xib
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="10115" systemVersion="15E64a" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="10117" systemVersion="15G12a" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10084"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
Expand All @@ -21,11 +21,11 @@
<rect key="frame" x="0.0" y="79" width="600" height="44"/>
<subviews>
<scrollView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" showsHorizontalScrollIndicator="NO" showsVerticalScrollIndicator="NO" translatesAutoresizingMaskIntoConstraints="NO" id="WNX-pj-5AB" customClass="HorizontalStackScrollView" customModule="ChattoAdditions" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="514" height="44"/>
<rect key="frame" x="0.0" y="0.0" width="506" height="44"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</scrollView>
<button opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" horizontalCompressionResistancePriority="751" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="hE9-hU-Ci1">
<rect key="frame" x="514" y="0.0" width="86" height="44"/>
<button opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" horizontalCompressionResistancePriority="751" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="hE9-hU-Ci1">
<rect key="frame" x="506" y="0.0" width="94" height="44"/>
<inset key="contentEdgeInsets" minX="20" minY="0.0" maxX="20" maxY="0.0"/>
<state key="normal" title="Button"/>
<connections>
Expand Down Expand Up @@ -84,6 +84,7 @@
<connections>
<outlet property="scrollView" destination="WNX-pj-5AB" id="Qqy-Ny-mng"/>
<outlet property="sendButton" destination="hE9-hU-Ci1" id="VFQ-Pb-J37"/>
<outlet property="tabBarContainerHeightConstraint" destination="vwa-F7-EIB" id="d3G-fs-hEH"/>
<outlet property="textView" destination="fsh-hH-hKG" id="QMH-G9-ADs"/>
<outlet property="topBorderHeightConstraint" destination="IIv-qg-Tlp" id="qiB-dH-AHS"/>
<outletCollection property="constraintsForVisibleTextView" destination="4Vl-vV-gaa" collectionClass="NSMutableArray" id="rBg-0B-c4B"/>
Expand Down
48 changes: 37 additions & 11 deletions ChattoAdditions/Source/Input/ChatInputBarAppearance.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,42 @@
*/

public struct ChatInputBarAppearance {
public var textFont = UIFont.systemFontOfSize(12)
public var textColor = UIColor.blackColor()
public var textPlaceholderFont = UIFont.systemFontOfSize(12)
public var textPlaceholderColor = UIColor.grayColor()
public var textPlaceholder = ""
public var textInsets = UIEdgeInsets(top: 8, left: 0, bottom: 8, right: 0)
public var sendButtonFont = UIFont.systemFontOfSize(16)
public var sendButtonInsets = UIEdgeInsets(top: 0, left: 20, bottom: 0, right: 20)
public var sendButtonTitle = ""
public var tabBarInsets = UIEdgeInsets(top: 0, left: 5, bottom: 0, right: 5)
public var tabBarInterItemSpacing: CGFloat = 10
public struct SendButtonAppearance {
public var font = UIFont.systemFontOfSize(16)
public var insets = UIEdgeInsets(top: 0, left: 20, bottom: 0, right: 20)
public var title = ""
public var titleColors: [UIControlState: UIColor] = [
.Disabled: UIColor.bma_color(rgb: 0x9AA3AB),
.Normal: UIColor.bma_color(rgb: 0x007AFF),
.Highlighted: UIColor.bma_color(rgb: 0x007AFF).bma_blendWithColor(UIColor.whiteColor().colorWithAlphaComponent(0.4))
]
}

public struct TabBarAppearance {
public var interItemSpacing: CGFloat = 10
public var height: CGFloat = 44
public var contentInsets = UIEdgeInsets(top: 0, left: 5, bottom: 0, right: 5)
}

public struct TextInputAppearance {
public var font = UIFont.systemFontOfSize(12)
public var textColor = UIColor.blackColor()
public var placeholderFont = UIFont.systemFontOfSize(12)
public var placeholderColor = UIColor.grayColor()
public var placeholderText = ""
public var textInsets = UIEdgeInsets(top: 8, left: 0, bottom: 8, right: 0)
}

public var sendButtonAppearance = SendButtonAppearance()
public var tabBarAppearance = TabBarAppearance()
public var textInputAppearance = TextInputAppearance()

public init() {}
}


extension UIControlState: Hashable {
public var hashValue: Int {
return Int(self.rawValue)
}
}
40 changes: 11 additions & 29 deletions ChattoAdditions/Source/Input/Photos/PhotosChatInputItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,6 @@

import Foundation

public struct ButtonImages {
public let normal: () -> UIImage
public let selected: () -> UIImage
public let highlighted: () -> UIImage
public init(
@autoclosure(escaping) normal: () -> UIImage,
@autoclosure(escaping) selected: () -> UIImage,
@autoclosure(escaping) highlighted: () -> UIImage) {
self.normal = normal
self.selected = selected
self.highlighted = highlighted
}
}

public class PhotosChatInputItem: ChatInputItemProtocol {
typealias Class = PhotosChatInputItem

Expand All @@ -46,27 +32,23 @@ public class PhotosChatInputItem: ChatInputItemProtocol {
public var photosPermissionHandler: (() -> Void)?
public weak var presentingController: UIViewController?

let buttonImages: ButtonImages
public init(presentingController: UIViewController?, buttonImages: ButtonImages = Class.createDefaultButtonStyle()) {
let buttonAppearance: TabInputButtonAppearance
public init(presentingController: UIViewController?, tabInputButtonAppearance: TabInputButtonAppearance = Class.createDefaultButtonAppearance()) {
self.presentingController = presentingController
self.buttonImages = buttonImages
self.buttonAppearance = tabInputButtonAppearance
}

public class func createDefaultButtonStyle() -> ButtonImages {
return ButtonImages(
normal: UIImage(named: "camera-icon-unselected", inBundle: NSBundle(forClass: Class.self), compatibleWithTraitCollection: nil)!,
selected: UIImage(named: "camera-icon-selected", inBundle: NSBundle(forClass: Class.self), compatibleWithTraitCollection: nil)!,
highlighted: UIImage(named: "camera-icon-selected", inBundle: NSBundle(forClass: Class.self), compatibleWithTraitCollection: nil)!
)
public class func createDefaultButtonAppearance() -> TabInputButtonAppearance {
let images: [UIControlState: UIImage] = [
.Normal: UIImage(named: "camera-icon-unselected", inBundle: NSBundle(forClass: Class.self), compatibleWithTraitCollection: nil)!,
.Selected: UIImage(named: "camera-icon-selected", inBundle: NSBundle(forClass: Class.self), compatibleWithTraitCollection: nil)!,
.Highlighted: UIImage(named: "camera-icon-selected", inBundle: NSBundle(forClass: Class.self), compatibleWithTraitCollection: nil)!
]
return TabInputButtonAppearance(images: images, size: nil)
}

lazy private var internalTabView: UIButton = {
var button = UIButton(type: .Custom)
button.exclusiveTouch = true
button.setImage(self.buttonImages.normal(), forState: .Normal)
button.setImage(self.buttonImages.highlighted(), forState: .Highlighted)
button.setImage(self.buttonImages.selected(), forState: .Selected)
return button
return TabInputButton.makeInputButton(withAppearance: self.buttonAppearance)
}()

lazy var photosInputView: PhotosInputViewProtocol = {
Expand Down
58 changes: 58 additions & 0 deletions ChattoAdditions/Source/Input/TabInputButton.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
The MIT License (MIT)

Copyright (c) 2015-present Badoo Trading Limited.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

import Foundation

public struct TabInputButtonAppearance {
public var images: [UIControlState: UIImage]
public var size: CGSize?

public init(images: [UIControlState: UIImage], size: CGSize?) {
self.images = images
self.size = size
}
}

public class TabInputButton: UIButton {

static public func makeInputButton(withAppearance appearance: TabInputButtonAppearance) -> TabInputButton {
let images = appearance.images
let button = TabInputButton(type: .Custom)
button.exclusiveTouch = true
images.forEach { (state, image) in
button.setImage(image, forState: state)
}
button.size = appearance.size
return button
}

private var size: CGSize?

public override func intrinsicContentSize() -> CGSize {
if let size = self.size {
return size
}
return super.intrinsicContentSize()
}
}
Loading