From c17a99014b8dbcd7139fa376fb349e893dc62fdf Mon Sep 17 00:00:00 2001 From: Anton Schukin Date: Tue, 26 Jul 2016 17:55:42 +0100 Subject: [PATCH] Move ChatInputItem selected and enabled properties to protocol extension --- .../Source/Input/ChatInputBarPresenter.swift | 4 ++-- .../Source/Input/ChatInputItem.swift | 19 ++++++++++++++++++- .../Input/Photos/PhotosChatInputItem.swift | 6 ------ .../Source/Input/Text/TextChatInputItem.swift | 7 ------- 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/ChattoAdditions/Source/Input/ChatInputBarPresenter.swift b/ChattoAdditions/Source/Input/ChatInputBarPresenter.swift index aa1103a..c9fc49a 100644 --- a/ChattoAdditions/Source/Input/ChatInputBarPresenter.swift +++ b/ChattoAdditions/Source/Input/ChatInputBarPresenter.swift @@ -60,10 +60,10 @@ protocol ChatInputBarPresenter: class { private(set) var focusedItem: ChatInputItemProtocol? { willSet { - self.focusedItem?.selected = false + self.focusedItem?.setSelected(false) } didSet { - self.focusedItem?.selected = true + self.focusedItem?.setSelected(true) } } diff --git a/ChattoAdditions/Source/Input/ChatInputItem.swift b/ChattoAdditions/Source/Input/ChatInputItem.swift index bad9389..72e06b6 100644 --- a/ChattoAdditions/Source/Input/ChatInputItem.swift +++ b/ChattoAdditions/Source/Input/ChatInputItem.swift @@ -35,7 +35,24 @@ public protocol ChatInputItemProtocol: AnyObject { var inputView: UIView? { get } var presentationMode: ChatInputItemPresentationMode { get } var showsSendButton: Bool { get } - var selected: Bool { get set } func handleInput(input: AnyObject) } + +extension ChatInputItemProtocol { + func selected() -> Bool { + return self.inputButton.selected + } + + func setSelected(selected: Bool) { + self.inputButton.selected = selected + } + + func enabled() -> Bool { + return self.inputButton.enabled + } + + func setEnabled(enabled: Bool) { + self.inputButton.enabled = enabled + } +} diff --git a/ChattoAdditions/Source/Input/Photos/PhotosChatInputItem.swift b/ChattoAdditions/Source/Input/Photos/PhotosChatInputItem.swift index b671a2b..23afc9a 100644 --- a/ChattoAdditions/Source/Input/Photos/PhotosChatInputItem.swift +++ b/ChattoAdditions/Source/Input/Photos/PhotosChatInputItem.swift @@ -57,12 +57,6 @@ public class PhotosChatInputItem: ChatInputItemProtocol { return photosInputView }() - public var selected = false { - didSet { - self.internalInputButton.selected = self.selected - } - } - // MARK: - ChatInputItemProtocol public var presentationMode: ChatInputItemPresentationMode { diff --git a/ChattoAdditions/Source/Input/Text/TextChatInputItem.swift b/ChattoAdditions/Source/Input/Text/TextChatInputItem.swift index 9128754..3485d4e 100644 --- a/ChattoAdditions/Source/Input/Text/TextChatInputItem.swift +++ b/ChattoAdditions/Source/Input/Text/TextChatInputItem.swift @@ -45,13 +45,6 @@ public class TextChatInputItem { lazy private var internalInputButton: ChatInputButton = { return ChatInputButton.makeInputButton(withAppearance: self.buttonAppearance) }() - - // Move to protocol extension - public var selected = false { - didSet { - self.internalInputButton.selected = self.selected - } - } } // MARK: - ChatInputItemProtocol