RxDataSource en charge plusieurs sections avec animation

voix
0

Je DurationSectionModelqui se prolonge SectionModelTypepour supporter de multiples sections.

Je me cache certaines cellules et les lignes et ils fonctionnent très bien , mais je ne pouvais pas obtenir une animation, donc afin d'obtenir l' animation que je veux DurationSectionModeld'étendreAnimatableSectionModelType

Je ne comprends pas comment je convertir cette ENUM à structs.

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)
    }
  }
}
Créé 09/10/2019 à 13:01
source utilisateur
Dans d'autres langues...                            

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