diff --git a/Sources/UIControl.swift b/Sources/UIControl.swift index 38e86d2..9d9a7c4 100644 --- a/Sources/UIControl.swift +++ b/Sources/UIControl.swift @@ -47,6 +47,7 @@ import ReactiveKit control.addTarget(self, action: #selector(RKUIControlHelper.eventHandlerEditingChanged), forControlEvents: UIControlEvents.EditingChanged) control.addTarget(self, action: #selector(RKUIControlHelper.eventHandlerEditingDidEnd), forControlEvents: UIControlEvents.EditingDidEnd) control.addTarget(self, action: #selector(RKUIControlHelper.eventHandlerEditingDidEndOnExit), forControlEvents: UIControlEvents.EditingDidEndOnExit) + control.addTarget(self, action: #selector(RKUIControlHelper.eventHandlerAllEditingEvents), forControlEvents: UIControlEvents.AllEditingEvents) } func eventHandlerTouchDown() { @@ -104,7 +105,11 @@ import ReactiveKit func eventHandlerEditingDidEndOnExit() { pushStream.next(.EditingDidEndOnExit) } - + + func eventHandlerAllEditingEvents() { + pushStream.next(.AllEditingEvents) + } + deinit { control?.removeTarget(self, action: nil, forControlEvents: UIControlEvents.AllEvents) pushStream.completed() diff --git a/Sources/UITextField.swift b/Sources/UITextField.swift index de81eef..7d381ab 100644 --- a/Sources/UITextField.swift +++ b/Sources/UITextField.swift @@ -48,12 +48,15 @@ extension UITextField { }.disposeIn(rBag) self.rControlEvent - .filter { $0 == UIControlEvents.EditingChanged } + .filter { $0 == UIControlEvents.AllEditingEvents } .observeNext { [weak self] event in guard let unwrappedSelf = self else { return } - updatingFromSelf = true - unwrappedSelf.rText.value = unwrappedSelf.text - updatingFromSelf = false + // only send to rText if value changed, as .AllEditingEvents reports more than just changes + if unwrappedSelf.rText.value != unwrappedSelf.text { + updatingFromSelf = true + unwrappedSelf.rText.value = unwrappedSelf.text + updatingFromSelf = false + } }.disposeIn(rBag) return rText @@ -76,12 +79,15 @@ extension UITextField { }.disposeIn(rBag) self.rControlEvent - .filter { $0 == UIControlEvents.EditingChanged } + .filter { $0 == UIControlEvents.AllEditingEvents } .observeNext { [weak self] event in guard let unwrappedSelf = self else { return } - updatingFromSelf = true - unwrappedSelf.rAttributedText.value = unwrappedSelf.attributedText - updatingFromSelf = false + // only sent to rAttributedText if value changed, as .AllEditingEvents reports more than just changes + if unwrappedSelf.rAttributedText.value != unwrappedSelf.attributedText { + updatingFromSelf = true + unwrappedSelf.rAttributedText.value = unwrappedSelf.attributedText + updatingFromSelf = false + } }.disposeIn(rBag) return rAttributedText