This repository has been archived by the owner on Apr 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
BumpTableModel.h
350 lines (267 loc) · 7.67 KB
/
BumpTableModel.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
#import <Foundation/Foundation.h>
@class BumpTableSection;
@class BumpTableRow;
typedef BOOL(^BumpTableRowPredicate)(BumpTableRow *row);
/*!
@class BumpTableModel
@abstract
The `BumpTableModel` object is the model backing for a BumpTableView
@discussion
*/
@interface BumpTableModel : NSObject
/*!
@abstract
The table section objects that make up the model
@discussion
This should only contain `BumpTableSection` objects
*/
@property (nonatomic, copy) NSArray *sections;
/*!
@method
@abstract
Creates and returns an model object configured with the sections provided
@param sections Array of `BumpTableSection` objects
*/
+ (instancetype)modelWithSections:(NSArray *)sections;
/*!
@method
@abstract
Creates and returns an model object configured with the rows provided
inside of a single section with the key "all"
@param rows Array of `BumpTableRow` objects
*/
+ (instancetype)modelWithRows:(NSArray *)rows;
/*!
@method
@abstract
Returns a dictionary containing the `NSIndexPath` of each section keyed on their unique keys
*/
- (NSDictionary *)sectionIndexes;
/*!
@method
@abstract
Returns a dictionary containing the `NSIndexPath` of each row, keyed on their unique keys
*/
- (NSDictionary *)rowIndexPaths;
/*!
@method
@abstract
Returns an array that contains each table-row, resulting from a filter of all
rows in the current model using the given string
@param searchString The string to use to filter
*/
- (NSMutableArray *)rowsForSearchString:(NSString *)searchString;
/*!
@method
@abstract
Same as rowsForSearchString, except the resulting filtered rows are wrapped
in a `BumpTableModel` and returned
@param searchString The string to use to filter
*/
- (BumpTableModel *)modelForSearchString:(NSString *)searchString;
/*!
@method
@abstract
Returns the `NSIndexPath` for a given row. Will return nil if row does not exist in this table
@param row A table row that exists in this model
*/
- (NSIndexPath *)indexPathForRow:(BumpTableRow *)row;
/*!
@method
@abstract
Returns a list of BumpTableRow objects that match the given predicate
@param predicate block that takes a row and returns a boolean
*/
- (NSArray *)rowsForPredicate:(BumpTableRowPredicate)predicate;
@end
/*!
@typedef BumpTableHeaderFooterGenerator
@abstract
Block used to create and return a UIView to be used as a table header or footer
*/
typedef UIView *(^BumpTableHeaderFooterGenerator)(void);
/*!
@class BumpTableHeaderFooter
@abstract
Model for a table header or footer
*/
@interface BumpTableHeaderFooter : NSObject
/*!
@abstract
The title of this header or footer. Note that this is ignored
by UITableView if a generator is supplied.
*/
@property (nonatomic, retain) NSString *title;
/*!
@abstract
the height of the header or footer view
*/
@property (nonatomic) CGFloat height;
/*!
@abstract
The generator that it used to create the table header or footer
*/
@property (nonatomic, copy) BumpTableHeaderFooterGenerator generator;
/*!
@abstract
Generates the view or returns nil if no generator is set
*/
- (UIView *)view;
/*!
@method
@abstract
Creates and returns a headerFooter model object, to be set on a table model
@param height The height of the header or footer view
@param generator The block used to create the header or footer view
*/
+ (instancetype)headerFooterForHeight:(CGFloat)height generator:(BumpTableHeaderFooterGenerator)generator;
/*!
@method
@abstract
Creates and returns a headerFooter model object, to be set on a table model
@param title The title of this header or footer
*/
+ (instancetype)headerFooterWithTitle:(NSString *)title;
@end
/*!
@class BumpTableSection
@abstract
The model object used to describe a table section
*/
@interface BumpTableSection : NSObject
/*!
@abstract
Must be unique in a table, specific within section. Used to animate transitions
*/
@property (nonatomic, strong) NSObject <NSCopying> *key;
/*!
@abstract
Array of table row objects contained in this section
*/
@property (nonatomic, strong) NSArray *rows;
/*!
@abstract
The index title to use if the table has scrubber enabled
*/
@property (nonatomic, strong) NSString *indexTitle;
/*!
@abstract
Header model for table
*/
@property (nonatomic, strong) BumpTableHeaderFooter *header;
/*!
@abstract
Footer model for table
*/
@property (nonatomic, strong) BumpTableHeaderFooter *footer;
/*!
@method
@abstract
Creates and returns a table section with the given key and rows
@param key A unique key used to identify this section
@param rows The rows that should be in this section (cannot be nil)
*/
+ (instancetype)sectionWithKey:(NSObject<NSCopying>*)key rows:(NSArray*)rows;
@end
/*!
@typedef BumpTableCellGenerator
@abstract
@discussion
*/
typedef UITableViewCell *(^BumpTableCellGenerator)(NSString *reuseIdentifier);
/*!
@typedef BumpTableCellUpdater
@abstract
@discussion
*/
typedef void (^BumpTableCellUpdater)(id cell);
/*!
@typedef BumpTableCellOnTap
@abstract
@discussion
*/
typedef void (^BumpTableCellOnTap)(id cell);
/*!
@typedef BumpTableCellOnSwipeConfirmation
@abstract
@discussion
*/
typedef void (^BumpTableCellOnSwipeConfirmation)(id cell);
/*!
@class BumpTableRow
@abstract
The model object used to describe a table row
*/
@interface BumpTableRow : NSObject
/*!
@abstract
Must be unique in a table, specific to the data of one row. Used to animate transitions
*/
@property (nonatomic, strong) NSObject <NSCopying> *key;
/*!
@abstract
String to be used for searching
*/
@property (nonatomic, copy) NSString *searchString;
/*!
@abstract
The height of the cell, needed by UITableView for upfront calculation
*/
@property (nonatomic) CGFloat height;
/*!
@abstract
Identifies the cell for use by other similar rows
*/
@property (nonatomic, strong) NSString *reuseIdentifier;
/*!
@abstract
Indicates whether this row is selectable. Defaults to yes.
*/
@property (nonatomic) BOOL selectable;
/*!
@abstract
Indicates whether this row is currently selected.
*/
@property (nonatomic) BOOL selected;
/*!
@abstract
if a cell of the designated reuseId can't be produced by recycling old ones,
this will generate a new one. Note: this may not be called for all rows,
and the cell returned may be recycled for other rows
*/
@property (nonatomic, copy) BumpTableCellGenerator generator;
/*!
@abstract
This is called to customize the cell for this particular row.
This will be called upon creation of a new cell, when the cell recycles,
and when the model changes (if cell is visible)
*/
@property (nonatomic, copy) BumpTableCellUpdater customizer;
/*!
@abstract
This get's called when the user taps on a row.
It should be used if you don't care about selection state callbacks below
*/
@property (nonatomic, copy) BumpTableCellOnTap onTap;
/*!
@abstract
This gets called when the row's swipe confirmation button is pressed
*/
@property (nonatomic, copy) BumpTableCellOnSwipeConfirmation onSwipeConfirmation;
/*!
@method
@abstract
Creates and returns a table row with the given information
@param key Unique key used to identify this row (for transition purposes)
@param height The height of this row
@param reuseIdentifier The reuseIdentifier to use for cell recycling
@param generator The block used to create and initially configure a cell for this row
*/
+ (instancetype)rowWithKey:(NSObject <NSCopying>*)key
height:(CGFloat)height
reuseIdentifier:(NSString *)reuseIdentifier
generator:(BumpTableCellGenerator)generator;
+ (instancetype)rowWithKey:(NSObject <NSCopying>*)key
height:(CGFloat)height
reuseIdentifier:(NSString *)reuseIdentifier;
@end