Skip to content

Commit

Permalink
bubble image flipped by public
Browse files Browse the repository at this point in the history
placeholder text in settings works
corrected access to button actions
scaleAspectFit for button images
organised settings order
settings made all public
  • Loading branch information
pgs-dkanak committed Apr 27, 2017
1 parent 06f43dd commit d007b8e
Show file tree
Hide file tree
Showing 7 changed files with 161 additions and 199 deletions.
4 changes: 2 additions & 2 deletions MessagesView/BubbleImage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class BubbleImage {
public lazy var middle: UIImage? = self.cropAndResize(slice: .middle)
public lazy var bottom: UIImage? = self.cropAndResize(slice: .bottom)

var flipped: BubbleImage {
public var flipped: BubbleImage {

let flippedImage = image.flipped
let flippedResizeInsets = insetsFlippedHorizontally(resizeInsets)
Expand Down Expand Up @@ -132,7 +132,7 @@ public class BubbleImage {
return result
}

public static func createTailPathIn(origin: CGPoint, size: CGSize) -> UIBezierPath {
private static func createTailPathIn(origin: CGPoint, size: CGSize) -> UIBezierPath {
let width = size.width
let height = size.height

Expand Down
27 changes: 6 additions & 21 deletions MessagesView/MessageEditorTextView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,14 @@

import UIKit

class MessageEditorTextView: UITextView {
class MessageEditorTextView: UITextField {

/*
// Only override draw() if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
override func draw(_ rect: CGRect) {
// Drawing code
}
*/

override func awakeFromNib() {
super.awakeFromNib()
setupTextView()
}

func setupTextView() {
self.backgroundColor = UIColor.yellow
}

func applySettings(settings: MessagesViewSettings) {
self.textColor = settings.textInputFieldTextColor
self.backgroundColor = settings.textInputFieldBackgroundColor
self.layer.cornerRadius = settings.textInputFieldCornerRadius
textColor = settings.textInputFieldTextColor
backgroundColor = settings.textInputFieldBackgroundColor
tintColor = settings.textInputTintColor
layer.cornerRadius = settings.textInputFieldCornerRadius
placeholder = settings.textInputFieldTextPlaceholderText
}

}
33 changes: 24 additions & 9 deletions MessagesView/MessagesInputToolbar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,34 @@

import UIKit

class MessagesInputToolbar: UIToolbar {
class MessagesInputToolbar: UIView {

let toolbarContentView = MessagesToolbarContentView.fromNib()

/*
// Only override draw() if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
override func draw(_ rect: CGRect) {
// Drawing code
var leftButtonAction: ()->() {
get {
return toolbarContentView.leftButtonAction
}
set {
toolbarContentView.leftButtonAction = newValue
}
}
var rightButtonAction: ()->() {
get {
return toolbarContentView.rightButtonAction
}
set {
toolbarContentView.rightButtonAction = newValue
}
}
*/
var messageText : String {
return toolbarContentView.messageText

var inputText : String {
get {
return toolbarContentView.inputText
}
set {
toolbarContentView.inputText = newValue
}
}

var settings = MessagesViewSettings() {
Expand Down
16 changes: 12 additions & 4 deletions MessagesView/MessagesToolbarContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ class MessagesToolbarContentView: UIView {
private var leftButtonEnabled: Bool = true
private var rightButtonEnabled: Bool = true

var leftButtonAction: (Void) -> () = {}
var rightButtonAction: (Void) -> () = {}

private var leftTintColor: UIColor {
return leftButtonEnabled ? settings.leftButtonTextColor : settings.leftButtonDisabledColor
}
Expand All @@ -57,7 +60,7 @@ class MessagesToolbarContentView: UIView {
@IBAction func didPressLeftButton(_ sender: AnyObject) {

if leftButtonEnabled {
settings.leftButtonAction()
leftButtonAction()
}

if settings.leftButtonHidesKeyboard {
Expand All @@ -68,7 +71,7 @@ class MessagesToolbarContentView: UIView {
@IBAction func didPressRightButton(_ sender: AnyObject) {

if rightButtonEnabled {
settings.rightButtonAction()
rightButtonAction()
}

if settings.rightButtonHidesKeyboard {
Expand All @@ -87,8 +90,13 @@ class MessagesToolbarContentView: UIView {
apply(settings: settings)
}
}
var messageText : String {
return messageEditorTextView.text
var inputText : String {
get {
return messageEditorTextView.text ?? ""
}
set {
messageEditorTextView.text = newValue
}
}

func righButton(show: Bool, animated: Bool) {
Expand Down
6 changes: 3 additions & 3 deletions MessagesView/MessagesToolbarContentView.xib
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<rect key="frame" x="0.0" y="0.0" width="432" height="78"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="6Ec-dF-1Fn" customClass="UIImageView">
<view contentMode="scaleAspectFit" translatesAutoresizingMaskIntoConstraints="NO" id="6Ec-dF-1Fn" customClass="UIImageView">
<rect key="frame" x="5" y="23" width="32" height="32"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Left" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="amt-9f-7ms">
Expand All @@ -38,7 +38,7 @@
<outletCollection property="gestureRecognizers" destination="xhb-ke-ACy" appends="YES" id="02m-NP-wt6"/>
</connections>
</view>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="PQK-3g-SCZ" customClass="UIImageView">
<view contentMode="scaleAspectFit" translatesAutoresizingMaskIntoConstraints="NO" id="PQK-3g-SCZ" customClass="UIImageView">
<rect key="frame" x="395" y="23" width="32" height="32"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="Right" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Su6-aD-T5D">
Expand All @@ -59,7 +59,7 @@
<outletCollection property="gestureRecognizers" destination="elv-KC-W68" appends="YES" id="LTt-wu-Dan"/>
</connections>
</view>
<textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" text="HI there!" textAlignment="natural" translatesAutoresizingMaskIntoConstraints="NO" id="2fz-9A-LKF" customClass="MessageEditorTextView" customModule="MessagesView" customModuleProvider="target">
<textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" textAlignment="natural" translatesAutoresizingMaskIntoConstraints="NO" id="2fz-9A-LKF" customClass="MessageEditorTextView" customModule="MessagesView" customModuleProvider="target">
<rect key="frame" x="45" y="23" width="342" height="32"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
Expand Down
100 changes: 55 additions & 45 deletions MessagesView/MessagesView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,14 @@ public class MessagesView: UIView {

@IBInspectable public var textInputFieldTextColor: UIColor = .black
@IBInspectable public var textInputFieldBackgroundColor: UIColor = .clear
@IBInspectable public var textInputTintColor: UIColor = .pumpkin
@IBInspectable public var textInputFieldTextPlaceholderText: String = "Write your message here"
@IBInspectable public var textInputFieldCornerRadius: CGFloat = 0.0
@IBInspectable public var textInputFieldFont: UIFont = UIFont.systemFont(ofSize: 10)
@IBInspectable public var textInputFieldFont: UIFont = .systemFont(ofSize: 10)

@IBInspectable public var textInputFieldTopSeparatorLineHeight: CGFloat = 1.0
@IBInspectable public var textInputFieldTopSeparatorLineColor: UIColor = .pumpkin
@IBInspectable public var textInputFieldTopSeparatorLineAlpha: CGFloat = 0.3
@IBInspectable public var textInputFieldTopSeparatorLineAlpha: CGFloat = 1.0

@IBInspectable public var inputToolbarBackgroundColor: UIColor = UIColor.white

Expand Down Expand Up @@ -101,13 +102,18 @@ public class MessagesView: UIView {
}

public var inputText: String {
return messagesInputToolbar.messageText
get {
return messagesInputToolbar.inputText
}
set {
messagesInputToolbar.inputText = newValue
}
}

var view: UIView!
public var settings = MessagesViewSettings.testChatSettings() {
public var settings = MessagesViewSettings() {
didSet {
messagesInputToolbar.settings = settings
apply(settings: settings)
}
}

Expand Down Expand Up @@ -187,11 +193,11 @@ public class MessagesView: UIView {
pinSubviewToEdges(subview: view)
registerCellNib()

settings.setLeftButtonAction {
self.delegate?.didTapLeftButton()
messagesInputToolbar.leftButtonAction = { [weak self] _ in
self?.delegate?.didTapLeftButton()
}
settings.setRightButtonAction {
self.delegate?.didTapRightButton()
messagesInputToolbar.rightButtonAction = { [weak self] _ in
self?.delegate?.didTapRightButton()
}

messagesInputToolbar.settings = settings
Expand Down Expand Up @@ -307,42 +313,46 @@ public class MessagesView: UIView {
}

private func readSettingsFromInpectables(settings: inout MessagesViewSettings) {
settings.leftMessageCellTextColor = self.leftMessageCellTextColor
settings.leftMessageCellBackgroundColor = self.leftMessageCellBackgroundColor
settings.rightMessageCellTextColor = self.rightMessageCellTextColor
settings.rightMessageCellBackgroundColor = self.rightMessageCellBackgroundColor

settings.collectionViewBackgroundColor = self.collectionViewBackgroundColor

settings.textInputFieldTextColor = self.textInputFieldTextColor
settings.textInputFieldBackgroundColor = self.textInputFieldBackgroundColor

settings.textInputFieldTopSeparatorLineHeight = self.textInputFieldTopSeparatorLineHeight
settings.textInputFieldTopSeparatorLineAlpha = self.textInputFieldTopSeparatorLineAlpha
settings.textInputFieldTopSeparatorLineColor = self.textInputFieldTopSeparatorLineColor
settings.textInputFieldTextPlaceholderText = self.textInputFieldTextPlaceholderText

settings.buttonSlideAnimationDuration = self.buttonSlideAnimationDuration
settings.inputToolbarBackgroundColor = self.inputToolbarBackgroundColor
settings.textInputFieldCornerRadius = self.textInputFieldCornerRadius

settings.leftButtonText = self.leftButtonText
settings.leftButtonShow = self.leftButtonShow
settings.leftButtonShowAnimated = self.leftButtonShowAnimated
settings.leftButtonTextColor = self.leftButtonTextColor
settings.leftButtonDisabledColor = self.leftButtonDisabledColor
settings.leftButtonBackgroundColor = self.leftButtonBackgroundColor
settings.leftButtonBackgroundImage = self.leftButtonBackgroundImage
settings.leftButtonCornerRadius = self.leftButtonCornerRadius

settings.rightButtonText = self.rightButtonText
settings.rightButtonShow = self.rightButtonShow
settings.rightButtonShowAnimated = self.rightButtonShowAnimated
settings.rightButtonTextColor = self.rightButtonTextColor
settings.rightButtonDisabledColor = self.rightButtonDisabledColor
settings.rightButtonBackgroundColor = self.rightButtonBackgroundColor
settings.rightButtonBackgroundImage = self.rightButtonBackgroundImage
settings.rightButtonCornerRadius = self.rightButtonCornerRadius

settings.leftMessageCellTextColor = leftMessageCellTextColor
settings.leftMessageCellBackgroundColor = leftMessageCellBackgroundColor
settings.rightMessageCellTextColor = rightMessageCellTextColor
settings.rightMessageCellBackgroundColor = rightMessageCellBackgroundColor

settings.collectionViewBackgroundColor = collectionViewBackgroundColor

settings.textInputFieldTextColor = textInputFieldTextColor
settings.textInputFieldBackgroundColor = textInputFieldBackgroundColor
settings.textInputTintColor = textInputTintColor
settings.textInputFieldTextPlaceholderText = textInputFieldTextPlaceholderText
settings.textInputFieldCornerRadius = textInputFieldCornerRadius
settings.textInputFieldFont = textInputFieldFont

settings.textInputFieldTopSeparatorLineHeight = textInputFieldTopSeparatorLineHeight
settings.textInputFieldTopSeparatorLineColor = textInputFieldTopSeparatorLineColor
settings.textInputFieldTopSeparatorLineAlpha = textInputFieldTopSeparatorLineAlpha

settings.inputToolbarBackgroundColor = inputToolbarBackgroundColor

settings.leftButtonText = leftButtonText
settings.leftButtonShow = leftButtonShow
settings.leftButtonShowAnimated = leftButtonShowAnimated
settings.leftButtonTextColor = leftButtonTextColor
settings.leftButtonDisabledColor = leftButtonDisabledColor
settings.leftButtonBackgroundColor = leftButtonBackgroundColor
settings.leftButtonBackgroundImage = leftButtonBackgroundImage
settings.leftButtonCornerRadius = leftButtonCornerRadius

settings.rightButtonText = rightButtonText
settings.rightButtonShow = rightButtonShow
settings.rightButtonShowAnimated = rightButtonShowAnimated
settings.rightButtonTextColor = rightButtonTextColor
settings.rightButtonDisabledColor = rightButtonDisabledColor
settings.rightButtonBackgroundColor = rightButtonBackgroundColor
settings.rightButtonBackgroundImage = rightButtonBackgroundImage
settings.rightButtonCornerRadius = rightButtonCornerRadius

settings.buttonSlideAnimationDuration = buttonSlideAnimationDuration
}

private func apply(settings: MessagesViewSettings) {
Expand Down
Loading

0 comments on commit d007b8e

Please sign in to comment.