RxSwiftCommunity / RxDataSources

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

is there possible to make collapsed menu

YunusDeveloper opened this issue · comments

Hello!

I have 3 sections and when user tap it should open and show it child datas when user again tap it should close current table views cell. I mean, I'm trying to make collapsed table view. is there possible to make it. Like this
cell

Hello!

I have 3 sections and when user tap it should open and show it child datas when user again tap it should close current table views cell. I mean, I'm trying to make collapsed table view. is there possible to make it. Like this

Yes, it is possible.

public struct ExpandableListVM<T, H> {
  /// Model for cell with expand button
  public let headerItem: H

  /// raw items
  public let _items: [T]

  /// items are shown only when isExpanded == true
  public var items: [T] {
    isExpanded ? _items : []
  }

  public let isExpanded: Bool

  public init(headerItem: H, items: [T], isExpanded: Bool) {
    self.headerItem = headerItem
    _items = items
    self.isExpanded = isExpanded
  }

  // when expand button is tapped, get new model with this method 
  public func togglingExpand() -> Self {
    copy(isExpanded: !isExpanded)
  }

  public func copy(isExpanded: Bool) -> Self {
    .init(headerItem: headerItem, items: _items, isExpanded: isExpanded)
  }
}

@iDmitriyy can you please showed how use this struct in real example ?

commented

@iDmitriyy can you please showed how use this struct in real example ?

Maybe you can use RxRelay as the Observable, when sectionTitle is tapped,change the value of RxRelay object.
As the RxRelay object has binded to tableView, the tableView should reload.

commented

@iDmitriyy can you please showed how use this struct in real example ?

this is a demo I write:
https://github.com/Dast1Woop/RxFoldableAndEditableSectionsDemo