Skip to content

Commit

Permalink
Use RCTBubblingEventBlocks in RNAdMobInterstitial & RNAdMobRewarded a…
Browse files Browse the repository at this point in the history
…s well.
  • Loading branch information
joeaverage1234 committed Mar 14, 2017
1 parent 6974b11 commit 3bec144
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 28 deletions.
4 changes: 1 addition & 3 deletions ios/BannerView.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
#if __has_include(<React/RCTEventDispatcher.h>)
#if __has_include(<React/RCTComponent.h>)
#import <React/RCTComponent.h>
#else
#import "RCTComponent.h"
#endif

@import GoogleMobileAds;

@class RCTEventDispatcher;

@interface BannerView : UIView <GADBannerViewDelegate>

@property (nonatomic, copy) NSString *bannerSize;
Expand Down
13 changes: 10 additions & 3 deletions ios/RNAdMobInterstitial.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
#if __has_include(<React/RCTBridgeModule.h>)
#if __has_include(<React/RCTComponent.h>)
#import <React/RCTComponent.h>
#import <React/RCTBridgeModule.h>
#import <React/RCTEventDispatcher.h>
#else
#import "RCTComponent.h"
#import "RCTBridgeModule.h"
#import "RCTEventDispatcher.h"
#endif

@import GoogleMobileAds;

@interface RNAdMobInterstitial : NSObject <RCTBridgeModule, GADInterstitialDelegate>

@property (nonatomic, copy) RCTBubblingEventBlock onInterstitialDidLoad;
@property (nonatomic, copy) RCTBubblingEventBlock onInterstitialDidFailToLoad;
@property (nonatomic, copy) RCTBubblingEventBlock onInterstitialDidOpen;
@property (nonatomic, copy) RCTBubblingEventBlock onInterstitialDidClose;
@property (nonatomic, copy) RCTBubblingEventBlock onInterstitialWillLeaveApplication;

@end
22 changes: 15 additions & 7 deletions ios/RNAdMobInterstitial.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ @implementation RNAdMobInterstitial {
RCTResponseSenderBlock _showAdCallback;
}

@synthesize bridge = _bridge;

