Skip to content

Commit 4114e4b

Browse files
dylancommikehardy
authored andcommitted
feat!: typescript rewrite (invertase#41)
* refactor: re-write library in typescript * refactor: use global undefined * no emit * remove explicit any * refactor: use named exports * use the same naming as the native class MobileAds * git track uppercase change
1 parent f15ccd5 commit 4114e4b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+2620
-1876
lines changed

.eslintrc.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ module.exports = {
4646
'no-empty-description': 'off',
4747
'@typescript-eslint/ban-ts-comment': 'off', // keep it professional when you use them though please
4848
'@typescript-eslint/no-use-before-define': 'off',
49-
'@typescript-eslint/no-explicit-any': 'off',
5049
'@typescript-eslint/no-var-requires': 'off',
5150
'@typescript-eslint/explicit-function-return-type': 'off',
5251
'@typescript-eslint/explicit-module-boundary-types': 'off',

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,7 @@ google-services.json
551551
GoogleService-Info.plist
552552

553553
# generated files
554+
src/version.ts
554555
RNFBVersion.m
555556
ReactNativeFirebaseVersion.java
556557

@@ -564,3 +565,6 @@ spelling.json
564565
# Gatsby / Website
565566
website/.cache
566567
website/public
568+
569+
# generated files by bob
570+
lib/

__tests__/consent.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { AdsConsent } from '../lib';
1+
import { AdsConsent } from '../src';
22

33
describe('Google Ads AdsConsent', function () {
44
describe('requestInfoUpdate', function () {

__tests__/googleAds.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import admob, { GoogleAdsTypes } from '../lib';
1+
import admob, { MaxAdContentRating } from '../src';
22

33
describe('Admob', function () {
44
describe('setRequestConfiguration()', function () {
@@ -13,8 +13,7 @@ describe('Admob', function () {
1313
it('throws if maxAdContentRating is invalid', function () {
1414
expect(() =>
1515
admob().setRequestConfiguration({
16-
maxAdContentRating:
17-
'Y' as GoogleAdsTypes.MaxAdContentRating[keyof GoogleAdsTypes.MaxAdContentRating],
16+
maxAdContentRating: 'Y' as MaxAdContentRating,
1817
}),
1918
).toThrowError(
2019
"setRequestConfiguration(*) 'requestConfiguration.maxAdContentRating' expected on of MaxAdContentRating.G, MaxAdContentRating.PG, MaxAdContentRating.T or MaxAdContentRating.MA",

__tests__/interstitial.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { InterstitialAd } from '../lib';
1+
import { InterstitialAd } from '../src';
22

33
describe('Google Ads Interstitial', function () {
44
describe('createForAdRequest', function () {

android/src/main/java/io/invertase/googleads/common/ReactNativeModule.java

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,26 +37,13 @@ public ReactNativeModule(ReactApplicationContext reactContext, String moduleName
3737
this.executorService = new TaskExecutorService(getName());
3838
}
3939

40-
public static void rejectPromiseWithExceptionMap(Promise promise, Exception exception) {
41-
promise.reject(exception, SharedUtils.getExceptionMap(exception));
42-
}
43-
4440
public static void rejectPromiseWithCodeAndMessage(Promise promise, String code, String message) {
4541
WritableMap userInfoMap = Arguments.createMap();
4642
userInfoMap.putString("code", code);
4743
userInfoMap.putString("message", message);
4844
promise.reject(code, message, userInfoMap);
4945
}
5046

51-
public static void rejectPromiseWithCodeAndMessage(
52-
Promise promise, String code, String message, String nativeErrorMessage) {
53-
WritableMap userInfoMap = Arguments.createMap();
54-
userInfoMap.putString("code", code);
55-
userInfoMap.putString("message", message);
56-
userInfoMap.putString("nativeErrorMessage", nativeErrorMessage);
57-
promise.reject(code, message, userInfoMap);
58-
}
59-
6047
@Override
6148
public void initialize() {
6249
super.initialize();

android/src/main/java/io/invertase/googleads/common/SharedUtils.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -82,17 +82,6 @@ public static Uri getUri(String uri) {
8282
return parsed;
8383
}
8484

85-
public static WritableMap getExceptionMap(Exception exception) {
86-
WritableMap exceptionMap = Arguments.createMap();
87-
String code = "unknown";
88-
String message = exception.getMessage();
89-
exceptionMap.putString("code", code);
90-
exceptionMap.putString("nativeErrorCode", code);
91-
exceptionMap.putString("message", message);
92-
exceptionMap.putString("nativeErrorMessage", message);
93-
return exceptionMap;
94-
}
95-
9685
public static String timestampToUTC(long timestamp) {
9786
long millisTimestamp = timestamp * 1000;
9887
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");

docs/index.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ receive content suitable for children before loading any adverts.
7878
If you need to set a custom request configuration, you must call the `setRequestConfiguration` method before initializing the Google Mobile Ads SDK:
7979

8080
```js
81-
import admob, { MaxAdContentRating } from '@invertase/react-native-google-ads';
81+
import mobileAds, { MaxAdContentRating } from '@invertase/react-native-google-ads';
8282

83-
admob()
83+
mobileAds()
8484
.setRequestConfiguration({
8585
// Update all future requests suitable for parental guidance
8686
maxAdContentRating: MaxAdContentRating.PG,
@@ -111,9 +111,9 @@ This needs to be done only once, ideally at app launch.
111111
If you need to obtain consent from users in the European Economic Area (EEA), set any request-specific flags (such as tagForChildDirectedTreatment), or otherwise take action before loading ads, ensure you do so before initializing the Mobile Ads SDK.
112112

113113
```js
114-
import admob from '@invertase/react-native-google-ads';
114+
import mobileAds from '@invertase/react-native-google-ads';
115115

116-
admob()
116+
mobileAds()
117117
.initialize()
118118
.then((adapterStatuses) => {
119119
// Initialization complete!

ios/RNGoogleAds/common/RNSharedUtils.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,6 @@
3838

3939
+ (void)sendJSEvent:name:(NSString *)name body:(NSDictionary *)body;
4040

41-
+ (void)rejectPromiseWithExceptionDict:(RCTPromiseRejectBlock)reject
42-
exception:(NSException *)exception;
43-
44-
+ (void)rejectPromiseWithNSError:(RCTPromiseRejectBlock)reject error:(NSError *)error;
45-
4641
+ (void)rejectPromiseWithUserInfo:(RCTPromiseRejectBlock)reject
4742
userInfo:(NSMutableDictionary *)userInfo;
4843

ios/RNGoogleAds/common/RNSharedUtils.m

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -27,36 +27,6 @@ @implementation RNSharedUtils
2727
#pragma mark -
2828
#pragma mark Methods
2929

30-
+ (void)rejectPromiseWithExceptionDict:(RCTPromiseRejectBlock)reject
31-
exception:(NSException *)exception {
32-
NSMutableDictionary *userInfo = [NSMutableDictionary dictionary];
33-
34-
[userInfo setValue:@(YES) forKey:@"fatal"];
35-
[userInfo setValue:@"unknown" forKey:@"code"];
36-
[userInfo setValue:exception.reason forKey:@"message"];
37-
[userInfo setValue:exception.name forKey:@"nativeErrorCode"];
38-
[userInfo setValue:exception.reason forKey:@"nativeErrorMessage"];
39-
40-
NSError *error = [NSError errorWithDomain:RNErrorDomain code:666 userInfo:userInfo];
41-
42-
reject(exception.name, exception.reason, error);
43-
}
44-
45-
+ (void)rejectPromiseWithNSError:(RCTPromiseRejectBlock)reject error:(NSError *)error {
46-
NSMutableDictionary *userInfo = [NSMutableDictionary dictionary];
47-
48-
[userInfo setValue:@(NO) forKey:@"fatal"];
49-
[userInfo setValue:@"unknown" forKey:@"code"];
50-
[userInfo setValue:error.localizedDescription forKey:@"message"];
51-
[userInfo setValue:@(error.code) forKey:@"nativeErrorCode"];
52-
[userInfo setValue:error.localizedDescription forKey:@"nativeErrorMessage"];
53-
54-
NSError *newErrorWithUserInfo = [NSError errorWithDomain:RNErrorDomain
55-
code:666
56-
userInfo:userInfo];
57-
reject(@"unknown", error.localizedDescription, newErrorWithUserInfo);
58-
}
59-
6030
+ (void)rejectPromiseWithUserInfo:(RCTPromiseRejectBlock)reject
6131
userInfo:(NSMutableDictionary *)userInfo {
6232
NSError *error = [NSError errorWithDomain:RNErrorDomain code:666 userInfo:userInfo];

0 commit comments

Comments
 (0)