Skip to content

Commit 0cb38c0

Browse files
committed
remove cell registration and creation from collection view data source
1 parent 1981484 commit 0cb38c0

File tree

3 files changed

+19
-576
lines changed

3 files changed

+19
-576
lines changed

FirebaseDatabaseUI/FirebaseArray.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ NS_ASSUME_NONNULL_BEGIN
4747

4848
/**
4949
* The delegate object that array changes are surfaced to, which conforms to the
50-
* [FirebaseArrayDelegate Protocol](FirebaseArrayDelegate).
50+
* @c FirebaseArrayDelegate protocol.
5151
*/
5252
@property(weak, nonatomic, nullable) id<FirebaseArrayDelegate> delegate;
5353

FirebaseDatabaseUI/FirebaseCollectionViewDataSource.h

Lines changed: 10 additions & 338 deletions
Original file line numberDiff line numberDiff line change
@@ -46,203 +46,19 @@ NS_ASSUME_NONNULL_BEGIN
4646
*/
4747
@interface FirebaseCollectionViewDataSource : FirebaseDataSource<UICollectionViewDataSource>
4848

49-
/**
50-
* The model class to coerce FIRDataSnapshots to (if desired). For instance, if
51-
* the modelClass is set
52-
* to [Message class] in Obj-C or Message.self in Swift, then objects of type
53-
* Message will be
54-
* returned instead of type FIRDataSnapshot.
55-
* Defaults to FIRDataSnapshot.
56-
*/
57-
@property(strong, nonatomic, null_resettable) Class modelClass;
58-
59-
/**
60-
* The cell class to coerce UICollectionViewCells to (if desired). For instance,
61-
* if the cellClass is
62-
* set to [CustomCollectionViewCell class] in Obj-C or CustomCollectionViewCell
63-
* in Swift, then
64-
* objects of type CustomCollectionViewCell will be returned instead of type
65-
* UICollectionViewCell.
66-
* Defaults to UICollectionViewCell.
67-
*/
68-
@property(strong, nonatomic, null_resettable) Class cellClass;
69-
70-
/**
71-
* The reuse identifier for cells in the UICollectionView.
72-
*/
73-
@property(strong, nonatomic) NSString *reuseIdentifier;
74-
7549
/**
7650
* The UICollectionView instance that operations (inserts, removals, moves,
77-
* etc.) are performed
78-
* against.
51+
* etc.) are performed against. The data source does not claim ownership of
52+
* the collection view it populates.
7953
*/
80-
@property(strong, nonatomic) UICollectionView *collectionView;
81-
82-
/**
83-
* Property to keep track of prototype cell use, to not register a class for the
84-
* UICollectionView or
85-
* do similar book keeping.
86-
*/
87-
@property BOOL hasPrototypeCell;
54+
@property (nonatomic, readonly, weak) UICollectionView *collectionView;
8855

