RxSwiftCommunity / RxDataSources

UITableView and UICollectionView Data Sources for RxSwift (sections, animated updates, editing ...)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

textView in tableView cell

tominisx-12 opened this issue · comments

Hi, I'm using RxTableViewSectionedAnimatedDataSource to create table view. One of the cells have textview. I subscribe to changes in textview text as follows:

        textView.rx.text.orEmpty
            .subscribe(onNext: { [weak self] text in
                self.viewModel.updateNote(note: text)
            })
            .disposed(by: disposeBag)

Then, I modify my textview text data in viewModel:

var subject = BehaviorRelay<[EventSectionModel]>.init(value: [])

    func updateNote(note: String) {
        var newSections = subject.value
        if let sectionIndex = newSections.firstIndex(where: { section in
            section.items.contains(where: { item in
                if case let .typeC(info) = item, info.noteName == noteName {
                    return true
                } else {
                    return false
                }
            })
        }), let itemIndex = newSections[sectionIndex].items.firstIndex(where: { item in
            if case let .typeC(info) = item, info.noteName == noteName {
                return true
            } else {
                return false
            }
        }) {
            var updatedItem = newSections[sectionIndex].items[itemIndex]
            if case .typeC(var info) = newSections[sectionIndex].items[itemIndex] {
                info.note = note
                updatedItem = .typeC(info)
                newSections[sectionIndex].items[itemIndex] = updatedItem
                subject.accept(newSections)
            }
        } else {
            print("No matching item found")
        }
    }

The problem is, when I call line bellow my cell with textview is reloaded and it causes keyboard to dismiss.
subject.accept(newSections)

So every time user types a letter, it dismisses keyboard. How to overcome this?

Thanks a lot! Any help/tips are welcome!