Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ios): precision constants on new arch #665

Merged
merged 1 commit into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,13 @@
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;
import io.invertase.googlemobileads.common.ReactNativeJSON;
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";
Expand Down Expand Up @@ -150,29 +147,4 @@ public void preferencesClearAll(Promise promise) {
ReactNativePreferences.getSharedInstance().clearAll();
promise.resolve(null);
}

@Override
public Map<String, Object> getConstants() {
Map<String, Object> constants = new HashMap<>();
// List<Map<String, Object>> appsList = new ArrayList<>();
// List<ReactNativeApp> 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -33,6 +34,18 @@ class ReactNativeGoogleMobileAdsModule(

override fun getName() = SERVICE

override fun getConstants(): Map<String, Any> {
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 {
Expand Down
17 changes: 17 additions & 0 deletions ios/RNGoogleMobileAds/RNGoogleMobileAdsModule.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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
21 changes: 0 additions & 21 deletions ios/RNGoogleMobileAds/common/RNAppModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@

#import <React/RCTUtils.h>

#if !TARGET_OS_MACCATALYST
#import <GoogleMobileAds/GoogleMobileAds.h>
#endif

#import "RNAppModule.h"
#import "RNJSON.h"
#import "RNMeta.h"
Expand Down Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions src/common/constants.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
7 changes: 7 additions & 0 deletions src/specs/modules/NativeGoogleMobileAdsModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<AdapterStatus[]>;
setRequestConfiguration(requestConfiguration?: UnsafeObject): Promise<void>;
openAdInspector(): Promise<void>;
Expand Down
Loading