parent
483c8d36c2
commit
53fde354c9
@ -0,0 +1,75 @@
|
||||
//
|
||||
// MusicStyleViewModel.swift
|
||||
// IndieMusic
|
||||
//
|
||||
// Created by WenLei on 2024/1/5.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import RxSwift
|
||||
import RxCocoa
|
||||
|
||||
class MusicStyleViewModel: ViewModel, ViewModelType {
|
||||
|
||||
struct Input {
|
||||
let viewWillAppear: ControlEvent<Bool>
|
||||
let selection: Driver<IndexPath>
|
||||
|
||||
let dropButtonTrigger: Driver<Void>
|
||||
|
||||
}
|
||||
|
||||
struct Output {
|
||||
let items: BehaviorRelay<[MusicStyleSection]>
|
||||
let selection: Driver<IndexPath>
|
||||
let itemSelected: PublishSubject<MusicStyle>
|
||||
|
||||
let isExpand: BehaviorRelay<Bool>
|
||||
}
|
||||
|
||||
let itemSelected = PublishSubject<MusicStyle>()
|
||||
let items = BehaviorRelay<[MusicStyleSection]>.init(value: [])
|
||||
|
||||
let isExpand = BehaviorRelay<Bool>.init(value: false)
|
||||
|
||||
|
||||
func transform(input: Input) -> Output {
|
||||
|
||||
input.viewWillAppear.subscribe { (_) in
|
||||
|
||||
}.disposed(by: rx.disposeBag)
|
||||
|
||||
|
||||
input.dropButtonTrigger.drive { _ in
|
||||
|
||||
self.isExpand.accept(!self.isExpand.value)
|
||||
|
||||
}.disposed(by: rx.disposeBag)
|
||||
|
||||
|
||||
|
||||
|
||||
let item = MusicStyle.init(title: "测试", subTitle: "123", backgroundImage: "")
|
||||
let musicStyleSection = MusicStyleSection.init(items: [item, item, item, item], header: "后摇", headerSub: "Post Rock", content: "总在不经意间获得简单朴素且乐趣其中的感怀,这种感怀的妙处在于它没有试图去提炼出任何的真理,他就像我们恬然的谈话里总夹杂着“那我懂你的意思了”,但是否是真的明白,却不然得知。即", isExpand: false)
|
||||
|
||||
|
||||
items.accept([musicStyleSection])
|
||||
|
||||
|
||||
input.selection.drive { indexPath in
|
||||
guard let sectionItem = self.items.value.first?.items[indexPath.row] else { return }
|
||||
self.itemSelected.onNext(sectionItem)
|
||||
}.disposed(by: rx.disposeBag)
|
||||
|
||||
|
||||
let journal = PublishSubject<JournalDetail>.init()
|
||||
|
||||
|
||||
return Output.init(items: items,
|
||||
selection: input.selection,
|
||||
itemSelected: itemSelected,
|
||||
isExpand: isExpand
|
||||
)
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in new issue