Skip to content

Commit

Permalink
fix(ios): register asset view properly in old arch
Browse files Browse the repository at this point in the history
  • Loading branch information
wjaykim committed Jan 23, 2025
1 parent f44c27e commit 166aa47
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions ios/RNGoogleMobileAds/RNGoogleMobileAdsNativeView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,12 @@ - (void)setResponseId:(NSString *)responseId {
- (void)registerAsset:(NSString *)assetType reactTag:(NSInteger)reactTag {
RCTExecuteOnMainQueue(^{
UIView *view = [_bridge.uiManager viewForReactTag:@(reactTag)];

if (!view) {
RCTLogError(@"Cannot find NativeAssetView with tag #%zd while registering asset type %@",
reactTag, assetType);
return;
}

if ([assetType isEqual:@"media"] && [view isKindOfClass:RNGoogleMobileAdsMediaView.class]) {
#ifdef RCT_NEW_ARCH_ENABLED
GADMediaView *mediaView = ((RNGoogleMobileAdsMediaView *)view).contentView;
Expand Down Expand Up @@ -194,17 +199,17 @@ - (UIView *)view {
}

RCT_EXPORT_METHOD(registerAsset
: (nonnull NSNumber *)reactTag commandID
: (NSInteger)commandID commandArgs
: (NSArray<id> *)commandArgs) {
: (nonnull NSNumber *)reactTag assetType
: (nonnull NSString *)assetType assetReactTag
: (nonnull NSNumber *)assetReactTag) {
[self.bridge.uiManager
addUIBlock:^(RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
RNGoogleMobileAdsNativeView *view = viewRegistry[reactTag];
if (!view || ![view isKindOfClass:[RNGoogleMobileAdsNativeView class]]) {
RCTLogError(@"Cannot find NativeView with tag #%@", reactTag);
return;
}
[view registerAsset:commandArgs[0] reactTag:((NSNumber *)commandArgs[1]).intValue];
[view registerAsset:assetType reactTag:assetReactTag.intValue];
}];
}
#endif
Expand Down

0 comments on commit 166aa47

Please sign in to comment.