8956
/**
9057
* The callback to populate a subclass of UICollectionViewCell with an object
91-
* provided by the
92-
* datasource.
93-
*/
94-
@property(strong, nonatomic, readonly) void (^populateCell)
95-
(__kindof UICollectionViewCell *cell, __kindof NSObject *object);
96-
97-
/**
98-
* Initialize an instance of FirebaseCollectionViewDataSource that populates
99-
* UICollectionViewCells
100-
* with FIRDataSnapshots.
101-
* @param ref A Firebase reference to bind the datasource to
102-
* @param identifier A string to use as a CellReuseIdentifier
103-
* @param collectionView An instance of a UICollectionView to bind to
104-
* @return An instance of FirebaseCollectionViewDataSource that populates
105-
* UICollectionViewCells with
106-
* FIRDataSnapshots
107-
*/
108-
- (instancetype)initWithRef:(FIRDatabaseReference *)ref
109-
cellReuseIdentifier:(NSString *)identifier
110-
view:(UICollectionView *)collectionView;
111-
112-
/**
113-
* Initialize an instance of FirebaseCollectionViewDataSource that populates
114-
* UICollectionViewCells
115-
* with FIRDataSnapshots. Note that this method is used when using prototype
116-
* cells, where the cells
117-
* don't need to be registered in the class.
118-
* @param ref A Firebase reference to bind the datasource to
119-
* @param identifier A string to use as a CellReuseIdentifier
120-
* @param collectionView An instance of a UICollectionView to bind to
121-
* @return An instance of FirebaseCollectionViewDataSource that populates
122-
* UICollectionViewCells with
123-
* FIRDataSnapshots
124-
*/
125-
- (instancetype)initWithRef:(FIRDatabaseReference *)ref
126-
prototypeReuseIdentifier:(NSString *)identifier
127-
view:(UICollectionView *)collectionView;
128-
129-
/**
130-
* Initialize an instance of FirebaseCollectionViewDataSource that populates a
131-
* custom subclass of
132-
* UICollectionViewCell with FIRDataSnapshots.
133-
* @param ref A Firebase reference to bind the datasource to
134-
* @param cell A subclass of UICollectionViewCell used to populate the
135-
* UICollectionView, defaults to
136-
* UICollectionViewCell if nil
137-
* @param identifier A string to use as a CellReuseIdentifier
138-
* @param collectionView An instance of a UICollectionView to bind to
139-
* @return An instance of FirebaseCollectionViewDataSource that populates a
140-
* custom subclass of
141-
* UICollectionViewCell with FIRDataSnapshots
142-
*/
143-
- (instancetype)initWithRef:(FIRDatabaseReference *)ref
144-
cellClass:(nullable Class)cell
145-
cellReuseIdentifier:(NSString *)identifier
146-
view:(UICollectionView *)collectionView;
147-
148-
/**
149-
* Initialize an instance of FirebaseCollectionViewDataSource that populates a
150-
* custom xib with
151-
* FIRDataSnapshots.
152-
* @param ref A Firebase reference to bind the datasource to
153-
* @param nibName The name of a xib file to create the layout for a
154-
* UICollectionViewCell
155-
* @param identifier A string to use as a CellReuseIdentifier
156-
* @param collectionView An instance of a UICollectionView to bind to
157-
* @return An instance of FirebaseCollectionViewDataSource that populates a
158-
* custom xib with
159-
* FIRDataSnapshots
160-
*/
161-
- (instancetype)initWithRef:(FIRDatabaseReference *)ref
162-
nibNamed:(NSString *)nibName
163-
cellReuseIdentifier:(NSString *)identifier
164-
view:(UICollectionView *)collectionView;
165-
166-
/**
167-
* Initialize an instance of FirebaseCollectionViewDataSource that populates
168-
* UICollectionViewCells
169-
* with a custom model class.
170-
* @param ref A Firebase reference to bind the datasource to
171-
* @param model A custom class that FIRDataSnapshots are coerced to, defaults to
172-
* FIRDataSnapshot if nil
173-
* @param identifier A string to use as a CellReuseIdentifier
174-
* @param collectionView An instance of a UICollectionView to bind to
175-
* @return An instance of FirebaseCollectionViewDataSource that populates
176-
* UICollectionViewCells with
177-
* a custom model class
178-
*/
179-
- (instancetype)initWithRef:(FIRDatabaseReference *)ref
180-
modelClass:(nullable Class)model
181-
cellReuseIdentifier:(NSString *)identifier
182-
view:(UICollectionView *)collectionView;
183-
184-
/**
185-
* Initialize an instance of FirebaseCollectionViewDataSource that populates
186-
* UICollectionViewCells
187-
* with a custom model class. Note that this method is used when using prototype
188-
* cells, where the
189-
* cells don't need to be registered in the class.
190-
* @param ref A Firebase reference to bind the datasource to
191-
* @param model A custom class that FIRDataSnapshots are coerced to, defaults to
192-
* FIRDataSnapshot if nil
193-
* @param identifier A string to use as a CellReuseIdentifier
194-
* @param collectionView An instance of a UICollectionView to bind to
195-
* @return An instance of FirebaseCollectionViewDataSource that populates
196-
* UICollectionViewCells with
197-
* a custom model class
198-
*/
199-
- (instancetype)initWithRef:(FIRDatabaseReference *)ref
200-
modelClass:(nullable Class)model
201-
prototypeReuseIdentifier:(NSString *)identifier
202-
view:(UICollectionView *)collectionView;
203-
204-
/**
205-
* Initialize an instance of FirebaseCollectionViewDataSource that populates a
206-
* custom subclass of
207-
* UICollectionViewCell with a custom model class.
208-
* @param ref A Firebase reference to bind the datasource to
209-
* @param model A custom class that FIRDataSnapshots are coerced to, defaults to
210-
* FIRDataSnapshot if nil
211-
* @param cell A subclass of UICollectionViewCell used to populate the
212-
* UICollectionView, defaults to
213-
* UICollectionViewCell if nil
214-
* @param identifier A string to use as a CellReuseIdentifier
215-
* @param collectionView An instance of a UICollectionView to bind to
216-
* @return An instance of FirebaseCollectionViewDataSource that populates a
217-
* custom subclass of
218-
* UICollectionViewCell with a custom model class
219-
*/
220-
- (instancetype)initWithRef:(FIRDatabaseReference *)ref
221-
modelClass:(nullable Class)model
222-
cellClass:(nullable Class)cell
223-
cellReuseIdentifier:(NSString *)identifier
224-
view:(UICollectionView *)collectionView;
225-
226-
/**
227-
* Initialize an instance of FirebaseCollectionViewDataSource that populates a
228-
* custom xib with a
229-
* custom model class.
230-
* @param ref A Firebase reference to bind the datasource to
231-
* @param model A custom class that FIRDataSnapshots are coerced to, defaults to
232-
* FIRDataSnapshot if nil
233-
* @param nibName The name of a xib file to create the layout for a
234-
* UICollectionViewCell
235-
* @param identifier A string to use as a CellReuseIdentifier
236-
* @param collectionView An instance of a UICollectionView to bind to
237-
* @return An instance of FirebaseCollectionViewDataSource that populates a
238-
* custom xib with a custom
239-
* model class
58+
* provided by the datasource.
24059
*/
241-
- (instancetype)initWithRef:(FIRDatabaseReference *)ref
242-
modelClass:(nullable Class)model
243-
nibNamed:(NSString *)nibName
244-
cellReuseIdentifier:(NSString *)identifier
245-
view:(UICollectionView *)collectionView;
60+
@property(strong, nonatomic, readonly) UICollectionViewCell *(^populateCellAtIndexPath)
61+
(NSIndexPath *indexPath, UICollectionView *collectionView, FIRDataSnapshot *object);
24662

