Skip to content
Open
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
15 changes: 11 additions & 4 deletions src/ads/native-ad/NativeAd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -52,7 +51,8 @@ export class NativeAd {
readonly extras: Record<string, unknown> | null;

private nativeEventSubscription: EventSubscription;
private eventEmitter: EventEmitter;
private eventEmitter: NativeEventEmitter;
private readonly eventEmitterTypes: string[];

private constructor(adUnitId: string, props: NativeAdProps) {
this.adUnitId = adUnitId;
Expand All @@ -68,6 +68,7 @@ export class NativeAd {
this.images = props.images;
this.mediaContent = props.mediaContent;
this.extras = props.extras as Record<string, unknown>;
this.eventEmitterTypes = [];

if ('onAdEvent' in NativeGoogleMobileAdsNativeModule) {
this.nativeEventSubscription = NativeGoogleMobileAdsNativeModule.onAdEvent(
Expand All @@ -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) {
Expand All @@ -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() {
Expand Down
4 changes: 2 additions & 2 deletions src/internal/SharedEventEmitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
16 changes: 7 additions & 9 deletions src/specs/components/GoogleMobileAdsBannerViewNativeComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<NativeEvent>;
onNativeEvent: CodegenTypes.BubblingEventHandler<NativeEvent>;
}

export type ComponentType = HostComponent<NativeProps>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -29,10 +27,11 @@ type NativeViewComponentType = HostComponent<NativeProps>;

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<NativeViewComponentType>,
assetType: string,
reactTag: Int32,
reactTag: CodegenTypes.Int32,
) => void;
}

Expand Down
14 changes: 11 additions & 3 deletions src/specs/modules/NativeAppOpenModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>;
appOpenLoad(
requestId: CodegenTypes.Double,
adUnitId: string,
requestOptions: CodegenTypes.UnsafeObject,
): void;
appOpenShow(
requestId: CodegenTypes.Double,
adUnitId: string,
showOptions?: CodegenTypes.UnsafeObject,
): Promise<void>;
}

export default TurboModuleRegistry.getEnforcing<Spec>('RNGoogleMobileAdsAppOpenModule');
4 changes: 2 additions & 2 deletions src/specs/modules/NativeGoogleMobileAdsModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<AdapterStatus[]>;
setRequestConfiguration(requestConfiguration?: UnsafeObject): Promise<void>;
setRequestConfiguration(requestConfiguration?: CodegenTypes.UnsafeObject): Promise<void>;
openAdInspector(): Promise<void>;
openDebugMenu(adUnit: string): void;
setAppVolume(volume: number): void;
Expand Down
14 changes: 11 additions & 3 deletions src/specs/modules/NativeInterstitialModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>;
interstitialLoad(
requestId: number,
adUnitId: string,
requestOptions: CodegenTypes.UnsafeObject,
): void;
interstitialShow(
requestId: number,
adUnitId: string,
showOptions?: CodegenTypes.UnsafeObject,
): Promise<void>;
}

export default TurboModuleRegistry.getEnforcing<Spec>('RNGoogleMobileAdsInterstitialModule');
10 changes: 7 additions & 3 deletions src/specs/modules/NativeRewardedInterstitialModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>;
}

Expand Down
14 changes: 11 additions & 3 deletions src/specs/modules/NativeRewardedModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>;
rewardedLoad(
requestId: number,
adUnitId: string,
requestOptions: CodegenTypes.UnsafeObject,
): void;
rewardedShow(
requestId: number,
adUnitId: string,
showOptions?: CodegenTypes.UnsafeObject,
): Promise<void>;
}

export default TurboModuleRegistry.getEnforcing<Spec>('RNGoogleMobileAdsRewardedModule');
Loading