Skip to content

Commit

Permalink
apply code formatting (iOS)
Browse files Browse the repository at this point in the history
  • Loading branch information
koenpunt committed Sep 29, 2017
1 parent 4ad6850 commit 2425ef9
Show file tree
Hide file tree
Showing 6 changed files with 146 additions and 105 deletions.
16 changes: 16 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -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
147 changes: 77 additions & 70 deletions ios/RNAdMobInterstitial.m
Original file line number Diff line number Diff line change
Expand Up @@ -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<NSString *> *)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<NSString *,id> *)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
2 changes: 1 addition & 1 deletion ios/RNAdMobManager.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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; };
Expand Down
23 changes: 15 additions & 8 deletions ios/RNAdMobRewarded.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
static NSString *const kEventRewarded = @"rewarded";
static NSString *const kEventVideoStarted = @"videoStarted";

@implementation RNAdMobRewarded {
@implementation RNAdMobRewarded
{
NSString *_adUnitID;
NSArray *_testDevices;
RCTPromiseResolveBlock _requestAdResolve;
Expand Down Expand Up @@ -57,7 +58,7 @@ - (dispatch_queue_t)methodQueue
{
_requestAdResolve = resolve;
_requestAdReject = reject;

[GADRewardBasedVideoAd sharedInstance].delegate = self;
GADRequest *request = [GADRequest request];
request.testDevices = _testDevices;
Expand Down Expand Up @@ -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];
Expand Down
37 changes: 21 additions & 16 deletions ios/RNDFPBannerView.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@ - (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;
_bannerView.appEventDelegate = self;
_bannerView.rootViewController = rootViewController;
[self addSubview:_bannerView];
}

return self;
}

Expand Down Expand Up @@ -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(@{});
Expand All @@ -83,30 +84,34 @@ - (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] } });
}
}

/// 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(@{});
}
Expand Down
Loading

0 comments on commit 2425ef9

Please sign in to comment.