Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,13 @@ - (void)reauthenticateWithPassword:(NSString *)password

[self.delegate incrementActivity];

if (self.delegate.auth.currentUser.email == nil) {
NSLog(@"FirebaseUI: Expected nonnull email during email/password reauthentication");
return;
}
[self.delegate.auth signInWithEmail:self.delegate.auth.currentUser.email
password:password
completion:^(FIRUser *_Nullable user, NSError *_Nullable error) {
completion:^(FIRAuthDataResult *authResult, NSError *error) {
[self.delegate decrementActivity];

[self finishOperationWithError:error];
Expand Down
9 changes: 7 additions & 2 deletions FirebaseAuthUI/FUIAuth.m
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,9 @@ - (void)handleAccountLinkingForEmail:(NSString *)email
return;
}

[self.auth signInWithCredential:credential completion:^(FIRUser *_Nullable user,
NSError *_Nullable error) {
[self.auth signInAndRetrieveDataWithCredential:credential
completion:^(FIRAuthDataResult*_Nullable authResult,
NSError *_Nullable error) {
if (error) {
[self invokeResultCallbackWithAuthDataResult:nil error:error];
if (result) {
Expand All @@ -314,6 +315,7 @@ - (void)handleAccountLinkingForEmail:(NSString *)email
return;
}

FIRUser *user = authResult.user;
[user linkAndRetrieveDataWithCredential:newCredential
completion:^(FIRAuthDataResult *_Nullable authResult,
NSError *_Nullable error) {
Expand All @@ -339,12 +341,15 @@ - (void)handleAccountLinkingForEmail:(NSString *)email
- (void)invokeResultCallbackWithAuthDataResult:(nullable FIRAuthDataResult *)authDataResult
error:(nullable NSError *)error {
dispatch_async(dispatch_get_main_queue(), ^{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
if ([self.delegate respondsToSelector:@selector(authUI:didSignInWithAuthDataResult:error:)]) {
[self.delegate authUI:self didSignInWithAuthDataResult:authDataResult error:error];
}
if ([self.delegate respondsToSelector:@selector(authUI:didSignInWithUser:error:)]) {
[self.delegate authUI:self didSignInWithUser:authDataResult.user error:error];
}
#pragma clang diagnostic pop
});
}

Expand Down
6 changes: 3 additions & 3 deletions FirebaseAuthUI/FUIAuthBaseViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -313,9 +313,9 @@ - (void)incrementActivity {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW,
(int64_t)(kActivityIndiactorAnimationDelay * NSEC_PER_SEC)),
dispatch_get_main_queue(), ^{
[_activityIndicator.superview bringSubviewToFront:_activityIndicator];
if (_activityCount > 0) {
[_activityIndicator startAnimating];
[self->_activityIndicator.superview bringSubviewToFront:_activityIndicator];
if (self->_activityCount > 0) {
[self->_activityIndicator startAnimating];
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion FirebaseAuthUI/FUIAuthProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
//

#import <UIKit/UIKit.h>
#import <FirebaseAuth/FIRAuth.h>
#import <FirebaseAuth/FirebaseAuth.h>

@class FIRAuth;
@class FIRAuthCredential;
Expand Down
2 changes: 1 addition & 1 deletion FirebaseAuthUI/FUIPasswordVerificationViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ - (void)verifyPassword:(NSString *)password {
return;
}

[authResult.user linkAndRetrieveDataWithCredential:_newCredential
[authResult.user linkAndRetrieveDataWithCredential:self->_newCredential
completion:^(FIRAuthDataResult *_Nullable authResult,
NSError *_Nullable error) {
[self decrementActivity];
Expand Down
1 change: 0 additions & 1 deletion FirebaseAuthUITests/FUIAuthTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
//

@import XCTest;
@import FirebaseAnalytics;
@import FirebaseAuth;
@import FirebaseAuthUI;
#import <OCMock/OCMock.h>
Expand Down
8 changes: 7 additions & 1 deletion FirebaseDatabaseUI/FUIIndexArray.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,15 @@ didFailLoadWithError:(NSError *)error;
*/
- (nullable FIRDataSnapshot *)objectAtIndex:(NSUInteger)index;

/**
* Starts observing the index array's listeners. The indexed array will pass updates to its delegate
* until the `invalidate` method is called.
*/
- (void)observeQuery;

/**
* Removes all observers from all queries managed by this array and renders this array
* unusable.
* unusable. Initialize a new array instead of reusing this array.
*/
- (void)invalidate;

Expand Down
5 changes: 4 additions & 1 deletion FirebaseDatabaseUI/FUIIndexArray.m
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ - (instancetype)initWithIndex:(id<FUIDataObservable>)index
_data = data;
_observers = [NSMutableArray array];
_delegate = delegate;
[self observeQueries];
}
return self;
}
Expand Down Expand Up @@ -93,6 +92,10 @@ - (NSUInteger)count {
return self.observers.count;
}

- (void)observeQuery {
[self observeQueries];
}

// FUIIndexArray instance becomes unusable after invalidation.
- (void)invalidate {
for (NSInteger i = 0; i < self.observers.count; i++) {
Expand Down
33 changes: 30 additions & 3 deletions FirebaseDatabaseUI/FUIIndexCollectionViewDataSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

NS_ASSUME_NONNULL_BEGIN

@class FUIIndexCollectionViewDataSource;
@class FUIIndexCollectionViewDataSource, FUIIndexArray;

@protocol FUIIndexCollectionViewDataSourceDelegate <NSObject>
@optional
Expand Down Expand Up @@ -70,6 +70,22 @@ didFailLoadAtIndex:(NSUInteger)index

- (instancetype)init NS_UNAVAILABLE;

/**
* Initializes a collection view data source.
* @param indexArray The FUIIndexArray whose contents will be displayed in the collection view.
* @param collectionView The collection view that is populated by this data source. The
* data source pulls updates from Firebase database, so it must maintain a reference
* to the collection view in order to update its contents as the database pushes updates.
* The collection view is not retained by its data source.
* @param populateCell The closure invoked when populating a UICollectionViewCell (or subclass).
*/
- (instancetype)initWithIndexArray:(FUIIndexArray *)indexArray
delegate:(nullable id<FUIIndexCollectionViewDataSourceDelegate>)delegate
populateCell:(UICollectionViewCell *(^)(UICollectionView *collectionView,
NSIndexPath *indexPath,
FIRDataSnapshot *_Nullable snap))populateCell
NS_DESIGNATED_INITIALIZER;

/**
* Initializes a collection view data source.
* @param indexQuery The Firebase query containing children of the data query.
Expand All @@ -84,11 +100,10 @@ didFailLoadAtIndex:(NSUInteger)index
*/
- (instancetype)initWithIndex:(FIRDatabaseQuery *)indexQuery
data:(FIRDatabaseReference *)dataQuery
collectionView:(UICollectionView *)collectionView
delegate:(nullable id<FUIIndexCollectionViewDataSourceDelegate>)delegate
populateCell:(UICollectionViewCell *(^)(UICollectionView *collectionView,
NSIndexPath *indexPath,
FIRDataSnapshot *_Nullable snap))populateCell NS_DESIGNATED_INITIALIZER;
FIRDataSnapshot *_Nullable snap))populateCell;

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

/**
* Attaches the data source to a collection view and begins sending updates immediately.
* @param view An instance of UICollectionView that the data source should push
* updates to.
*/
- (void)bindToView:(UICollectionView *)view;

/**
* Detaches the data source from a view and stops sending any updates.
*/
- (void)unbind;

@end

@interface UICollectionView (FUIIndexCollectionViewDataSource)
Expand Down
53 changes: 36 additions & 17 deletions FirebaseDatabaseUI/FUIIndexCollectionViewDataSource.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
@interface FUIIndexCollectionViewDataSource () <FUIIndexArrayDelegate>

@property (nonatomic, readonly, nonnull) FUIIndexArray *array;
@property (nonatomic, readonly, weak) UICollectionView *collectionView;
@property (nonatomic, weak, nullable) UICollectionView *collectionView;

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

- (instancetype)initWithIndex:(FIRDatabaseQuery *)indexQuery
data:(FIRDatabaseReference *)dataQuery
collectionView:(UICollectionView *)collectionView
delegate:(id<FUIIndexCollectionViewDataSourceDelegate>)delegate
populateCell:(UICollectionViewCell *(^)(UICollectionView *collectionView,
NSIndexPath *indexPath,
FIRDataSnapshot *snap))populateCell {
FUIIndexArray *array = [[FUIIndexArray alloc] initWithIndex:indexQuery
data:dataQuery
delegate:self];
return [self initWithIndexArray:array delegate:delegate populateCell:populateCell];
}

- (instancetype)initWithIndexArray:(FUIIndexArray *)indexArray
delegate:(id<FUIIndexCollectionViewDataSourceDelegate>)delegate
populateCell:(UICollectionViewCell *(^)(UICollectionView *collectionView,
NSIndexPath *indexPath,
FIRDataSnapshot *snap))populateCell {
self = [super init];
if (self != nil) {
_array = [[FUIIndexArray alloc] initWithIndex:indexQuery
data:dataQuery
delegate:self];
_collectionView = collectionView;
_array = indexArray;
_collectionView.dataSource = self;
_populateCell = populateCell;
_delegate = delegate;
Expand All @@ -58,6 +65,18 @@ - (FIRDataSnapshot *)snapshotAtIndex:(NSInteger)index {
return [self.array objectAtIndex:index];
}

- (void)bindToView:(UICollectionView *)view {
self.collectionView = view;
view.dataSource = self;
[self.array observeQuery];
}

- (void)unbind {
[self.array invalidate];
self.collectionView.dataSource = nil;
self.collectionView = nil;
}

#pragma mark - FUIIndexArrayDelegate

- (void)array:(FUIIndexArray *)array
Expand Down Expand Up @@ -115,7 +134,8 @@ - (void)array:(FUIIndexArray *)array

#pragma mark - UICollectionViewDataSource

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
- (NSInteger)collectionView:(UICollectionView *)collectionView
numberOfItemsInSection:(NSInteger)section {
return self.array.count;
}

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

- (FUIIndexCollectionViewDataSource *)bindToIndexedQuery:(FIRDatabaseQuery *)index
data:(FIRDatabaseReference *)data
delegate:(id<FUIIndexCollectionViewDataSourceDelegate>)delegate
populateCell:(UICollectionViewCell *(^)(UICollectionView *,
NSIndexPath *,
FIRDataSnapshot *))populateCell {
data:(FIRDatabaseReference *)data
delegate:(id<FUIIndexCollectionViewDataSourceDelegate>)delegate
populateCell:(UICollectionViewCell *(^)(UICollectionView *,
NSIndexPath *,
FIRDataSnapshot *))populateCell {
FUIIndexCollectionViewDataSource *dataSource =
[[FUIIndexCollectionViewDataSource alloc] initWithIndex:index
data:data
collectionView:self
delegate:delegate
populateCell:populateCell];
self.dataSource = dataSource;
data:data
delegate:delegate
populateCell:populateCell];
[dataSource bindToView:self];
return dataSource;
}

Expand Down
35 changes: 31 additions & 4 deletions FirebaseDatabaseUI/FUIIndexTableViewDataSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

NS_ASSUME_NONNULL_BEGIN

@class FUIIndexTableViewDataSource;
@class FUIIndexTableViewDataSource, FUIIndexArray;

@protocol FUIIndexTableViewDataSourceDelegate <NSObject>
@optional
Expand Down Expand Up @@ -74,7 +74,7 @@ didFailLoadAtIndex:(NSUInteger)index
* Initializes a table view data source.
* @param indexQuery The Firebase query containing children of the data query.
* @param dataQuery The reference whose children correspond to the contents of the
* index query. This reference's children's contents are served as teh contents
* index query. This reference's children's contents are served as the contents
* of the table view that adopts this data source.
* @param tableView The table view that is populated by this data source. The
* data source pulls updates from Firebase database, so it must maintain a reference
Expand All @@ -84,11 +84,26 @@ didFailLoadAtIndex:(NSUInteger)index
*/
- (instancetype)initWithIndex:(FIRDatabaseQuery *)indexQuery
data:(FIRDatabaseReference *)dataQuery
tableView:(UITableView *)tableView
delegate:(nullable id<FUIIndexTableViewDataSourceDelegate>)delegate
populateCell:(UITableViewCell *(^)(UITableView *tableView,
NSIndexPath *indexPath,
FIRDataSnapshot *_Nullable snap))populateCell NS_DESIGNATED_INITIALIZER;
FIRDataSnapshot *_Nullable snap))populateCell;

/**
* Initializes a table view data source.
* @param indexArray The FUIIndexArray whose contents will be displayed in the table view.
* @param tableView The table view that is populated by this data source. The
* data source pulls updates from Firebase database, so it must maintain a reference
* to the table view in order to update its contents as the database pushes updates.
* The table view is not retained by its data source.
* @param populateCell The closure invoked when populating a UITableViewCell (or subclass).
*/
- (instancetype)initWithIndexArray:(FUIIndexArray *)indexArray
delegate:(nullable id<FUIIndexTableViewDataSourceDelegate>)delegate
populateCell:(UITableViewCell *(^)(UITableView *tableView,
NSIndexPath *indexPath,
FIRDataSnapshot *_Nullable snap))populateCell
NS_DESIGNATED_INITIALIZER;

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

/**
* Attaches the data source to a table view and begins sending updates immediately.
* @param view An instance of UITableView that the data source should push
* updates to.
*/
- (void)bindToView:(UITableView *)view;

/**
* Detaches the data source from a view and stops sending any updates.
*/
- (void)unbind;

@end

@interface UITableView (FUIIndexTableViewDataSource)
Expand Down
Loading