diff --git a/src/ads/native-ad/NativeAd.ts b/src/ads/native-ad/NativeAd.ts index b74dc8e3..be3e1384 100644 --- a/src/ads/native-ad/NativeAd.ts +++ b/src/ads/native-ad/NativeAd.ts @@ -16,7 +16,6 @@ */ import { EventSubscription, NativeEventEmitter, Platform } from 'react-native'; -import EventEmitter from 'react-native/Libraries/vendor/emitter/EventEmitter'; import { NativeAdEventType } from '../../NativeAdEventType'; import { isFunction, isOneOf, isString } from '../../common'; @@ -52,7 +51,8 @@ export class NativeAd { readonly extras: Record | null; private nativeEventSubscription: EventSubscription; - private eventEmitter: EventEmitter; + private eventEmitter: NativeEventEmitter; + private readonly eventEmitterTypes: string[]; private constructor(adUnitId: string, props: NativeAdProps) { this.adUnitId = adUnitId; @@ -68,6 +68,7 @@ export class NativeAd { this.images = props.images; this.mediaContent = props.mediaContent; this.extras = props.extras as Record; + this.eventEmitterTypes = []; if ('onAdEvent' in NativeGoogleMobileAdsNativeModule) { this.nativeEventSubscription = NativeGoogleMobileAdsNativeModule.onAdEvent( @@ -84,8 +85,9 @@ export class NativeAd { 'RNGMANativeAdEvent', this.onNativeAdEvent.bind(this), ); + this.eventEmitterTypes.push('RNGMANativeAdEvent'); } - this.eventEmitter = new EventEmitter(); + this.eventEmitter = new NativeEventEmitter(); } private onNativeAdEvent({ responseId, type, ...data }: NativeAdEventPayload) { @@ -106,11 +108,16 @@ export class NativeAd { throw new Error(`NativeAd.addAdEventListener(_, *) 'listener' expected a function.`); } + this.eventEmitterTypes.push(type); return this.eventEmitter.addListener(type, listener); } removeAllAdEventListeners() { - this.eventEmitter.removeAllListeners(); + this.eventEmitterTypes.forEach(type => { + this.eventEmitter.removeAllListeners(type); + }); + // we want the array to be read-only, but also want to clear it. + this.eventEmitterTypes.splice(0, this.eventEmitterTypes.length); } destroy() { diff --git a/src/internal/SharedEventEmitter.ts b/src/internal/SharedEventEmitter.ts index 5923815b..dd6cf4d3 100644 --- a/src/internal/SharedEventEmitter.ts +++ b/src/internal/SharedEventEmitter.ts @@ -15,6 +15,6 @@ * */ -import EventEmitter from 'react-native/Libraries/vendor/emitter/EventEmitter'; +import { NativeEventEmitter } from 'react-native'; -export const SharedEventEmitter: EventEmitter = new EventEmitter(); +export const SharedEventEmitter: NativeEventEmitter = new NativeEventEmitter(); diff --git a/src/specs/components/GoogleMobileAdsBannerViewNativeComponent.ts b/src/specs/components/GoogleMobileAdsBannerViewNativeComponent.ts index d93d3e0b..7076a848 100644 --- a/src/specs/components/GoogleMobileAdsBannerViewNativeComponent.ts +++ b/src/specs/components/GoogleMobileAdsBannerViewNativeComponent.ts @@ -17,29 +17,27 @@ import type * as React from 'react'; import type { HostComponent, ViewProps } from 'react-native'; -import type { BubblingEventHandler, Float } from 'react-native/Libraries/Types/CodegenTypes'; -import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent'; -import codegenNativeCommands from 'react-native/Libraries/Utilities/codegenNativeCommands'; +import { codegenNativeCommands, codegenNativeComponent, CodegenTypes } from 'react-native'; export type NativeEvent = { type: string; - width?: Float; - height?: Float; + width?: CodegenTypes.Float; + height?: CodegenTypes.Float; code?: string; message?: string; name?: string; data?: string; currency?: string; - precision?: Float; - value?: Float; + precision?: CodegenTypes.Float; + value?: CodegenTypes.Float; }; export interface NativeProps extends ViewProps { - sizeConfig: { sizes: string[]; maxHeight?: Float; width?: Float }; + sizeConfig: { sizes: string[]; maxHeight?: CodegenTypes.Float; width?: CodegenTypes.Float }; unitId: string; request: string; manualImpressionsEnabled: boolean; - onNativeEvent: BubblingEventHandler; + onNativeEvent: CodegenTypes.BubblingEventHandler; } export type ComponentType = HostComponent; diff --git a/src/specs/components/GoogleMobileAdsMediaViewNativeComponent.ts b/src/specs/components/GoogleMobileAdsMediaViewNativeComponent.ts index 5465164f..40fbbeca 100644 --- a/src/specs/components/GoogleMobileAdsMediaViewNativeComponent.ts +++ b/src/specs/components/GoogleMobileAdsMediaViewNativeComponent.ts @@ -16,7 +16,7 @@ */ import type { HostComponent, ViewProps } from 'react-native'; -import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent'; +import { codegenNativeComponent } from 'react-native'; export interface NativeProps extends ViewProps { responseId: string; diff --git a/src/specs/components/GoogleMobileAdsNativeViewNativeComponent.ts b/src/specs/components/GoogleMobileAdsNativeViewNativeComponent.ts index 5b93bd1a..9cafc079 100644 --- a/src/specs/components/GoogleMobileAdsNativeViewNativeComponent.ts +++ b/src/specs/components/GoogleMobileAdsNativeViewNativeComponent.ts @@ -17,9 +17,7 @@ import type * as React from 'react'; import type { HostComponent, ViewProps } from 'react-native'; -import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent'; -import codegenNativeCommands from 'react-native/Libraries/Utilities/codegenNativeCommands'; -import type { Int32 } from 'react-native/Libraries/Types/CodegenTypes'; +import { codegenNativeComponent, codegenNativeCommands, CodegenTypes } from 'react-native'; export interface NativeProps extends ViewProps { responseId: string; @@ -29,10 +27,11 @@ type NativeViewComponentType = HostComponent; interface NativeCommands { registerAsset: ( + // TODO - we may remove this deprecation and shift to React.ComponentRef when RN0.84 is our minimum // eslint-disable-next-line @typescript-eslint/no-deprecated -- https://github.com/facebook/react-native/issues/54272 viewRef: React.ElementRef, assetType: string, - reactTag: Int32, + reactTag: CodegenTypes.Int32, ) => void; } diff --git a/src/specs/modules/NativeAppOpenModule.ts b/src/specs/modules/NativeAppOpenModule.ts index d391fb36..953e50bc 100644 --- a/src/specs/modules/NativeAppOpenModule.ts +++ b/src/specs/modules/NativeAppOpenModule.ts @@ -16,11 +16,19 @@ */ import { TurboModule, TurboModuleRegistry } from 'react-native'; -import { Double, UnsafeObject } from 'react-native/Libraries/Types/CodegenTypes'; +import { CodegenTypes } from 'react-native'; export interface Spec extends TurboModule { - appOpenLoad(requestId: Double, adUnitId: string, requestOptions: UnsafeObject): void; - appOpenShow(requestId: Double, adUnitId: string, showOptions?: UnsafeObject): Promise; + appOpenLoad( + requestId: CodegenTypes.Double, + adUnitId: string, + requestOptions: CodegenTypes.UnsafeObject, + ): void; + appOpenShow( + requestId: CodegenTypes.Double, + adUnitId: string, + showOptions?: CodegenTypes.UnsafeObject, + ): Promise; } export default TurboModuleRegistry.getEnforcing('RNGoogleMobileAdsAppOpenModule'); diff --git a/src/specs/modules/NativeGoogleMobileAdsModule.ts b/src/specs/modules/NativeGoogleMobileAdsModule.ts index 24957139..a04f926c 100644 --- a/src/specs/modules/NativeGoogleMobileAdsModule.ts +++ b/src/specs/modules/NativeGoogleMobileAdsModule.ts @@ -17,13 +17,13 @@ import type { TurboModule } from 'react-native'; import { TurboModuleRegistry } from 'react-native'; -import type { UnsafeObject } from 'react-native/Libraries/Types/CodegenTypes'; +import type { CodegenTypes } from 'react-native'; import { AdapterStatus } from '../../types'; export interface Spec extends TurboModule { initialize(): Promise; - setRequestConfiguration(requestConfiguration?: UnsafeObject): Promise; + setRequestConfiguration(requestConfiguration?: CodegenTypes.UnsafeObject): Promise; openAdInspector(): Promise; openDebugMenu(adUnit: string): void; setAppVolume(volume: number): void; diff --git a/src/specs/modules/NativeInterstitialModule.ts b/src/specs/modules/NativeInterstitialModule.ts index bcf8f1b4..9bd639ef 100644 --- a/src/specs/modules/NativeInterstitialModule.ts +++ b/src/specs/modules/NativeInterstitialModule.ts @@ -16,11 +16,19 @@ */ import { TurboModule, TurboModuleRegistry } from 'react-native'; -import { UnsafeObject } from 'react-native/Libraries/Types/CodegenTypes'; +import { CodegenTypes } from 'react-native'; export interface Spec extends TurboModule { - interstitialLoad(requestId: number, adUnitId: string, requestOptions: UnsafeObject): void; - interstitialShow(requestId: number, adUnitId: string, showOptions?: UnsafeObject): Promise; + interstitialLoad( + requestId: number, + adUnitId: string, + requestOptions: CodegenTypes.UnsafeObject, + ): void; + interstitialShow( + requestId: number, + adUnitId: string, + showOptions?: CodegenTypes.UnsafeObject, + ): Promise; } export default TurboModuleRegistry.getEnforcing('RNGoogleMobileAdsInterstitialModule'); diff --git a/src/specs/modules/NativeRewardedInterstitialModule.ts b/src/specs/modules/NativeRewardedInterstitialModule.ts index 1c7c7a6b..dba1a8ab 100644 --- a/src/specs/modules/NativeRewardedInterstitialModule.ts +++ b/src/specs/modules/NativeRewardedInterstitialModule.ts @@ -16,14 +16,18 @@ */ import { TurboModule, TurboModuleRegistry } from 'react-native'; -import { UnsafeObject } from 'react-native/Libraries/Types/CodegenTypes'; +import { CodegenTypes } from 'react-native'; export interface Spec extends TurboModule { - rewardedInterstitialLoad(requestId: number, adUnitId: string, requestOptions: UnsafeObject): void; + rewardedInterstitialLoad( + requestId: number, + adUnitId: string, + requestOptions: CodegenTypes.UnsafeObject, + ): void; rewardedInterstitialShow( requestId: number, adUnitId: string, - showOptions?: UnsafeObject, + showOptions?: CodegenTypes.UnsafeObject, ): Promise; } diff --git a/src/specs/modules/NativeRewardedModule.ts b/src/specs/modules/NativeRewardedModule.ts index 8f615c57..bc577dd8 100644 --- a/src/specs/modules/NativeRewardedModule.ts +++ b/src/specs/modules/NativeRewardedModule.ts @@ -16,11 +16,19 @@ */ import { TurboModule, TurboModuleRegistry } from 'react-native'; -import { UnsafeObject } from 'react-native/Libraries/Types/CodegenTypes'; +import { CodegenTypes } from 'react-native'; export interface Spec extends TurboModule { - rewardedLoad(requestId: number, adUnitId: string, requestOptions: UnsafeObject): void; - rewardedShow(requestId: number, adUnitId: string, showOptions?: UnsafeObject): Promise; + rewardedLoad( + requestId: number, + adUnitId: string, + requestOptions: CodegenTypes.UnsafeObject, + ): void; + rewardedShow( + requestId: number, + adUnitId: string, + showOptions?: CodegenTypes.UnsafeObject, + ): Promise; } export default TurboModuleRegistry.getEnforcing('RNGoogleMobileAdsRewardedModule');