RxSwiftCommunity / RxDataSources

UITableView and UICollectionView Data Sources for RxSwift (sections, animated updates, editing ...)
MIT License
3.1k stars 496 forks source link

textView in tableView cell #424

Open tominisx-12 opened 1 year ago

tominisx-12 commented 1 year ago

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!