RxDataSource ondersteunen meerdere secties met animatie

stemmen
0

Ik heb DurationSectionModeldat zich SectionModelTypemeerdere secties ondersteunen.

Ik ben het verbergen van sommige cellen en rijen en ze werken prima, maar ik kon geen animatie te krijgen, dus om de animatie te krijgen ik wil DurationSectionModeluit te breidenAnimatableSectionModelType

Ik begrijp niet hoe ik dit omzetten enum naar structuren.

class DurationViewModel {

  enum SectionItem {
    case titleCell(title: String, value: String)
    case tickCell(title: String, value: Bool)
    case datePickerCell(title: String, value: String)
  }

  enum DurationSectionModel {
    case startDate(items: [SectionItem])
    case periodType(items: [SectionItem])
    case period(items: [SectionItem])
  }

  var startDateSection: [SectionItem] = [.titleCell(title: Start Date, value: 10/12/2019)]
  var periodTypeSection: [SectionItem] = [.tickCell(title: No end date, value: false),
                                          .tickCell(title: Until date, value: false),
                                          .tickCell(title: No end date, value: false)]
  var periodSection: [SectionItem] = [.datePickerCell(title: , value: )]

  var tableState = PublishRelay<[DurationSectionModel]>()

  func tableState() {
    let sections: [DurationSectionModel] = [
      .startDate(items: startDateSection),
      .periodType(items: periodTypeSection),
    ]
    tableState.accept(sections)
  }
}

extension DurationViewModel.DurationSectionModel: SectionModelType {
  typealias Item = DurationViewModel.SectionItem

  var items: [DurationViewModel.SectionItem] {
    switch self {
    case .startDate(items: let items):
      return items.map { $0 }
    case .periodType(items: let periods):
      return periods.map { $0 }
    case .period(items: let period):
      return period.map { $0 }
    }
  }

  init(original: DurationViewModel.DurationSectionModel, items: [DurationViewModel.SectionItem]) {
    switch original {
    case let .startDate(items: items):
      self = .startDate(items: items)

    case let .periodType(items: items):
      self = .periodType(items: items)

    case let .period(items: items):
      self = .period(items: items)
    }
  }
}
De vraag is gesteld op 09/10/2019 om 13:01
bron van user
In andere talen...                            

Cookies help us deliver our services. By using our services, you agree to our use of cookies. Learn more