I have two textfields. I want to open a bottomsheet when the first textfield is tapped. And the other textfield is accepting user input regularly.
This is my trigger when the produklistrikDropdown
text field with edittingDidBegin
.
produkListrikDropDown.rx.controlEvent(.editingDidBegin)
.subscribe(onNext:{
self.dismissKeyboard()
print("produk Listrik Field did begin")
self.viewModel.showProdukListrik()
})
.disposed(by: disposeBag)
And after I choose a product from the bottom sheet it just change the text of the field to the one i choose.
viewModel.currentProdukListBehaviorSubject
.map{$0?.rawValue}
.subscribe(onNext: { [unowned self] in
if produkListrikDropDown.text != $0 {
produkListrikDropDown.text = $0
}
})
.disposed(by: disposeBag)
This is my second textfield configuration. Just a regular textfield receiving input from the user.
idPelangganField.rx.text
.bind(to: viewModel.currentIdPelangganBehaviorSubject)
.disposed(by: disposeBag)
When I tapped the first textfield and choose a product, its acting okay. But when I tapped the second textfield and tapped back to the first textfield, the edittingDidBegin on the first textfield triggered twice. This doesn't happen on IOS 12.4.
You can clone this repo to reproduce the problem https://github.com/Bobbyphtr/TextfieldDidEdittingProblem/tree/master
I've found a better way without sacrificing the use of textfield. Like @Daniel T. said, that we can use a tap gesture recognizer on it. I put a Tag Gesture Recognizer for the UITextField and set it to receive touch down
events. It eliminates any side effects of the textFieldShouldBeginEditting(_:)
and also not use any RxSwift to make the call.