Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Dallas62 committed Nov 8, 2021
1 parent eb1a258 commit a85abd2
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import java.util.List;

public class ReactNativeGoogleAdsConsentModule extends ReactNativeModule {
private static final String TAG = "GoogleAdsConsent";
private static final String TAG = "RNGoogleAdsConsentModule";
private ConsentInformation consentInformation;
private ConsentForm consentForm;

Expand Down Expand Up @@ -223,4 +223,14 @@ public void addTestDevices(ReadableArray deviceIds, Promise promise) {
}
promise.resolve(null);
}

@ReactMethod
public void addListener(String eventName) {
// Keep: Required for RN built in Event Emitter Calls.
}

@ReactMethod
public void removeListeners(Integer count) {
// Keep: Required for RN built in Event Emitter Calls.
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
import javax.annotation.Nullable;

public class ReactNativeGoogleAdsInterstitialModule extends ReactNativeModule {
private static final String SERVICE = "GoogleAdsInterstitial";
private static final String SERVICE = "RNGoogleAdsInterstitialModule";
private static SparseArray<InterstitialAd> interstitialAdArray = new SparseArray<>();

public ReactNativeGoogleAdsInterstitialModule(ReactApplicationContext reactContext) {
Expand Down Expand Up @@ -149,4 +149,14 @@ public void interstitialShow(int requestId, ReadableMap showOptions, Promise pro
}
});
}

@ReactMethod
public void addListener(String eventName) {
// Keep: Required for RN built in Event Emitter Calls.
}

