This repository has been archived by the owner on Jul 18, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 76
Add hide method to react-native-lock-ios #10
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,11 @@ | |
#import "A0Token+ReactNative.h" | ||
#import "A0UserProfile+ReactNative.h" | ||
|
||
|
||
@interface A0LockReact() | ||
@property (nonatomic, assign) BOOL shown; | ||
@end | ||
|
||
@implementation A0LockReact | ||
|
||
+ (instancetype)sharedInstance { | ||
|
@@ -44,6 +49,19 @@ - (void)configureLockWithClientId:(NSString *)clientId domain:(NSString *)domain | |
_lock = [A0Lock newLockWithClientId:clientId domain:domain]; | ||
} | ||
|
||
- (void)hideWithCallback:(A0LockCallback)callback { | ||
if (self.shown) { | ||
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(@[]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should call the callback inside the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @hzalaz good idea. Will move the callback. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"; | ||
|
@@ -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]]); | ||
}; | ||
|
||
|
@@ -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 { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.