24763
/**
24864
* Initialize an instance of FirebaseCollectionViewDataSource that populates
@@ -256,154 +72,10 @@ NS_ASSUME_NONNULL_BEGIN
25672
* FIRDataSnapshots
25773
*/
25874
- (instancetype)initWithQuery:(FIRDatabaseQuery *)query
259-
cellReuseIdentifier:(NSString *)identifier
260-
view:(UICollectionView *)collectionView;
261-
262-
/**
263-
* Initialize an instance of FirebaseCollectionViewDataSource that populates
264-
* UICollectionViewCells
265-
* with FIRDataSnapshots. Note that this method is used when using prototype
266-
* cells, where the cells
267-
* don't need to be registered in the class.
268-
* @param query A Firebase query to bind the datasource to
269-
* @param identifier A string to use as a CellReuseIdentifier
270-
* @param collectionView An instance of a UICollectionView to bind to
271-
* @return An instance of FirebaseCollectionViewDataSource that populates
272-
* UICollectionViewCells with
273-
* FIRDataSnapshots
274-
*/
275-
- (instancetype)initWithQuery:(FIRDatabaseQuery *)query
276-
prototypeReuseIdentifier:(NSString *)identifier
277-
view:(UICollectionView *)collectionView;
278-
279-
/**
280-
* Initialize an instance of FirebaseCollectionViewDataSource that populates a
281-
* custom subclass of
282-
* UICollectionViewCell with FIRDataSnapshots.
283-
* @param query A Firebase query to bind the datasource to
284-
* @param cell A subclass of UICollectionViewCell used to populate the
285-
* UICollectionView, defaults to
286-
* UICollectionViewCell if nil
287-
* @param identifier A string to use as a CellReuseIdentifier
288-
* @param collectionView An instance of a UICollectionView to bind to
289-
* @return An instance of FirebaseCollectionViewDataSource that populates a
290-
* custom subclass of
291-
* UICollectionViewCell with FIRDataSnapshots
292-
*/
293-
- (instancetype)initWithQuery:(FIRDatabaseQuery *)query
294-
cellClass:(nullable Class)cell
295-
cellReuseIdentifier:(NSString *)identifier
296-
view:(UICollectionView *)collectionView;
297-
298-
/**
299-
* Initialize an instance of FirebaseCollectionViewDataSource that populates a
300-
* custom xib with
301-
* FIRDataSnapshots.
302-
* @param query A Firebase query to bind the datasource to
303-
* @param nibName The name of a xib file to create the layout for a
304-
* UICollectionViewCell
305-
* @param identifier A string to use as a CellReuseIdentifier
306-
* @param collectionView An instance of a UICollectionView to bind to
307-
* @return An instance of FirebaseCollectionViewDataSource that populates a
308-
* custom xib with
309-
* FIRDataSnapshots
310-
*/
311-
- (instancetype)initWithQuery:(FIRDatabaseQuery *)query
312-
nibNamed:(NSString *)nibName
313-
cellReuseIdentifier:(NSString *)identifier
314-
view:(UICollectionView *)collectionView;
315-
316-
/**
317-
* Initialize an instance of FirebaseCollectionViewDataSource that populates
318-
* UICollectionViewCells
319-
* with a custom model class.
320-
* @param query A Firebase query to bind the datasource to
321-
* @param model A custom class that FIRDataSnapshots are coerced to, defaults to
322-
* FIRDataSnapshot if nil
323-
* @param identifier A string to use as a CellReuseIdentifier
324-
* @param collectionView An instance of a UICollectionView to bind to
325-
* @return An instance of FirebaseCollectionViewDataSource that populates
326-
* UICollectionViewCells with
327-
* a custom model class
328-
*/
329-
- (instancetype)initWithQuery:(FIRDatabaseQuery *)query
330-
modelClass:(nullable Class)model
331-
cellReuseIdentifier:(NSString *)identifier
332-
view:(UICollectionView *)collectionView;
333-
334-
/**
335-
* Initialize an instance of FirebaseCollectionViewDataSource that populates
336-
* UICollectionViewCells
337-
* with a custom model class. Note that this method is used when using prototype
338-
* cells, where the
339-
* cells don't need to be registered in the class.
340-
* @param query A Firebase query to bind the datasource to
341-
* @param model A custom class that FIRDataSnapshots are coerced to, defaults to
342-
* FIRDataSnapshot if nil
343-
* @param identifier A string to use as a CellReuseIdentifier
344-
* @param collectionView An instance of a UICollectionView to bind to
345-
* @return An instance of FirebaseCollectionViewDataSource that populates
346-
* UICollectionViewCells with
347-
* a custom model class
348-
*/
349-
- (instancetype)initWithQuery:(FIRDatabaseQuery *)query
350-
modelClass:(nullable Class)model
351-
prototypeReuseIdentifier:(NSString *)identifier
352-
view:(UICollectionView *)collectionView;
353-
354-
/**
355-
* Initialize an instance of FirebaseCollectionViewDataSource that populates a
356-
* custom subclass of
357-
* UICollectionViewCell with a custom model class.
358-
* @param query A Firebase query to bind the datasource to
359-
* @param model A custom class that FIRDataSnapshots are coerced to, defaults to
360-
* FIRDataSnapshot if nil
361-
* @param cell A subclass of UICollectionViewCell used to populate the
362-
* UICollectionView, defaults to
363-
* UICollectionViewCell if nil
364-
* @param identifier A string to use as a CellReuseIdentifier
365-
* @param collectionView An instance of a UICollectionView to bind to
366-
* @return An instance of FirebaseCollectionViewDataSource that populates a
367-
* custom subclass of
368-
* UICollectionViewCell with a custom model class
369-
*/
370-
- (instancetype)initWithQuery:(FIRDatabaseQuery *)query
371-
modelClass:(nullable Class)model
372-
cellClass:(nullable Class)cell
373-
cellReuseIdentifier:(NSString *)identifier
374-
view:(UICollectionView *)collectionView;
375-
376-
/**
377-
* Initialize an instance of FirebaseCollectionViewDataSource that populates a
378-
* custom xib with a
379-
* custom model class.
380-
* @param query A Firebase query to bind the datasource to
381-
* @param model A custom class that FIRDataSnapshots are coerced to, defaults to
382-
* FIRDataSnapshot if nil
383-
* @param nibName The name of a xib file to create the layout for a
384-
* UICollectionViewCell
385-
* @param identifier A string to use as a CellReuseIdentifier
386-
* @param collectionView An instance of a UICollectionView to bind to
387-
* @return An instance of FirebaseCollectionViewDataSource that populates a
388-
* custom xib with a custom
389-
* model class
390-
*/
391-
- (instancetype)initWithQuery:(FIRDatabaseQuery *)query
392-
modelClass:(nullable Class)model
393-
nibNamed:(NSString *)nibName
394-
cellReuseIdentifier:(NSString *)identifier
395-
view:(UICollectionView *)collectionView;
396-
397-
/**
398-
* This method populates the fields of a UICollectionViewCell or subclass given
399-
* an FIRDataSnapshot (or
400-
* custom model object).
401-
* @param callback A block which returns an initialized UICollectionViewCell (or
402-
* subclass) and the
403-
* corresponding object to populate the cell with.
404-
*/
405-
- (void)populateCellWithBlock:(void (^)(__kindof UICollectionViewCell *cell,
406-
__kindof NSObject *object))callback;
75+
view:(UICollectionView *)collectionView
76+
populateCell:(UICollectionViewCell * (^)(NSIndexPath *indexPath,
77+
UICollectionView *collectionView,
78+
FIRDataSnapshot *object))populateCell;
40779

40880
@end
40981

0 commit comments

Comments
 (0)