@ReactMethod
public void removeListeners(Integer count) {
// Keep: Required for RN built in Event Emitter Calls.
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import java.util.Objects;

public class ReactNativeGoogleAdsModule extends ReactNativeModule {
private static final String SERVICE = "GoogleAds";
private static final String SERVICE = "RNGoogleAdsModule";

ReactNativeGoogleAdsModule(ReactApplicationContext reactContext) {
super(reactContext, SERVICE);
Expand Down Expand Up @@ -90,4 +90,14 @@ public void setRequestConfiguration(ReadableMap requestConfiguration, Promise pr
MobileAds.setRequestConfiguration(buildRequestConfiguration(requestConfiguration));
promise.resolve(null);
}

@ReactMethod
public void addListener(String eventName) {
// Keep: Required for RN built in Event Emitter Calls.
}

@ReactMethod
public void removeListeners(Integer count) {
// Keep: Required for RN built in Event Emitter Calls.
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import io.invertase.googleads.common.ReactNativeModule;

public class ReactNativeGoogleAdsRewardedModule extends ReactNativeModule {
private static final String SERVICE = "GoogleAdsRewarded";
private static final String SERVICE = "RNGoogleAdsRewardedModule";
private static SparseArray<RewardedAd> rewardedAdArray = new SparseArray<>();

public ReactNativeGoogleAdsRewardedModule(ReactApplicationContext reactContext) {
Expand Down Expand Up @@ -158,4 +158,14 @@ public void onRewardedAdFailedToShow(int errorCode) {
promise.resolve(null);
});
}

@ReactMethod
public void addListener(String eventName) {
// Keep: Required for RN built in Event Emitter Calls.
}

@ReactMethod
public void removeListeners(Integer count) {
// Keep: Required for RN built in Event Emitter Calls.
}
}
8 changes: 8 additions & 0 deletions ios/RNGoogleAds/RNGoogleAdsModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,12 @@ - (void)setRequestConfiguration:(NSDictionary *)requestConfiguration {
}
}

RCT_EXPORT_METHOD(addListener : (NSString *)eventName) {
// Keep: Required for RN built in Event Emitter Calls.
}

RCT_EXPORT_METHOD(removeListeners : (NSInteger)count) {
// Keep: Required for RN built in Event Emitter Calls.
}

@end
8 changes: 4 additions & 4 deletions jest.setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ jest.doMock('react-native', () => {
},
NativeModules: {
...ReactNative.NativeModules,
GoogleAdsModule: {
RNGoogleAdsModule: {
addListener: jest.fn(),
removeListeners: jest.fn(),
eventsAddListener: jest.fn(),
eventsNotifyReady: jest.fn(),
},
GoogleAdsInterstitialModule: {},
GoogleAdsRewardedModule: {},
GoogleAdsConsentModule: {},
RNGoogleAdsInterstitialModule: {},
RNGoogleAdsRewardedModule: {},
RNGoogleAdsConsentModule: {},
},
},
ReactNative,
Expand Down
2 changes: 1 addition & 1 deletion lib/AdsConsent.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { NativeModules } from 'react-native';
import AdsConsentDebugGeography from './AdsConsentDebugGeography';
import AdsConsentStatus from './AdsConsentStatus';

const native = NativeModules.GoogleAdsConsentModule;
const native = NativeModules.RNGoogleAdsConsentModule;

export default {
/**
Expand Down
5 changes: 4 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ class GoogleAdsModule extends Module {
// import { SDK_VERSION } from '@invertase/react-native-google-ads';
export const SDK_VERSION = version;

export default new GoogleAdsModule();
export default new GoogleAdsModule('AppName', {
namespace: 'GoogleAds',
nativeModuleName: 'RNGoogleAdsModule'
});

export { default as AdsConsentDebugGeography } from './AdsConsentDebugGeography';
export { default as AdsConsentStatus } from './AdsConsentStatus';
Expand Down
14 changes: 7 additions & 7 deletions lib/internal/GoogleAdsNativeEventEmitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@

import { NativeEventEmitter, NativeModules } from 'react-native';

const { GoogleAdsModule } = NativeModules;
const { RNGoogleAdsModule } = NativeModules;

class GoogleAdsNativeEventEmitter extends NativeEventEmitter {
constructor() {
super(GoogleAdsModule);
super(RNGoogleAdsModule);
this.ready = false;
}

addListener(eventType, listener, context) {
if (!this.ready) {
GoogleAdsModule.eventsNotifyReady(true);
RNGoogleAdsModule.eventsNotifyReady(true);
this.ready = true;
}
GoogleAdsModule.eventsAddListener(eventType);
RNGoogleAdsModule.eventsAddListener(eventType);

let subscription = super.addListener(`google_ads_${eventType}`, listener, context);

Expand All @@ -45,7 +45,7 @@ class GoogleAdsNativeEventEmitter extends NativeEventEmitter {
// we will modify it to do our native unsubscription then call the original
let originalRemove = subscription.remove;
let newRemove = () => {
GoogleAdsModule.eventsRemoveListener(eventType, false);
RNGoogleAdsModule.eventsRemoveListener(eventType, false);
if (super.removeSubscription != null) {
// This is for RN <= 0.64 - 65 and greater no longer have removeSubscription
super.removeSubscription(subscription);
Expand All @@ -59,13 +59,13 @@ class GoogleAdsNativeEventEmitter extends NativeEventEmitter {
}

removeAllListeners(eventType) {
GoogleAdsModule.eventsRemoveListener(eventType, true);
RNGoogleAdsModule.eventsRemoveListener(eventType, true);
super.removeAllListeners(`google_ads_${eventType}`);
}

// This is likely no longer ever called, but it is here for backwards compatibility with RN <= 0.64
removeSubscription(subscription) {
GoogleAdsModule.eventsRemoveListener(subscription.eventType.replace('google_ads_'), false);
RNGoogleAdsModule.eventsRemoveListener(subscription.eventType.replace('google_ads_'), false);
if (super.removeSubscription) {
super.removeSubscription(subscription);
}
Expand Down
4 changes: 3 additions & 1 deletion lib/internal/registry/nativeModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const NATIVE_MODULE_REGISTRY = {};
const NATIVE_MODULE_EVENT_SUBSCRIPTIONS = {};

function nativeModuleKey(module) {
return `${module._customUrlOrRegion || ''}:${module.app.name}:${module._config.namespace}`;
return `${module._customUrlOrRegion || ''}:${module.app.name || ''}:${module._config.namespace || ''}`;
}

/**
Expand Down Expand Up @@ -90,6 +90,8 @@ function initialiseNativeModule(module) {
const { namespace, nativeEvents, nativeModuleName } = config;
const nativeModuleNames = [nativeModuleName];

let multiModuleRoot = {}, multiModule = false;

for (let i = 0; i < nativeModuleNames.length; i++) {
const nativeModule = NativeModules[nativeModuleNames[i]];

Expand Down

0 comments on commit a85abd2

Please sign in to comment.