9
9
import Material
10
10
import UIKit
11
11
12
- class PreviewCardCell : BaseTableViewCell {
12
+ class PreviewCardCell : BaseTableViewCell < PreviewCardCellViewModel > {
13
13
let previewButton = IconButton ( image: Icon . cm. skipForward, tintColor: BKColor . grey. base)
14
14
let copyButton = IconButton ( image: UIImage ( named: " baseline_file_copy_white_24pt " ) , tintColor: BKColor . grey. base)
15
15
@@ -142,23 +142,22 @@ class PreviewCardCell: BaseTableViewCell {
142
142
noticeLabel. addGestureRecognizer ( UITapGestureRecognizer ( ) )
143
143
}
144
144
145
- override func bindViewModel( model: ViewModel ) {
146
- guard let viewModel = model as? PreviewCardCellViewModel else {
147
- return
148
- }
149
- viewModel. title
145
+ override func bindViewModel( model: PreviewCardCellViewModel ) {
146
+ super. bindViewModel ( model: model)
147
+
148
+ model. title
150
149
. bind ( to: self . titleLabel. rx. text) . disposed ( by: rx. reuseBag)
151
- viewModel . body
150
+ model . body
152
151
. bind ( to: self . bodyLabel. rx. text) . disposed ( by: rx. reuseBag)
153
- viewModel . content
152
+ model . content
154
153
. bind ( to: self . contentLabel. rx. attributedText) . disposed ( by: rx. reuseBag)
155
- viewModel . notice
154
+ model . notice
156
155
. bind ( to: self . noticeLabel. rx. attributedText) . disposed ( by: rx. reuseBag)
157
- viewModel . contentImage
156
+ model . contentImage
158
157
. compactMap { $0 }
159
158
. bind ( to: self . contentImageView. rx. image)
160
159
. disposed ( by: rx. reuseBag)
161
- viewModel . contentImage
160
+ model . contentImage
162
161
. map { $0 == nil }
163
162
. bind ( to: self . contentImageView. rx. isHidden)
164
163
. disposed ( by: rx. reuseBag)
@@ -170,14 +169,14 @@ class PreviewCardCell: BaseTableViewCell {
170
169
// 仅在有 moreViewModel 时 点击
171
170
weakModel? . previewModel. moreViewModel
172
171
}
173
- . bind ( to: viewModel . noticeTap)
172
+ . bind ( to: model . noticeTap)
174
173
. disposed ( by: rx. reuseBag)
175
174
176
175
// 点击复制
177
176
copyButton. rx. tap. map { [ weak self] ( ) -> String in
178
177
self ? . contentLabel. text ?? " "
179
178
}
180
- . bind ( to: viewModel . copy)
179
+ . bind ( to: model . copy)
181
180
. disposed ( by: rx. reuseBag)
182
181
183
182
// 点击预览
@@ -189,7 +188,7 @@ class PreviewCardCell: BaseTableViewCell {
189
188
}
190
189
return nil
191
190
}
192
- . bind ( to: viewModel . preview)
191
+ . bind ( to: model . preview)
193
192
. disposed ( by: rx. reuseBag)
194
193
}
195
194
}
0 commit comments