Skip to content

Commit c71e037

Browse files
authored
Merge pull request #443 from firebase/firebase-5
Firebase 5
2 parents 4229048 + 6b2b5b5 commit c71e037

34 files changed

+410
-134
lines changed

FirebaseAuthUI/AccountManagement/FUIAccountSettingsOperation.m

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,13 @@ - (void)reauthenticateWithPassword:(NSString *)password
205205

206206
[self.delegate incrementActivity];
207207

208+
if (self.delegate.auth.currentUser.email == nil) {
209+
NSLog(@"FirebaseUI: Expected nonnull email during email/password reauthentication");
210+
return;
211+
}
208212
[self.delegate.auth signInWithEmail:self.delegate.auth.currentUser.email
209213
password:password
210-
completion:^(FIRUser *_Nullable user, NSError *_Nullable error) {
214+
completion:^(FIRAuthDataResult *authResult, NSError *error) {
211215
[self.delegate decrementActivity];
212216

213217
[self finishOperationWithError:error];

FirebaseAuthUI/FUIAuth.m

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,9 @@ - (void)handleAccountLinkingForEmail:(NSString *)email
304304
return;
305305
}
306306

307-
[self.auth signInWithCredential:credential completion:^(FIRUser *_Nullable user,
308-
NSError *_Nullable error) {
307+
[self.auth signInAndRetrieveDataWithCredential:credential
308+
completion:^(FIRAuthDataResult*_Nullable authResult,
309+
NSError *_Nullable error) {
309310
if (error) {
310311
[self invokeResultCallbackWithAuthDataResult:nil error:error];
311312
if (result) {
@@ -314,6 +315,7 @@ - (void)handleAccountLinkingForEmail:(NSString *)email
314315
return;
315316
}
316317

318+
FIRUser *user = authResult.user;
317319
[user linkAndRetrieveDataWithCredential:newCredential
318320
completion:^(FIRAuthDataResult *_Nullable authResult,
319321
NSError *_Nullable error) {
@@ -339,12 +341,15 @@ - (void)handleAccountLinkingForEmail:(NSString *)email
339341
- (void)invokeResultCallbackWithAuthDataResult:(nullable FIRAuthDataResult *)authDataResult
340342
error:(nullable NSError *)error {
341343
dispatch_async(dispatch_get_main_queue(), ^{
344+
#pragma clang diagnostic push
345+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
342346
if ([self.delegate respondsToSelector:@selector(authUI:didSignInWithAuthDataResult:error:)]) {
343347
[self.delegate authUI:self didSignInWithAuthDataResult:authDataResult error:error];
344348
}
345349
if ([self.delegate respondsToSelector:@selector(authUI:didSignInWithUser:error:)]) {
346350
[self.delegate authUI:self didSignInWithUser:authDataResult.user error:error];
347351
}
352+
#pragma clang diagnostic pop
348353
});
349354
}
350355

FirebaseAuthUI/FUIAuthBaseViewController.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -313,9 +313,9 @@ - (void)incrementActivity {
313313
dispatch_after(dispatch_time(DISPATCH_TIME_NOW,
314314
(int64_t)(kActivityIndiactorAnimationDelay * NSEC_PER_SEC)),
315315
dispatch_get_main_queue(), ^{
316-
[_activityIndicator.superview bringSubviewToFront:_activityIndicator];
317-
if (_activityCount > 0) {
318-
[_activityIndicator startAnimating];
316+
[self->_activityIndicator.superview bringSubviewToFront:_activityIndicator];
317+
if (self->_activityCount > 0) {
318+
[self->_activityIndicator startAnimating];
319319
}
320320
});
321321
}

FirebaseAuthUI/FUIAuthProvider.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
//
1616

1717
#import <UIKit/UIKit.h>
18-
#import <FirebaseAuth/FIRAuth.h>
18+
#import <FirebaseAuth/FirebaseAuth.h>
1919

2020
@class FIRAuth;
2121
@class FIRAuthCredential;

FirebaseAuthUI/FUIPasswordVerificationViewController.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ - (void)verifyPassword:(NSString *)password {
152152
return;
153153
}
154154

155-
[authResult.user linkAndRetrieveDataWithCredential:_newCredential
155+
[authResult.user linkAndRetrieveDataWithCredential:self->_newCredential
156156
completion:^(FIRAuthDataResult *_Nullable authResult,
157157
NSError *_Nullable error) {
158158
[self decrementActivity];

FirebaseAuthUITests/FUIAuthTest.m

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
//
1616

1717
@import XCTest;
18-
@import FirebaseAnalytics;
1918
@import FirebaseAuth;
2019
@import FirebaseAuthUI;
2120
#import <OCMock/OCMock.h>

FirebaseDatabaseUI/FUIIndexArray.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,15 @@ didFailLoadWithError:(NSError *)error;
170170
*/
171171
- (nullable FIRDataSnapshot *)objectAtIndex:(NSUInteger)index;
172172

173+
/**
174+
* Starts observing the index array's listeners. The indexed array will pass updates to its delegate
175+
* until the `invalidate` method is called.
176+
*/
177+
- (void)observeQuery;
178+
173179
/**
174180
* Removes all observers from all queries managed by this array and renders this array
175-
* unusable.
181+
* unusable. Initialize a new array instead of reusing this array.
176182
*/
177183
- (void)invalidate;
178184

FirebaseDatabaseUI/FUIIndexArray.m

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ - (instancetype)initWithIndex:(id<FUIDataObservable>)index
5959
_data = data;
6060
_observers = [NSMutableArray array];
6161
_delegate = delegate;
62-
[self observeQueries];
6362
}
6463
return self;
6564
}
@@ -93,6 +92,10 @@ - (NSUInteger)count {
9392
return self.observers.count;
9493
}
9594

95+
- (void)observeQuery {
96+
[self observeQueries];
97+
}
98+
9699
// FUIIndexArray instance becomes unusable after invalidation.
97100
- (void)invalidate {
98101
for (NSInteger i = 0; i < self.observers.count; i++) {

FirebaseDatabaseUI/FUIIndexCollectionViewDataSource.h

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
NS_ASSUME_NONNULL_BEGIN
2121

22-
@class FUIIndexCollectionViewDataSource;
22+
@class FUIIndexCollectionViewDataSource, FUIIndexArray;
2323

2424
@protocol FUIIndexCollectionViewDataSourceDelegate <NSObject>
2525
@optional
@@ -70,6 +70,22 @@ didFailLoadAtIndex:(NSUInteger)index
7070

7171
- (instancetype)init NS_UNAVAILABLE;
7272

73+
/**
74+
* Initializes a collection view data source.
75+
* @param indexArray The FUIIndexArray whose contents will be displayed in the collection view.
76+
* @param collectionView The collection view that is populated by this data source. The
77+
* data source pulls updates from Firebase database, so it must maintain a reference
78+
* to the collection view in order to update its contents as the database pushes updates.
79+
* The collection view is not retained by its data source.
80+
* @param populateCell The closure invoked when populating a UICollectionViewCell (or subclass).
81+
*/
82+
- (instancetype)initWithIndexArray:(FUIIndexArray *)indexArray
83+
delegate:(nullable id<FUIIndexCollectionViewDataSourceDelegate>)delegate
84+
populateCell:(UICollectionViewCell *(^)(UICollectionView *collectionView,
85+
NSIndexPath *indexPath,
86+
FIRDataSnapshot *_Nullable snap))populateCell
87+
NS_DESIGNATED_INITIALIZER;
88+
7389
/**
7490
* Initializes a collection view data source.
7591
* @param indexQuery The Firebase query containing children of the data query.
@@ -84,11 +100,10 @@ didFailLoadAtIndex:(NSUInteger)index
84100
*/
85101
- (instancetype)initWithIndex:(FIRDatabaseQuery *)indexQuery
86102
data:(FIRDatabaseReference *)dataQuery
87-
collectionView:(UICollectionView *)collectionView
88103
delegate:(nullable id<FUIIndexCollectionViewDataSourceDelegate>)delegate
89104
populateCell:(UICollectionViewCell *(^)(UICollectionView *collectionView,
90105
NSIndexPath *indexPath,
91-
FIRDataSnapshot *_Nullable snap))populateCell NS_DESIGNATED_INITIALIZER;
106+
FIRDataSnapshot *_Nullable snap))populateCell;
92107

93108
/**
94109
* Returns the snapshot at the given index, if it has loaded.
@@ -98,6 +113,18 @@ didFailLoadAtIndex:(NSUInteger)index
98113
*/
99114
- (nullable FIRDataSnapshot *)snapshotAtIndex:(NSInteger)index;
100115

116+
/**
117+
* Attaches the data source to a collection view and begins sending updates immediately.
118+
* @param view An instance of UICollectionView that the data source should push
119+
* updates to.
120+
*/
121+
- (void)bindToView:(UICollectionView *)view;
122+
123+
/**
124+
* Detaches the data source from a view and stops sending any updates.
125+
*/
126+
- (void)unbind;
127+
101128
@end
102129

103130
@interface UICollectionView (FUIIndexCollectionViewDataSource)

FirebaseDatabaseUI/FUIIndexCollectionViewDataSource.m

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
@interface FUIIndexCollectionViewDataSource () <FUIIndexArrayDelegate>
2222

2323
@property (nonatomic, readonly, nonnull) FUIIndexArray *array;
24-
@property (nonatomic, readonly, weak) UICollectionView *collectionView;
24+
@property (nonatomic, weak, nullable) UICollectionView *collectionView;
2525

2626
@property (nonatomic, readonly, copy) UICollectionViewCell *(^populateCell)
2727
(UICollectionView *collectionView, NSIndexPath *indexPath, FIRDataSnapshot *object);
@@ -32,17 +32,24 @@ @implementation FUIIndexCollectionViewDataSource
3232

3333
- (instancetype)initWithIndex:(FIRDatabaseQuery *)indexQuery
3434
data:(FIRDatabaseReference *)dataQuery
35-
collectionView:(UICollectionView *)collectionView
35+
delegate:(id<FUIIndexCollectionViewDataSourceDelegate>)delegate
36+
populateCell:(UICollectionViewCell *(^)(UICollectionView *collectionView,
37+
NSIndexPath *indexPath,
38+
FIRDataSnapshot *snap))populateCell {
39+
FUIIndexArray *array = [[FUIIndexArray alloc] initWithIndex:indexQuery
40+
data:dataQuery
41+
delegate:self];
42+
return [self initWithIndexArray:array delegate:delegate populateCell:populateCell];
43+
}
44+
45+
- (instancetype)initWithIndexArray:(FUIIndexArray *)indexArray
3646
delegate:(id<FUIIndexCollectionViewDataSourceDelegate>)delegate
3747
populateCell:(UICollectionViewCell *(^)(UICollectionView *collectionView,
3848
NSIndexPath *indexPath,
3949
FIRDataSnapshot *snap))populateCell {
4050
self = [super init];
4151
if (self != nil) {
42-
_array = [[FUIIndexArray alloc] initWithIndex:indexQuery
43-
data:dataQuery
44-
delegate:self];
45-
_collectionView = collectionView;
52+
_array = indexArray;
4653
_collectionView.dataSource = self;
4754
_populateCell = populateCell;
4855
_delegate = delegate;
@@ -58,6 +65,18 @@ - (FIRDataSnapshot *)snapshotAtIndex:(NSInteger)index {
5865
return [self.array objectAtIndex:index];
5966
}
6067

68+
- (void)bindToView:(UICollectionView *)view {
69+
self.collectionView = view;
70+
view.dataSource = self;
71+
[self.array observeQuery];
72+
}
73+
74+
- (void)unbind {
75+
[self.array invalidate];
76+
self.collectionView.dataSource = nil;
77+
self.collectionView = nil;
78+
}
79+
6180
#pragma mark - FUIIndexArrayDelegate
6281

6382
- (void)array:(FUIIndexArray *)array
@@ -115,7 +134,8 @@ - (void)array:(FUIIndexArray *)array
115134

116135
#pragma mark - UICollectionViewDataSource
117136

118-
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
137+
- (NSInteger)collectionView:(UICollectionView *)collectionView
138+
numberOfItemsInSection:(NSInteger)section {
119139
return self.array.count;
120140
}
121141

@@ -131,18 +151,17 @@ - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView
131151
@implementation UICollectionView (FUIIndexCollectionViewDataSource)
132152

133153
- (FUIIndexCollectionViewDataSource *)bindToIndexedQuery:(FIRDatabaseQuery *)index
134-
data:(FIRDatabaseReference *)data
135-
delegate:(id<FUIIndexCollectionViewDataSourceDelegate>)delegate
136-
populateCell:(UICollectionViewCell *(^)(UICollectionView *,
137-
NSIndexPath *,
138-
FIRDataSnapshot *))populateCell {
154+
data:(FIRDatabaseReference *)data
155+
delegate:(id<FUIIndexCollectionViewDataSourceDelegate>)delegate
156+
populateCell:(UICollectionViewCell *(^)(UICollectionView *,
157+
NSIndexPath *,
158+
FIRDataSnapshot *))populateCell {
139159
FUIIndexCollectionViewDataSource *dataSource =
140160
[[FUIIndexCollectionViewDataSource alloc] initWithIndex:index
141-
data:data
142-
collectionView:self
143-
delegate:delegate
144-
populateCell:populateCell];
145-
self.dataSource = dataSource;
161+
data:data
162+
delegate:delegate
163+
populateCell:populateCell];
164+
[dataSource bindToView:self];
146165
return dataSource;
147166
}
148167

FirebaseDatabaseUI/FUIIndexTableViewDataSource.h

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
NS_ASSUME_NONNULL_BEGIN
2121

22-
@class FUIIndexTableViewDataSource;
22+
@class FUIIndexTableViewDataSource, FUIIndexArray;
2323

2424
@protocol FUIIndexTableViewDataSourceDelegate <NSObject>
2525
@optional
@@ -74,7 +74,7 @@ didFailLoadAtIndex:(NSUInteger)index
7474
* Initializes a table view data source.
7575
* @param indexQuery The Firebase query containing children of the data query.
7676
* @param dataQuery The reference whose children correspond to the contents of the
77-
* index query. This reference's children's contents are served as teh contents
77+
* index query. This reference's children's contents are served as the contents
7878
* of the table view that adopts this data source.
7979
* @param tableView The table view that is populated by this data source. The
8080
* data source pulls updates from Firebase database, so it must maintain a reference
@@ -84,11 +84,26 @@ didFailLoadAtIndex:(NSUInteger)index
8484
*/
8585
- (instancetype)initWithIndex:(FIRDatabaseQuery *)indexQuery
8686
data:(FIRDatabaseReference *)dataQuery
87-
tableView:(UITableView *)tableView
8887
delegate:(nullable id<FUIIndexTableViewDataSourceDelegate>)delegate
8988
populateCell:(UITableViewCell *(^)(UITableView *tableView,
9089
NSIndexPath *indexPath,
91-
FIRDataSnapshot *_Nullable snap))populateCell NS_DESIGNATED_INITIALIZER;
90+
FIRDataSnapshot *_Nullable snap))populateCell;
91+
92+
/**
93+
* Initializes a table view data source.
94+
* @param indexArray The FUIIndexArray whose contents will be displayed in the table view.
95+
* @param tableView The table view that is populated by this data source. The
96+
* data source pulls updates from Firebase database, so it must maintain a reference
97+
* to the table view in order to update its contents as the database pushes updates.
98+
* The table view is not retained by its data source.
99+
* @param populateCell The closure invoked when populating a UITableViewCell (or subclass).
100+
*/
101+
- (instancetype)initWithIndexArray:(FUIIndexArray *)indexArray
102+
delegate:(nullable id<FUIIndexTableViewDataSourceDelegate>)delegate
103+
populateCell:(UITableViewCell *(^)(UITableView *tableView,
104+
NSIndexPath *indexPath,
105+
FIRDataSnapshot *_Nullable snap))populateCell
106+
NS_DESIGNATED_INITIALIZER;
92107

93108
/**
94109
* Returns the snapshot at the given index, if it has loaded.
@@ -98,6 +113,18 @@ didFailLoadAtIndex:(NSUInteger)index
98113
*/
99114
- (nullable FIRDataSnapshot *)snapshotAtIndex:(NSInteger)index;
100115

116+
/**
117+
* Attaches the data source to a table view and begins sending updates immediately.
118+
* @param view An instance of UITableView that the data source should push
119+
* updates to.
120+
*/
121+
- (void)bindToView:(UITableView *)view;
122+
123+
/**
124+
* Detaches the data source from a view and stops sending any updates.
125+
*/
126+
- (void)unbind;
127+
101128
@end
102129

103130
@interface UITableView (FUIIndexTableViewDataSource)

0 commit comments

Comments
 (0)