Skip to content

Commit 06ecf04

Browse files
Foghrnystrom
authored andcommitted
Left button support - Clean up (#43)
* Rename inset property for left button so it matches the tint property * Clean up * More cleaning
1 parent 80e1db5 commit 06ecf04

File tree

1 file changed

+21
-34
lines changed

1 file changed

+21
-34
lines changed

MessageViewController/MessageView.swift

Lines changed: 21 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -110,50 +110,36 @@ public final class MessageView: UIView, MessageTextViewListener {
110110
}
111111
}
112112

113-
public var buttonLeftInset: CGFloat = 0 {
113+
public var leftButtonInset: CGFloat = 0 {
114114
didSet { setNeedsLayout() }
115115
}
116116

117117
public func set(buttonIcon: UIImage?, for state: UIControlState, type: buttonType) {
118+
let button: UIButton
118119
switch type {
119-
case .left:
120-
setLeft(buttonIcon: buttonIcon, for: state)
121-
break
122-
case .right:
123-
setRight(buttonIcon: buttonIcon, for: state)
124-
break
120+
case .left:
121+
button = leftButton
122+
case .right:
123+
button = rightButton
125124
}
125+
126+
button.setImage(buttonIcon, for: state)
126127
buttonLayoutDidChange()
127128
}
128129

129130
public func set(buttonTitle: String, for state: UIControlState, type: buttonType) {
131+
let button: UIButton
130132
switch type {
131133
case .left:
132-
setLeft(buttonTitle: buttonTitle, for: state)
133-
break
134+
button = leftButton
134135
case .right:
135-
setRight(buttonTitle: buttonTitle, for: state)
136-
break
136+
button = rightButton
137137
}
138+
139+
button.setTitle(buttonTitle, for: state)
138140
buttonLayoutDidChange()
139141
}
140142

141-
private func setLeft(buttonIcon: UIImage?, for state: UIControlState) {
142-
leftButton.setImage(buttonIcon, for: state)
143-
}
144-
145-
private func setLeft(buttonTitle: String, for state: UIControlState) {
146-
leftButton.setTitle(buttonTitle, for: state)
147-
}
148-
149-
private func setRight(buttonIcon: UIImage?, for state: UIControlState) {
150-
rightButton.setImage(buttonIcon, for: state)
151-
}
152-
153-
private func setRight(buttonTitle: String, for state: UIControlState) {
154-
rightButton.setTitle(buttonTitle, for: state)
155-
}
156-
157143
public var leftButtonTint: UIColor {
158144
get { return leftButton.tintColor }
159145
set {
@@ -192,16 +178,17 @@ public final class MessageView: UIView, MessageTextViewListener {
192178
}
193179

194180
public func addButton(target: Any, action: Selector, type: buttonType) {
181+
let button: UIButton
195182
switch type {
196183
case .left:
197-
leftButton.addTarget(target, action: action, for: .touchUpInside)
184+
button = leftButton
198185
leftButtonAction = action
199-
break
200186
case .right:
201-
rightButton.addTarget(target, action: action, for: .touchUpInside)
187+
button = rightButton
202188
rightButtonAction = action
203-
break
204189
}
190+
191+
button.addTarget(target, action: action, for: .touchUpInside)
205192
}
206193

207194
public override var keyCommands: [UIKeyCommand]? {
@@ -243,16 +230,16 @@ public final class MessageView: UIView, MessageTextViewListener {
243230
leftButton.frame = (showLeftButton) ? leftButtonFrame : .zero
244231

245232
let textViewFrame = CGRect(
246-
x: ((showLeftButton) ? leftButtonFrame.maxX : 0) + buttonLeftInset,
233+
x: ((showLeftButton) ? leftButtonFrame.maxX : 0) + leftButtonInset,
247234
y: insetBounds.minY,
248-
width: insetBounds.width - ((showLeftButton) ? leftButtonSize.width : 0) - buttonLeftInset - rightButtonSize.width,
235+
width: insetBounds.width - ((showLeftButton) ? leftButtonSize.width : 0) - leftButtonInset - rightButtonSize.width,
249236
height: textViewHeight
250237
)
251238
textView.frame = textViewFrame
252239

253240
// adjust by bottom offset so content is flush w/ text view
254241
let rightButtonFrame = CGRect(
255-
x: textViewFrame.maxX + buttonLeftInset,
242+
x: textViewFrame.maxX + leftButtonInset,
256243
y: textViewFrame.maxY - rightButtonSize.height + rightButton.bottomHeightOffset,
257244
width: rightButtonSize.width,
258245
height: rightButtonSize.height

0 commit comments

Comments
 (0)