From ce49f0fcb6306631c0a45e6e91ef358f8c3104b4 Mon Sep 17 00:00:00 2001 From: pan Date: Sat, 10 Jun 2017 01:22:10 +0800 Subject: [PATCH] Add "inputToolbarDoneClosure" Improve "willUpdateClosure", which could change value in this closure --- SwiftForms/cells/base/FormBaseCell.swift | 3 +++ .../descriptors/FormRowDescriptor.swift | 26 ++++++++++++++----- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/SwiftForms/cells/base/FormBaseCell.swift b/SwiftForms/cells/base/FormBaseCell.swift index e294eb1..b1f06a4 100644 --- a/SwiftForms/cells/base/FormBaseCell.swift +++ b/SwiftForms/cells/base/FormBaseCell.swift @@ -73,6 +73,9 @@ open class FormBaseCell: UITableViewCell { } internal func handleDoneAction(_: UIBarButtonItem) { + if let inputToolbarDoneClosure = rowDescriptor?.configuration.cell.inputToolbarDoneClosure { + inputToolbarDoneClosure(self) + } firstResponderElement()?.resignFirstResponder() } diff --git a/SwiftForms/descriptors/FormRowDescriptor.swift b/SwiftForms/descriptors/FormRowDescriptor.swift index 9760ca3..2442790 100644 --- a/SwiftForms/descriptors/FormRowDescriptor.swift +++ b/SwiftForms/descriptors/FormRowDescriptor.swift @@ -47,9 +47,10 @@ public final class FormRowDescriptor { public var placeholder: String? public var showsInputToolbar: Bool public var required: Bool - public var willUpdateClosure: ((FormRowDescriptor) -> Void)? + public var willUpdateClosure: ((FormRowDescriptor, AnyObject?, inout AnyObject?) -> Void)? public var didUpdateClosure: ((FormRowDescriptor) -> Void)? public var visualConstraintsClosure: ((FormBaseCell) -> [String])? + public var inputToolbarDoneClosure: ((FormBaseCell) -> Void)? public init() { cellClass = nil @@ -60,6 +61,7 @@ public final class FormRowDescriptor { willUpdateClosure = nil didUpdateClosure = nil visualConstraintsClosure = nil + inputToolbarDoneClosure = nil } } @@ -128,14 +130,24 @@ public final class FormRowDescriptor { public var title: String? + private var _value: AnyObject? public var value: AnyObject? { - willSet { - guard let willUpdateBlock = configuration.cell.willUpdateClosure else { return } - willUpdateBlock(self) + set { + if newValue !== _value { + var newV = newValue + if let willUpdateBlock = configuration.cell.willUpdateClosure { + willUpdateBlock(self, _value, &newV) + } + + _value = newV + + if let didUpdateBlock = configuration.cell.didUpdateClosure { + didUpdateBlock(self) + } + } } - didSet { - guard let didUpdateBlock = configuration.cell.didUpdateClosure else { return } - didUpdateBlock(self) + get { + return _value } }