- (dispatch_queue_t)methodQueue
{
return dispatch_get_main_queue();
Expand Down Expand Up @@ -71,27 +69,37 @@ - (dispatch_queue_t)methodQueue
#pragma mark delegate events

- (void)interstitialDidReceiveAd:(GADInterstitial *)ad {
[self.bridge.eventDispatcher sendDeviceEventWithName:@"interstitialDidLoad" body:nil];
if (self.onInterstitialDidLoad) {
self.onInterstitialDidLoad(@{});
}
_requestAdCallback(@[[NSNull null]]);
}

- (void)interstitial:(GADInterstitial *)interstitial
didFailToReceiveAdWithError:(GADRequestError *)error {
[self.bridge.eventDispatcher sendDeviceEventWithName:@"interstitialDidFailToLoad" body:@{@"name": [error description]}];
if (self.onInterstitialDidFailToLoad) {
self.onInterstitialDidFailToLoad(@{@"name": [error description]});
}
_requestAdCallback(@[[error description]]);
}

- (void)interstitialWillPresentScreen:(GADInterstitial *)ad {
[self.bridge.eventDispatcher sendDeviceEventWithName:@"interstitialDidOpen" body:nil];
if (self.onInterstitialDidOpen) {
self.onInterstitialDidOpen(@{});
}
_showAdCallback(@[[NSNull null]]);
}

- (void)interstitialDidDismissScreen:(GADInterstitial *)ad {
[self.bridge.eventDispatcher sendDeviceEventWithName:@"interstitialDidClose" body:nil];
if (self.onInterstitialDidClose) {
self.onInterstitialDidClose(@{});
}
}

- (void)interstitialWillLeaveApplication:(GADInterstitial *)ad {
[self.bridge.eventDispatcher sendDeviceEventWithName:@"interstitialWillLeaveApplication" body:nil];
if (self.onInterstitialWillLeaveApplication) {
self.onInterstitialWillLeaveApplication(@{});
}
}

@end
14 changes: 11 additions & 3 deletions ios/RNAdMobRewarded.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
#if __has_include(<React/RCTEventDispatcher.h>)
#import <React/RCTEventDispatcher.h>
#if __has_include(<React/RCTComponent.h>)
#import <React/RCTComponent.h>
#import <React/RCTBridgeModule.h>
#else
#import "RCTEventDispatcher.h"
#import "RCTComponent.h"
#import "RCTBridgeModule.h"
#endif

@import GoogleMobileAds;

@interface RNAdMobRewarded : NSObject <RCTBridgeModule, GADRewardBasedVideoAdDelegate>

@property (nonatomic, copy) RCTBubblingEventBlock onRewardedVideoDidRewardUser;
@property (nonatomic, copy) RCTBubblingEventBlock onRewardedVideoDidLoad;
@property (nonatomic, copy) RCTBubblingEventBlock onRewardedVideoDidOpen;
@property (nonatomic, copy) RCTBubblingEventBlock onRewardedVideoDidClose;
@property (nonatomic, copy) RCTBubblingEventBlock onRewardedVideoWillLeaveApplication;
@property (nonatomic, copy) RCTBubblingEventBlock onRewardedVideoDidFailToLoad;

@end

26 changes: 18 additions & 8 deletions ios/RNAdMobRewarded.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ @implementation RNAdMobRewarded {
RCTResponseSenderBlock _showAdCallback;
}

@synthesize bridge = _bridge;

+ (void)initialize
{
NSLog(@"initialize");
Expand Down Expand Up @@ -71,16 +69,22 @@ - (dispatch_queue_t)methodQueue

- (void)rewardBasedVideoAd:(GADRewardBasedVideoAd *)rewardBasedVideoAd
didRewardUserWithReward:(GADAdReward *)reward {
[self.bridge.eventDispatcher sendDeviceEventWithName:@"rewardedVideoDidRewardUser" body:@{@"type": reward.type, @"amount": reward.amount}];
if (self.onRewardedVideoDidRewardUser) {
self.onRewardedVideoDidRewardUser(@{@"type": reward.type, @"amount": reward.amount});
}
}

- (void)rewardBasedVideoAdDidReceiveAd:(GADRewardBasedVideoAd *)rewardBasedVideoAd {
[self.bridge.eventDispatcher sendDeviceEventWithName:@"rewardedVideoDidLoad" body:nil];
if (self.onRewardedVideoDidLoad) {
self.onRewardedVideoDidLoad(@{});
}
_requestAdCallback(@[[NSNull null]]);
}

- (void)rewardBasedVideoAdDidOpen:(GADRewardBasedVideoAd *)rewardBasedVideoAd {
[self.bridge.eventDispatcher sendDeviceEventWithName:@"rewardedVideoDidOpen" body:nil];
if (self.onRewardedVideoDidOpen) {
self.onRewardedVideoDidOpen(@{});
}
_showAdCallback(@[[NSNull null]]);
}

Expand All @@ -89,16 +93,22 @@ - (void)rewardBasedVideoAdDidStartPlaying:(GADRewardBasedVideoAd *)rewardBasedVi
}

- (void)rewardBasedVideoAdDidClose:(GADRewardBasedVideoAd *)rewardBasedVideoAd {
[self.bridge.eventDispatcher sendDeviceEventWithName:@"rewardedVideoDidClose" body:nil];
if (self.onRewardedVideoDidClose) {
self.onRewardedVideoDidClose(@{});
}
}

- (void)rewardBasedVideoAdWillLeaveApplication:(GADRewardBasedVideoAd *)rewardBasedVideoAd {
[self.bridge.eventDispatcher sendDeviceEventWithName:@"rewardedVideoWillLeaveApplication" body:nil];
if (self.onRewardedVideoWillLeaveApplication) {
self.onRewardedVideoWillLeaveApplication(@{});
}
}

- (void)rewardBasedVideoAd:(GADRewardBasedVideoAd *)rewardBasedVideoAd
didFailToLoadWithError:(NSError *)error {
[self.bridge.eventDispatcher sendDeviceEventWithName:@"rewardedVideoDidFailToLoad" body:@{@"name": [error description]}];
if (self.onRewardedVideoDidFailToLoad) {
self.onRewardedVideoDidFailToLoad(@{@"name": [error description]});
}
_requestAdCallback(@[[error description]]);
}

Expand Down
5 changes: 1 addition & 4 deletions ios/RNDFPBannerView.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
#if __has_include(<React/RCTEventDispatcher.h>)
#if __has_include(<React/RCTComponent.h>)
#import <React/RCTComponent.h>
#else
#import "RCTComponent.h"
#endif

@import GoogleMobileAds;

@class RCTEventDispatcher;

@interface RNDFPBannerView : UIView <GADBannerViewDelegate>

@property (nonatomic, copy) NSString *bannerSize;
Expand All @@ -23,7 +21,6 @@
@property (nonatomic, copy) RCTBubblingEventBlock onAdViewDidDismissScreen;
@property (nonatomic, copy) RCTBubblingEventBlock onAdViewWillLeaveApplication;

- (instancetype)initWithEventDispatcher:(RCTEventDispatcher *)eventDispatcher NS_DESIGNATED_INITIALIZER;
- (GADAdSize)getAdSizeFromString:(NSString *)bannerSize;
- (void)loadBanner;

Expand Down

0 comments on commit 3bec144

Please sign in to comment.