Skip to content

Commit 1d93455

Browse files
이명규dylancom
authored andcommitted
fix(ios): resolve native asset registration issues in New Architecture
This commit fixes an issue where native ad assets could not be found via their react tags when the New Architecture (Fabric) was enabled. - Added a recursive findViewByTag:inView: helper method to navigate the view hierarchy. - Updated registerAsset:reactTag: to use the new lookup logic in New Architecture. - The lookup now searches within both the _nativeAdView and the component itself.
1 parent e7bc2cc commit 1d93455

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

ios/RNGoogleMobileAds/RNGoogleMobileAdsNativeView.mm

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,23 @@ - (void)handleCommand:(const NSString *)commandName args:(const NSArray *)args {
104104
RCTRNGoogleMobileAdsNativeViewHandleCommand(self, commandName, args);
105105
}
106106

107+
- (UIView *)findViewByTag:(NSInteger)targetTag inView:(UIView *)parentView {
108+
for (UIView *subview in parentView.subviews) {
109+
if (subview.tag == targetTag) {
110+
return subview;
111+
}
112+
if ([subview isKindOfClass:[RCTViewComponentView class]]) {
113+
UIView *contentView = ((RCTViewComponentView *)subview).contentView;
114+
if (contentView && contentView.tag == targetTag) {
115+
return contentView;
116+
}
117+
}
118+
UIView *found = [self findViewByTag:targetTag inView:subview];
119+
if (found) return found;
120+
}
121+
return nil;
122+
}
123+
107124
#else
108125
#pragma mark - Paper specific
109126

@@ -128,7 +145,14 @@ - (void)setResponseId:(NSString *)responseId {
128145

129146
- (void)registerAsset:(NSString *)assetType reactTag:(NSInteger)reactTag {
130147
RCTExecuteOnMainQueue(^{
148+
#ifdef RCT_NEW_ARCH_ENABLED
149+
UIView *view = [self findViewByTag:reactTag inView:_nativeAdView];
150+
if (!view) {
151+
view = [self findViewByTag:reactTag inView:self];
152+
}
153+
#else
131154
UIView *view = [_bridge.uiManager viewForReactTag:@(reactTag)];
155+
#endif
132156
if (!view) {
133157
RCTLogError(@"Cannot find NativeAssetView with tag #%zd while registering asset type %@",
134158
reactTag, assetType);

0 commit comments

Comments
 (0)