diff --git a/README.md b/README.md index 73ca84d6..3b8929b9 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ When using The New Architecture, some legacy code will still be used though. See | iOS | Full Screen Ads (Turbo Native Module) | ✅ Complete | | iOS | User Messaging Platform (Turbo Native Module) | ⏳ To-Do | | iOS | EventEmitter (Turbo Native Module) | ⏳ To-Do | -| iOS | Revenue Precision Constants (Turbo Native Module) | ⏳ To-Do | +| iOS | Revenue Precision Constants (Turbo Native Module) | ✅ Complete | | Android | Mobile Ads SDK Methods (Turbo Native Module) | ⏳ To-Do | | Android | Banners (Fabric Native Component) | ⏳ To-Do | | Android | Full Screen Ads (Turbo Native Module) | ⏳ To-Do | diff --git a/android/src/main/java/io/invertase/googlemobileads/ReactNativeAppModule.java b/android/src/main/java/io/invertase/googlemobileads/ReactNativeAppModule.java index 89cf6f6f..c845b11d 100644 --- a/android/src/main/java/io/invertase/googlemobileads/ReactNativeAppModule.java +++ b/android/src/main/java/io/invertase/googlemobileads/ReactNativeAppModule.java @@ -21,7 +21,6 @@ import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.bridge.ReactMethod; import com.facebook.react.bridge.ReadableMap; -import com.google.android.gms.ads.AdValue; import io.invertase.googlemobileads.common.RCTConvert; import io.invertase.googlemobileads.common.ReactNativeEvent; import io.invertase.googlemobileads.common.ReactNativeEventEmitter; @@ -29,8 +28,6 @@ import io.invertase.googlemobileads.common.ReactNativeMeta; import io.invertase.googlemobileads.common.ReactNativeModule; import io.invertase.googlemobileads.common.ReactNativePreferences; -import java.util.HashMap; -import java.util.Map; public class ReactNativeAppModule extends ReactNativeModule { private static final String TAG = "RNAppModule"; @@ -150,29 +147,4 @@ public void preferencesClearAll(Promise promise) { ReactNativePreferences.getSharedInstance().clearAll(); promise.resolve(null); } - - @Override - public Map getConstants() { - Map constants = new HashMap<>(); - // List> appsList = new ArrayList<>(); - // List reactNativeApps = ReactNativeApp.getApps(getReactApplicationContext()); - - // for (ReactNativeApp app : reactNativeApps) { - // appsList.add(RCTConvertFirebase.reactNativeAppToMap(app)); - // } - - // constants.put("NATIVE_FIREBASE_APPS", appsList); - - // constants.put("FIREBASE_RAW_JSON", ReactNativeJSON.getSharedInstance().getRawJSON()); - - // Precision types in ad revenue events. - // See: - // https://developers.google.com/android/reference/com/google/android/gms/ads/AdValue.PrecisionType - constants.put("REVENUE_PRECISION_UNKNOWN", AdValue.PrecisionType.UNKNOWN); - constants.put("REVENUE_PRECISION_ESTIMATED", AdValue.PrecisionType.ESTIMATED); - constants.put("REVENUE_PRECISION_PUBLISHER_PROVIDED", AdValue.PrecisionType.PUBLISHER_PROVIDED); - constants.put("REVENUE_PRECISION_PRECISE", AdValue.PrecisionType.PRECISE); - - return constants; - } } diff --git a/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsModule.kt b/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsModule.kt index 29c57164..aedc2daa 100644 --- a/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsModule.kt +++ b/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsModule.kt @@ -23,6 +23,7 @@ import com.google.android.gms.ads.initialization.OnInitializationCompleteListene import com.google.android.gms.ads.RequestConfiguration import com.google.android.gms.ads.AdInspectorError import com.google.android.gms.ads.AdRequest +import com.google.android.gms.ads.AdValue; import com.google.android.gms.ads.OnAdInspectorClosedListener private const val SERVICE = "RNGoogleMobileAdsModule"; @@ -33,6 +34,18 @@ class ReactNativeGoogleMobileAdsModule( override fun getName() = SERVICE + override fun getConstants(): Map { + return mapOf( + // Precision types in ad revenue events. + // See: + // https://developers.google.com/android/reference/com/google/android/gms/ads/AdValue.PrecisionType + "REVENUE_PRECISION_UNKNOWN" to AdValue.PrecisionType.UNKNOWN, + "REVENUE_PRECISION_ESTIMATED" to AdValue.PrecisionType.ESTIMATED, + "REVENUE_PRECISION_PUBLISHER_PROVIDED" to AdValue.PrecisionType.PUBLISHER_PROVIDED, + "REVENUE_PRECISION_PRECISE" to AdValue.PrecisionType.PRECISE + ) + } + private fun buildRequestConfiguration( requestConfiguration: ReadableMap ): RequestConfiguration { diff --git a/ios/RNGoogleMobileAds/RNGoogleMobileAdsModule.mm b/ios/RNGoogleMobileAds/RNGoogleMobileAdsModule.mm index 7fc1d425..a24d31be 100644 --- a/ios/RNGoogleMobileAds/RNGoogleMobileAdsModule.mm +++ b/ios/RNGoogleMobileAds/RNGoogleMobileAdsModule.mm @@ -175,4 +175,21 @@ - (void)openAdInspector:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseReject #endif } +- (NSDictionary *)constantsToExport { + return @{ + // Precision types in ad revenue events. + // See: https://developers.google.com/admob/ios/impression-level-ad-revenue#objective-c +#if !TARGET_OS_MACCATALYST + @"REVENUE_PRECISION_UNKNOWN" : @(GADAdValuePrecisionUnknown), + @"REVENUE_PRECISION_ESTIMATED" : @(GADAdValuePrecisionEstimated), + @"REVENUE_PRECISION_PUBLISHER_PROVIDED" : @(GADAdValuePrecisionPublisherProvided), + @"REVENUE_PRECISION_PRECISE" : @(GADAdValuePrecisionPrecise) + }; +#endif +} + +- (NSDictionary *)getConstants { + return [self constantsToExport]; +} + @end diff --git a/ios/RNGoogleMobileAds/common/RNAppModule.m b/ios/RNGoogleMobileAds/common/RNAppModule.m index 050ece09..09a72a1f 100644 --- a/ios/RNGoogleMobileAds/common/RNAppModule.m +++ b/ios/RNGoogleMobileAds/common/RNAppModule.m @@ -17,10 +17,6 @@ #import -#if !TARGET_OS_MACCATALYST -#import -#endif - #import "RNAppModule.h" #import "RNJSON.h" #import "RNMeta.h" @@ -148,23 +144,6 @@ - (void)invalidate { // Keep: Required for RN built in Event Emitter Calls. } -- (NSDictionary *)constantsToExport { - NSMutableDictionary *constants = [NSMutableDictionary new]; - - constants[@"ADMOB_RAW_JSON"] = [[RNJSON shared] getRawJSON]; - - // Precision types in ad revenue events. - // See: https://developers.google.com/admob/ios/impression-level-ad-revenue#objective-c -#if !TARGET_OS_MACCATALYST - constants[@"REVENUE_PRECISION_UNKNOWN"] = @(GADAdValuePrecisionUnknown); - constants[@"REVENUE_PRECISION_ESTIMATED"] = @(GADAdValuePrecisionEstimated); - constants[@"REVENUE_PRECISION_PUBLISHER_PROVIDED"] = @(GADAdValuePrecisionPublisherProvided); - constants[@"REVENUE_PRECISION_PRECISE"] = @(GADAdValuePrecisionPrecise); -#endif - - return constants; -} - + (BOOL)requiresMainQueueSetup { return YES; } diff --git a/src/common/constants.ts b/src/common/constants.ts index 1fb9db7f..b0020581 100644 --- a/src/common/constants.ts +++ b/src/common/constants.ts @@ -1,11 +1,11 @@ -import { NativeModules } from 'react-native'; +import RNGoogleMobileAdsModule from '../specs/modules/NativeGoogleMobileAdsModule'; const { REVENUE_PRECISION_ESTIMATED, REVENUE_PRECISION_PRECISE, REVENUE_PRECISION_PUBLISHER_PROVIDED, REVENUE_PRECISION_UNKNOWN, -} = NativeModules.RNAppModule.getConstants?.() ?? {}; +} = RNGoogleMobileAdsModule.getConstants?.() ?? {}; export enum RevenuePrecisions { ESTIMATED = REVENUE_PRECISION_ESTIMATED, diff --git a/src/specs/modules/NativeGoogleMobileAdsModule.ts b/src/specs/modules/NativeGoogleMobileAdsModule.ts index 4225e654..d82f1ee3 100644 --- a/src/specs/modules/NativeGoogleMobileAdsModule.ts +++ b/src/specs/modules/NativeGoogleMobileAdsModule.ts @@ -22,6 +22,13 @@ import { UnsafeObject } from 'react-native/Libraries/Types/CodegenTypes'; import { AdapterStatus } from '../../types'; export interface Spec extends TurboModule { + readonly getConstants: () => { + REVENUE_PRECISION_ESTIMATED: number; + REVENUE_PRECISION_PRECISE: number; + REVENUE_PRECISION_PUBLISHER_PROVIDED: number; + REVENUE_PRECISION_UNKNOWN: number; + }; + initialize(): Promise; setRequestConfiguration(requestConfiguration?: UnsafeObject): Promise; openAdInspector(): Promise;