Skip to content

fix(native, ios): fix bridgeless mode compatibility for native ad views#845

Open
adsellor wants to merge 1 commit intoinvertase:mainfrom
adsellor:fix/ios-bridgeless-native-ads
Open

fix(native, ios): fix bridgeless mode compatibility for native ad views#845
adsellor wants to merge 1 commit intoinvertase:mainfrom
adsellor:fix/ios-bridgeless-native-ads

Conversation

@adsellor
Copy link
Copy Markdown

@adsellor adsellor commented Apr 1, 2026

Description

Fix iOS native ad views crashing/not working in bridgeless (New Architecture) mode.

  • Fix incorrect props type in RNGoogleMobileAdsMediaView (BannerViewPropsMediaViewProps)
  • Add sharedInstance weak singleton accessor to RNGoogleMobileAdsNativeModule for bridgeless module resolution
  • Update RNGoogleMobileAdsNativeView and RNGoogleMobileAdsMediaView to fall back to sharedInstance when RCTBridge is nil

Note

The weak singleton approach is just a workaround to allow usage with new architecture. A future improvement would be to use RCTModuleRegistry for proper bridgeless module resolution.

Related issues

N/A

Release Summary

iOS native ad views now work correctly in bridgeless (New Architecture) mode.

Checklist

  • I read the Contributor Guide
    and followed the process outlined there for submitting PRs.
    • Yes
  • My change supports the following platforms;
    • Android
    • iOS
  • My change includes tests;
    • e2e tests added or updated in __tests__e2e__
    • jest tests added or updated in __tests__
  • I have updated TypeScript types that are affected by my change.
  • This is a breaking change;
    • Yes
    • No

Test Plan

  • Verified native ads load and render correctly on iOS in bridgeless mode
  • Verified native ads still work on iOS with the classic bridge
  • Verified GADMediaView renders media content properly in both modes

🔥

@docs-page
Copy link
Copy Markdown

docs-page bot commented Apr 1, 2026

To view this pull requests documentation preview, visit the following URL:

docs.page/invertase/react-native-google-mobile-ads~845

Documentation is deployed and generated using docs.page.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a singleton pattern for RNGoogleMobileAdsNativeModule to support Bridgeless mode and fixes a property type mismatch in RNGoogleMobileAdsMediaView. The review feedback identifies potential issues with the singleton implementation in multi-instance scenarios and suggests lazy module resolution to prevent nil references during the lazy initialization process characteristic of Bridgeless mode.

- (instancetype)init {
if (self = [super init]) {
_adHolders = [NSMutableDictionary dictionary];
_sharedInstance = self;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

In scenarios with multiple React Native instances (e.g., multiple bridges or surfaces), this assignment will overwrite the _sharedInstance with the most recently initialized module. This can cause views in older instances to incorrectly reference the module from the new instance, potentially leading to state inconsistencies or missing ad references. While acceptable as a workaround for bridgeless mode, consider if a more robust resolution mechanism (like using the module registry) is needed for multi-instance support.

Comment on lines +59 to +63
if (_bridge) {
_nativeModule = [_bridge moduleForClass:RNGoogleMobileAdsNativeModule.class];
} else {
_nativeModule = [RNGoogleMobileAdsNativeModule sharedInstance];
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

In Bridgeless mode, TurboModules are often initialized lazily. If this view is instantiated before the RNGoogleMobileAdsNativeModule has been accessed from JavaScript, [RNGoogleMobileAdsNativeModule sharedInstance] will return nil, and _nativeModule will remain nil for the lifetime of this view. It is safer to resolve the module lazily when it is first needed (e.g., in setResponseId:) rather than only during initialization.

Comment on lines +61 to +65
if (_bridge) {
_nativeModule = [_bridge moduleForClass:RNGoogleMobileAdsNativeModule.class];
} else {
_nativeModule = [RNGoogleMobileAdsNativeModule sharedInstance];
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

In Bridgeless mode, TurboModules are often initialized lazily. If this view is instantiated before the RNGoogleMobileAdsNativeModule has been accessed from JavaScript, [RNGoogleMobileAdsNativeModule sharedInstance] will return nil, and _nativeModule will remain nil for the lifetime of this view. It is safer to resolve the module lazily when it is first needed (e.g., in setResponseId:) rather than only during initialization.

@adsellor adsellor force-pushed the fix/ios-bridgeless-native-ads branch from 5e0c83b to a032bcb Compare April 1, 2026 19:23
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Apr 1, 2026

CLA assistant check
All committers have signed the CLA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants