Skip to content
This repository has been archived by the owner on Jul 18, 2020. It is now read-only.

Add hide method to react-native-lock-ios #10

Merged
merged 2 commits into from Jan 26, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 4 additions & 0 deletions auth0-lock.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ class Auth0Lock {
}
}

hide(callback) {
LockModule.hide(callback);
}

show(options, callback) {
LockModule.init(this.lockOptions);
if (this.nativeIntegrations) {
Expand Down
6 changes: 6 additions & 0 deletions objc/A0LockReactModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ @implementation A0LockReactModule
[lock registerAuthenticators:authenticators];
}

RCT_EXPORT_METHOD(hide:(RCTResponseSenderBlock)callback) {
dispatch_async(dispatch_get_main_queue(), ^{
[[A0LockReact sharedInstance] hideWithCallback:callback];
});
}

RCT_EXPORT_METHOD(show:(NSDictionary *)options callback:(RCTResponseSenderBlock)callback) {
dispatch_async(dispatch_get_main_queue(), ^{
[[A0LockReact sharedInstance] showWithOptions:options callback:callback];
Expand Down
2 changes: 2 additions & 0 deletions objc/core/A0LockReact.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ typedef void(^A0LockCallback)(NSArray *parameters);

@property (strong, readonly, nonatomic) A0Lock *lock;

- (void)hideWithCallback:(A0LockCallback)callback;

- (void)showWithOptions:(NSDictionary *)options callback:(A0LockCallback)callback;

- (void)configureLockFromBundle;
Expand Down
20 changes: 20 additions & 0 deletions objc/core/A0LockReact.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
#import "A0Token+ReactNative.h"
#import "A0UserProfile+ReactNative.h"


@interface A0LockReact()
@property (nonatomic, assign) BOOL shown;
@end

@implementation A0LockReact

+ (instancetype)sharedInstance {
Expand All @@ -44,6 +49,19 @@ - (void)configureLockWithClientId:(NSString *)clientId domain:(NSString *)domain
_lock = [A0Lock newLockWithClientId:clientId domain:domain];
}

- (void)hideWithCallback:(A0LockCallback)callback {
if (self.shown) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not convinced we should add this flag, the worst case scenario is that you'll dismiss a VC that is presented from the rootViewController of the window if Lock is not displayed (which should be strange). So I'd rather remove this flag and just dismiss the presented VC.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hzalaz that scenario was what I was trying to avoid. Wanted the call to be safe to attach to some state change event which may not be dependent upon the lock being shown.

e.g. we have a listener on a firebase variable that detects when an app version value has changed. If the version requires an updated we ensure the login screen is hidden by calling lock.hide() without having to keep track of whether or not it's shown.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, I still don't like it and probably is something the app might take care of (trying not to dismiss something is not there) but besides my opinion there is no other argument against it. So let's keep it as it is, just check the other comment and I'll merge it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! FWIW one other issue this has allowed us to work around.

During development of a react-native app, if the lock is open and you hit 'command r' to refresh the app, the lock will persist open (since it lives in the native layer) even though the js app state has been blown away and restarted. We're able to work around this now by calling lock.hide() on init of app to ensure the lock is closed.

if (!self.lock) {
callback(@[@"Please configure Lock before using it"]);
return;
}
UIViewController *controller = [[[[UIApplication sharedApplication] windows] firstObject] rootViewController];
[controller dismissViewControllerAnimated:YES completion:nil];
self.shown = NO;
}
callback(@[]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should call the callback inside the completion block of dismissViewControllerAnimated:completion:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hzalaz good idea. Will move the callback.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

callback moved in commit a9f8236

}

- (void)showWithOptions:(NSDictionary *)options callback:(A0LockCallback)callback {
static NSString *TouchID = @"touchid";
static NSString *SMS = @"sms";
Expand Down Expand Up @@ -78,6 +96,7 @@ - (void)showWithOptions:(NSDictionary *)options callback:(A0LockCallback)callbac
[controller dismissViewControllerAnimated:YES completion:nil];
};
void(^dismissBlock)() = ^{
self.shown = NO;
callback(@[@"Lock was dismissed by the user", [NSNull null], [NSNull null]]);
};

Expand Down Expand Up @@ -115,6 +134,7 @@ - (void)showWithOptions:(NSDictionary *)options callback:(A0LockCallback)callbac
lock.onUserDismissBlock = dismissBlock;
[self.lock presentLockController:lock fromController:controller];
}
self.shown = YES;
}

- (A0AuthParameters *)authenticationParametersFromOptions:(NSDictionary *)options {
Expand Down