Skip to content

Commit 5e0c83b

Browse files
committed
fix(native, ios): fix bridgeless mode compatibility for native ad views
1 parent 8a5be91 commit 5e0c83b

File tree

4 files changed

+19
-3
lines changed

4 files changed

+19
-3
lines changed

ios/RNGoogleMobileAds/RNGoogleMobileAdsMediaView.mm

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,15 @@ @implementation RNGoogleMobileAdsMediaView {
5252

5353
- (instancetype)initWithFrame:(CGRect)frame {
5454
if (self = [super initWithFrame:frame]) {
55-
static const auto defaultProps = std::make_shared<const RNGoogleMobileAdsBannerViewProps>();
55+
static const auto defaultProps = std::make_shared<const RNGoogleMobileAdsMediaViewProps>();
5656
_props = defaultProps;
5757

5858
_bridge = [RCTBridge currentBridge];
59-
_nativeModule = [_bridge moduleForClass:RNGoogleMobileAdsNativeModule.class];
59+
if (_bridge) {
60+
_nativeModule = [_bridge moduleForClass:RNGoogleMobileAdsNativeModule.class];
61+
} else {
62+
_nativeModule = [RNGoogleMobileAdsNativeModule sharedInstance];
63+
}
6064
_mediaView = [[GADMediaView alloc] init];
6165
_contentMode = UIViewContentModeScaleAspectFill;
6266
self.contentView = _mediaView;

ios/RNGoogleMobileAds/RNGoogleMobileAdsNativeModule.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
@interface RNGoogleMobileAdsNativeModule : RCTEventEmitter <RCTBridgeModule>
3131
#endif
3232

33+
+ (instancetype)sharedInstance;
3334
- (GADNativeAd *)nativeAdForResponseId:(NSString *)responseId;
3435

3536
@end

ios/RNGoogleMobileAds/RNGoogleMobileAdsNativeModule.mm

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,16 @@ - (dispatch_queue_t)methodQueue {
5959
}
6060
#endif
6161

62+
static __weak RNGoogleMobileAdsNativeModule *_sharedInstance = nil;
63+
64+
+ (instancetype)sharedInstance {
65+
return _sharedInstance;
66+
}
67+
6268
- (instancetype)init {
6369
if (self = [super init]) {
6470
_adHolders = [NSMutableDictionary dictionary];
71+
_sharedInstance = self;
6572
}
6673
return self;
6774
}

ios/RNGoogleMobileAds/RNGoogleMobileAdsNativeView.mm

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,11 @@ - (instancetype)initWithFrame:(CGRect)frame {
5858
_props = defaultProps;
5959

6060
_bridge = [RCTBridge currentBridge];
61-
_nativeModule = [_bridge moduleForClass:RNGoogleMobileAdsNativeModule.class];
61+
if (_bridge) {
62+
_nativeModule = [_bridge moduleForClass:RNGoogleMobileAdsNativeModule.class];
63+
} else {
64+
_nativeModule = [RNGoogleMobileAdsNativeModule sharedInstance];
65+
}
6266
_nativeAdView = [[GADNativeAdView alloc] init];
6367
self.contentView = _nativeAdView;
6468
}

0 commit comments

Comments
 (0)