diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 000000000..680fd53d5 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,16 @@ +# editorconfig.org +root = true + +[*] +indent_style = space +indent_size = 4 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.md] +trim_trailing_whitespace = false + +[*.js] +indent_size = 2 diff --git a/ios/RNAdMobInterstitial.m b/ios/RNAdMobInterstitial.m index 357979340..203851058 100644 --- a/ios/RNAdMobInterstitial.m +++ b/ios/RNAdMobInterstitial.m @@ -13,137 +13,144 @@ static NSString *const kEventAdClosed = @"adClosed"; static NSString *const kEventAdLeftApplication = @"adLeftApplication"; -@implementation RNAdMobInterstitial { - GADInterstitial *_interstitial; - NSString *_adUnitID; - NSArray *_testDevices; - RCTPromiseResolveBlock _requestAdResolve; - RCTPromiseRejectBlock _requestAdReject; - BOOL hasListeners; +@implementation RNAdMobInterstitial +{ + GADInterstitial *_interstitial; + NSString *_adUnitID; + NSArray *_testDevices; + RCTPromiseResolveBlock _requestAdResolve; + RCTPromiseRejectBlock _requestAdReject; + BOOL hasListeners; } - (dispatch_queue_t)methodQueue { - return dispatch_get_main_queue(); + return dispatch_get_main_queue(); } RCT_EXPORT_MODULE(); - (NSArray *)supportedEvents { - return @[ - kEventAdLoaded, - kEventAdFailedToLoad, - kEventAdOpened, - kEventAdFailedToOpen, - kEventAdClosed, - kEventAdLeftApplication ]; + return @[ + kEventAdLoaded, + kEventAdFailedToLoad, + kEventAdOpened, + kEventAdFailedToOpen, + kEventAdClosed, + kEventAdLeftApplication ]; } #pragma mark exported methods RCT_EXPORT_METHOD(setAdUnitID:(NSString *)adUnitID) { - _adUnitID = adUnitID; + _adUnitID = adUnitID; } RCT_EXPORT_METHOD(setTestDevices:(NSArray *)testDevices) { - _testDevices = testDevices; + _testDevices = testDevices; } RCT_EXPORT_METHOD(requestAd:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) { - _requestAdResolve = nil; - _requestAdReject = nil; + _requestAdResolve = nil; + _requestAdReject = nil; - if ([_interstitial hasBeenUsed] || _interstitial == nil) { - _requestAdResolve = resolve; - _requestAdReject = reject; + if ([_interstitial hasBeenUsed] || _interstitial == nil) { + _requestAdResolve = resolve; + _requestAdReject = reject; - _interstitial = [[GADInterstitial alloc] initWithAdUnitID:_adUnitID]; - _interstitial.delegate = self; + _interstitial = [[GADInterstitial alloc] initWithAdUnitID:_adUnitID]; + _interstitial.delegate = self; - GADRequest *request = [GADRequest request]; - request.testDevices = _testDevices; - [_interstitial loadRequest:request]; - } else { - reject(@"E_AD_ALREADY_LOADED", @"Ad is already loaded.", nil); - } + GADRequest *request = [GADRequest request]; + request.testDevices = _testDevices; + [_interstitial loadRequest:request]; + } else { + reject(@"E_AD_ALREADY_LOADED", @"Ad is already loaded.", nil); + } } RCT_EXPORT_METHOD(showAd:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) { - if ([_interstitial isReady]) { - [_interstitial presentFromRootViewController:[UIApplication sharedApplication].delegate.window.rootViewController]; - resolve(nil); - } - else { - reject(@"E_AD_NOT_READY", @"Ad is not ready.", nil); - } + if ([_interstitial isReady]) { + [_interstitial presentFromRootViewController:[UIApplication sharedApplication].delegate.window.rootViewController]; + resolve(nil); + } + else { + reject(@"E_AD_NOT_READY", @"Ad is not ready.", nil); + } } RCT_EXPORT_METHOD(isReady:(RCTResponseSenderBlock)callback) { - callback(@[[NSNumber numberWithBool:[_interstitial isReady]]]); + callback(@[[NSNumber numberWithBool:[_interstitial isReady]]]); } - (NSDictionary *)constantsToExport { - return @{ - @"simulatorId": kGADSimulatorID - }; + return @{ + @"simulatorId": kGADSimulatorID + }; } - (void)startObserving { - hasListeners = YES; + hasListeners = YES; } - (void)stopObserving { - hasListeners = NO; + hasListeners = NO; } #pragma mark GADInterstitialDelegate -- (void)interstitialDidReceiveAd:(__unused GADInterstitial *)ad { - if (hasListeners) { - [self sendEventWithName:kEventAdLoaded body:nil]; - } - _requestAdResolve(nil); +- (void)interstitialDidReceiveAd:(__unused GADInterstitial *)ad +{ + if (hasListeners) { + [self sendEventWithName:kEventAdLoaded body:nil]; + } + _requestAdResolve(nil); } -- (void)interstitial:(__unused GADInterstitial *)interstitial didFailToReceiveAdWithError:(GADRequestError *)error { - if (hasListeners) { - NSDictionary *jsError = RCTJSErrorFromCodeMessageAndNSError(@"E_AD_REQUEST_FAILED", error.localizedDescription, error); - [self sendEventWithName:kEventAdFailedToLoad body:jsError]; - } - _requestAdReject(@"E_AD_REQUEST_FAILED", error.localizedDescription, error); +- (void)interstitial:(__unused GADInterstitial *)interstitial didFailToReceiveAdWithError:(GADRequestError *)error +{ + if (hasListeners) { + NSDictionary *jsError = RCTJSErrorFromCodeMessageAndNSError(@"E_AD_REQUEST_FAILED", error.localizedDescription, error); + [self sendEventWithName:kEventAdFailedToLoad body:jsError]; + } + _requestAdReject(@"E_AD_REQUEST_FAILED", error.localizedDescription, error); } -- (void)interstitialWillPresentScreen:(__unused GADInterstitial *)ad { - if (hasListeners){ - [self sendEventWithName:kEventAdOpened body:nil]; - } +- (void)interstitialWillPresentScreen:(__unused GADInterstitial *)ad +{ + if (hasListeners){ + [self sendEventWithName:kEventAdOpened body:nil]; + } } -- (void)interstitialDidFailToPresentScreen:(__unused GADInterstitial *)ad { - if (hasListeners){ - [self sendEventWithName:kEventAdFailedToOpen body:nil]; - } +- (void)interstitialDidFailToPresentScreen:(__unused GADInterstitial *)ad +{ + if (hasListeners){ + [self sendEventWithName:kEventAdFailedToOpen body:nil]; + } } -- (void)interstitialWillDismissScreen:(__unused GADInterstitial *)ad { - if (hasListeners) { - [self sendEventWithName:kEventAdClosed body:nil]; - } +- (void)interstitialWillDismissScreen:(__unused GADInterstitial *)ad +{ + if (hasListeners) { + [self sendEventWithName:kEventAdClosed body:nil]; + } } -- (void)interstitialWillLeaveApplication:(__unused GADInterstitial *)ad { - if (hasListeners) { - [self sendEventWithName:kEventAdLeftApplication body:nil]; - } +- (void)interstitialWillLeaveApplication:(__unused GADInterstitial *)ad +{ + if (hasListeners) { + [self sendEventWithName:kEventAdLeftApplication body:nil]; + } } @end diff --git a/ios/RNAdMobManager.xcodeproj/project.pbxproj b/ios/RNAdMobManager.xcodeproj/project.pbxproj index 663a3c429..3a81209c1 100644 --- a/ios/RNAdMobManager.xcodeproj/project.pbxproj +++ b/ios/RNAdMobManager.xcodeproj/project.pbxproj @@ -38,7 +38,7 @@ A90F2F8A1D50AEF200F2A2E3 /* RNAdMobRewarded.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNAdMobRewarded.h; sourceTree = SOURCE_ROOT; }; A90F2F8B1D50AEF200F2A2E3 /* RNAdMobRewarded.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNAdMobRewarded.m; sourceTree = SOURCE_ROOT; }; A962C2511CB27DBD00E508A1 /* RNAdMobInterstitial.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNAdMobInterstitial.h; sourceTree = SOURCE_ROOT; }; - A962C2521CB27DBD00E508A1 /* RNAdMobInterstitial.m */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.c.objc; path = RNAdMobInterstitial.m; sourceTree = SOURCE_ROOT; }; + A962C2521CB27DBD00E508A1 /* RNAdMobInterstitial.m */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.objc; path = RNAdMobInterstitial.m; sourceTree = SOURCE_ROOT; }; A96DA7741C146D7200FC639B /* libRNAdMobManager.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libRNAdMobManager.a; sourceTree = BUILT_PRODUCTS_DIR; }; A96DA7801C146DA600FC639B /* RNGADBannerView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNGADBannerView.h; sourceTree = SOURCE_ROOT; }; A96DA7811C146DA600FC639B /* RNGADBannerView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNGADBannerView.m; sourceTree = SOURCE_ROOT; }; diff --git a/ios/RNAdMobRewarded.m b/ios/RNAdMobRewarded.m index 1a68cda9a..0d9f8a8a3 100644 --- a/ios/RNAdMobRewarded.m +++ b/ios/RNAdMobRewarded.m @@ -14,7 +14,8 @@ static NSString *const kEventRewarded = @"rewarded"; static NSString *const kEventVideoStarted = @"videoStarted"; -@implementation RNAdMobRewarded { +@implementation RNAdMobRewarded +{ NSString *_adUnitID; NSArray *_testDevices; RCTPromiseResolveBlock _requestAdResolve; @@ -57,7 +58,7 @@ - (dispatch_queue_t)methodQueue { _requestAdResolve = resolve; _requestAdReject = reject; - + [GADRewardBasedVideoAd sharedInstance].delegate = self; GADRequest *request = [GADRequest request]; request.testDevices = _testDevices; @@ -109,39 +110,45 @@ - (void)rewardBasedVideoAd:(__unused GADRewardBasedVideoAd *)rewardBasedVideoAd } } -- (void)rewardBasedVideoAdDidReceiveAd:(__unused GADRewardBasedVideoAd *)rewardBasedVideoAd { +- (void)rewardBasedVideoAdDidReceiveAd:(__unused GADRewardBasedVideoAd *)rewardBasedVideoAd +{ if (hasListeners) { [self sendEventWithName:kEventAdLoaded body:nil]; } _requestAdResolve(nil); } -- (void)rewardBasedVideoAdDidOpen:(__unused GADRewardBasedVideoAd *)rewardBasedVideoAd { +- (void)rewardBasedVideoAdDidOpen:(__unused GADRewardBasedVideoAd *)rewardBasedVideoAd +{ if (hasListeners) { [self sendEventWithName:kEventAdOpened body:nil]; } } -- (void)rewardBasedVideoAdDidStartPlaying:(__unused GADRewardBasedVideoAd *)rewardBasedVideoAd { +- (void)rewardBasedVideoAdDidStartPlaying:(__unused GADRewardBasedVideoAd *)rewardBasedVideoAd +{ if (hasListeners) { [self sendEventWithName:kEventVideoStarted body:nil]; } } -- (void)rewardBasedVideoAdDidClose:(__unused GADRewardBasedVideoAd *)rewardBasedVideoAd { +- (void)rewardBasedVideoAdDidClose:(__unused GADRewardBasedVideoAd *)rewardBasedVideoAd +{ if (hasListeners) { [self sendEventWithName:kEventAdClosed body:nil]; } } -- (void)rewardBasedVideoAdWillLeaveApplication:(__unused GADRewardBasedVideoAd *)rewardBasedVideoAd { +- (void)rewardBasedVideoAdWillLeaveApplication:(__unused GADRewardBasedVideoAd *)rewardBasedVideoAd +{ if (hasListeners) { [self sendEventWithName:kEventAdLeftApplication body:nil]; } } - (void)rewardBasedVideoAd:(__unused GADRewardBasedVideoAd *)rewardBasedVideoAd - didFailToLoadWithError:(NSError *)error { + didFailToLoadWithError:(NSError *)error +{ if (hasListeners) { NSDictionary *jsError = RCTJSErrorFromCodeMessageAndNSError(@"E_AD_FAILED_TO_LOAD", error.localizedDescription, error); [self sendEventWithName:kEventAdFailedToLoad body:jsError]; diff --git a/ios/RNDFPBannerView.m b/ios/RNDFPBannerView.m index 334ca6fc9..2454dd545 100644 --- a/ios/RNDFPBannerView.m +++ b/ios/RNDFPBannerView.m @@ -26,10 +26,10 @@ - (instancetype)initWithFrame:(CGRect)frame { if ((self = [super initWithFrame:frame])) { super.backgroundColor = [UIColor clearColor]; - + UIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow]; UIViewController *rootViewController = [keyWindow rootViewController]; - + _bannerView = [[DFPBannerView alloc] initWithAdSize:kGADAdSizeBanner]; _bannerView.delegate = self; _bannerView.adSizeDelegate = self; @@ -37,7 +37,7 @@ - (instancetype)initWithFrame:(CGRect)frame _bannerView.rootViewController = rootViewController; [self addSubview:_bannerView]; } - + return self; } @@ -70,11 +70,12 @@ -(void)layoutSubviews # pragma mark GADBannerViewDelegate /// Tells the delegate an ad request loaded an ad. -- (void)adViewDidReceiveAd:(DFPBannerView *)adView { +- (void)adViewDidReceiveAd:(DFPBannerView *)adView +{ if (self.onSizeChange) { - self.onSizeChange(@{ - @"width": @(adView.frame.size.width), - @"height": @(adView.frame.size.height) }); + self.onSizeChange(@{ + @"width": @(adView.frame.size.width), + @"height": @(adView.frame.size.height) }); } if (self.onAdLoaded) { self.onAdLoaded(@{}); @@ -83,7 +84,8 @@ - (void)adViewDidReceiveAd:(DFPBannerView *)adView { /// Tells the delegate an ad request failed. - (void)adView:(DFPBannerView *)adView -didFailToReceiveAdWithError:(GADRequestError *)error { +didFailToReceiveAdWithError:(GADRequestError *)error +{ if (self.onAdFailedToLoad) { self.onAdFailedToLoad(@{ @"error": @{ @"message": [error localizedDescription] } }); } @@ -91,22 +93,25 @@ - (void)adView:(DFPBannerView *)adView /// Tells the delegate that a full screen view will be presented in response /// to the user clicking on an ad. -- (void)adViewWillPresentScreen:(DFPBannerView *)adView { +- (void)adViewWillPresentScreen:(DFPBannerView *)adView +{ if (self.onAdOpened) { self.onAdOpened(@{}); } } - /// Tells the delegate that the full screen view will be dismissed. - - (void)adViewWillDismissScreen:(__unused DFPBannerView *)adView { - if (self.onAdClosed) { - self.onAdClosed(@{}); - } - } +/// Tells the delegate that the full screen view will be dismissed. +- (void)adViewWillDismissScreen:(__unused DFPBannerView *)adView +{ + if (self.onAdClosed) { + self.onAdClosed(@{}); + } +} /// Tells the delegate that a user click will open another app (such as /// the App Store), backgrounding the current app. -- (void)adViewWillLeaveApplication:(DFPBannerView *)adView { +- (void)adViewWillLeaveApplication:(DFPBannerView *)adView +{ if (self.onAdLeftApplication) { self.onAdLeftApplication(@{}); } diff --git a/ios/RNGADBannerView.m b/ios/RNGADBannerView.m index 690b5a7b5..e0a780bb3 100644 --- a/ios/RNGADBannerView.m +++ b/ios/RNGADBannerView.m @@ -34,7 +34,8 @@ - (instancetype)initWithFrame:(CGRect)frame return self; } -- (void)loadBanner { +- (void)loadBanner +{ if(self.onSizeChange) { CGSize size = CGSizeFromGADAdSize(_bannerView.adSize); if(!CGSizeEqualToSize(size, self.bounds.size)) { @@ -58,7 +59,8 @@ -(void)layoutSubviews # pragma mark GADBannerViewDelegate /// Tells the delegate an ad request loaded an ad. -- (void)adViewDidReceiveAd:(__unused GADBannerView *)adView { +- (void)adViewDidReceiveAd:(__unused GADBannerView *)adView +{ if (self.onAdLoaded) { self.onAdLoaded(@{}); } @@ -66,7 +68,8 @@ - (void)adViewDidReceiveAd:(__unused GADBannerView *)adView { /// Tells the delegate an ad request failed. - (void)adView:(__unused GADBannerView *)adView -didFailToReceiveAdWithError:(GADRequestError *)error { +didFailToReceiveAdWithError:(GADRequestError *)error +{ if (self.onAdFailedToLoad) { self.onAdFailedToLoad(@{ @"error": @{ @"message": [error localizedDescription] } }); } @@ -74,22 +77,25 @@ - (void)adView:(__unused GADBannerView *)adView /// Tells the delegate that a full screen view will be presented in response /// to the user clicking on an ad. -- (void)adViewWillPresentScreen:(__unused GADBannerView *)adView { +- (void)adViewWillPresentScreen:(__unused GADBannerView *)adView +{ if (self.onAdOpened) { self.onAdOpened(@{}); } } - /// Tells the delegate that the full screen view will be dismissed. - - (void)adViewWillDismissScreen:(__unused GADBannerView *)adView { - if (self.onAdClosed) { - self.onAdClosed(@{}); - } +/// Tells the delegate that the full screen view will be dismissed. +- (void)adViewWillDismissScreen:(__unused GADBannerView *)adView +{ + if (self.onAdClosed) { + self.onAdClosed(@{}); + } } /// Tells the delegate that a user click will open another app (such as /// the App Store), backgrounding the current app. -- (void)adViewWillLeaveApplication:(__unused GADBannerView *)adView { +- (void)adViewWillLeaveApplication:(__unused GADBannerView *)adView +{ if (self.onAdLeftApplication) { self.onAdLeftApplication(@{}); }