Skip to content

Commit

Permalink
Merge pull request facebook#5 from sghiassy/sghiassy.v0.28.0_SOA.REBE…
Browse files Browse the repository at this point in the history
…L-620

REBEL-620: Providing better alert information when developers are try…
  • Loading branch information
daniel-beard authored Jul 14, 2016
2 parents 325a0bd + 2cebd19 commit fb0f56c
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions React/Modules/RCTDevMenu.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
#import "RCTUtils.h"
#import "RCTWebSocketProxy.h"

static BOOL hasShownDisabledDebugAlert = NO;


#if RCT_DEV

static NSString *const RCTShowDevMenuNotification = @"RCTShowDevMenuNotification";
Expand Down Expand Up @@ -514,6 +517,23 @@ - (NSString *)devMenuSettingsKey {
return;
}

BOOL inBuildMode = _bundleURL.fileURL; // syntactic sugar

if (inBuildMode) {
if (!hasShownDisabledDebugAlert) {
/**
* Each service is going to try to show its own debug menu. But we only want
* one alert this instance, so we introduce the variable `hasShownDisabledDebugAlert`
*/
hasShownDisabledDebugAlert = YES;
[RCTDevMenu presentAlert:@"Debugging Disabled. See 'runMode' in Capacitorfile" onComplete:^{
hasShownDisabledDebugAlert = NO;
}];
}

return;
}

UIActionSheet *actionSheet = [UIActionSheet new];
actionSheet.title = [NSString stringWithFormat:@"RN Dev: %@:%@", _bundleURL.host, _bundleURL.port];
actionSheet.delegate = self;
Expand Down Expand Up @@ -688,6 +708,21 @@ - (void)checkForUpdates
[_updateTask resume];
}

#pragma mark - Helper Methods

+ (void)presentAlert:(NSString *)title onComplete:(void(^)(void))onComplete {
UIAlertController *alert = [[UIAlertController alloc] init];
alert.title = title;
UIAlertAction *ok = [UIAlertAction actionWithTitle:@"ok" style:0 handler:^(UIAlertAction * _Nonnull action) {
if (onComplete) {
onComplete();
}
}];
[alert addAction:ok];

[[[[UIApplication sharedApplication] keyWindow] rootViewController] presentViewController:alert animated:YES completion:nil]; // Present VC
}

@end

#else // Unavailable when not in dev mode
Expand Down

0 comments on commit fb0f56c

Please sign in to comment.