Skip to content

Instantly share code, notes, and snippets.

@andrepimenta
Last active July 25, 2019 16:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrepimenta/a3df03d766c709863e7bea7fb21413c1 to your computer and use it in GitHub Desktop.
Save andrepimenta/a3df03d766c709863e7bea7fb21413c1 to your computer and use it in GitHub Desktop.
Tutorial file for React Native iOS bridge
//
// LoadingOverlay.m
// ReactNativeLoadingSpinnerOverlayNative
//
// Created by Andre Pimenta on 11/07/2019.
// Copyright © 2019 Facebook. All rights reserved.
//
#import "React/RCTLog.h"
#import "LoadingOverlay.h"
#import "JGProgressHUD.h"
#import <UIKit/UIKit.h>
@implementation LoadingOverlay
// This RCT (React) "macro" exposes the current module to JavaScript
RCT_EXPORT_MODULE();
JGProgressHUD *HUD;
RCT_EXPORT_METHOD(toggle:(BOOL *)show
resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject)
{
dispatch_async(dispatch_get_main_queue(), ^{
@try{
if(!HUD)
HUD = [JGProgressHUD progressHUDWithStyle:JGProgressHUDStyleDark];
if(show){
UIWindow *window = [[UIApplication sharedApplication] keyWindow];
UIView *topView = window.rootViewController.view;
HUD.textLabel.text = @"Loading";
[HUD showInView:topView];
}else{
[HUD dismiss];
}
resolve(@{ @"key": [NSNumber numberWithBool:1] });
}
@catch(NSException *exception){
reject(@"get_error",exception.reason, nil);
}
});
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment