Skip to content

Commit

Permalink
feat!: typescript rewrite (#41)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
dylancom authored and mikehardy committed Feb 7, 2022
1 parent f15ccd5 commit 4114e4b
Show file tree
Hide file tree
Showing 71 changed files with 2,620 additions and 1,876 deletions.
1 change: 0 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ module.exports = {
'no-empty-description': 'off',
'@typescript-eslint/ban-ts-comment': 'off', // keep it professional when you use them though please
'@typescript-eslint/no-use-before-define': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,7 @@ google-services.json
GoogleService-Info.plist

# generated files
src/version.ts
RNFBVersion.m
ReactNativeFirebaseVersion.java

Expand All @@ -564,3 +565,6 @@ spelling.json
# Gatsby / Website
website/.cache
website/public

# generated files by bob
lib/
2 changes: 1 addition & 1 deletion __tests__/consent.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AdsConsent } from '../lib';
import { AdsConsent } from '../src';

describe('Google Ads AdsConsent', function () {
describe('requestInfoUpdate', function () {
Expand Down
5 changes: 2 additions & 3 deletions __tests__/googleAds.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import admob, { GoogleAdsTypes } from '../lib';
import admob, { MaxAdContentRating } from '../src';

describe('Admob', function () {
describe('setRequestConfiguration()', function () {
Expand All @@ -13,8 +13,7 @@ describe('Admob', function () {
it('throws if maxAdContentRating is invalid', function () {
expect(() =>
admob().setRequestConfiguration({
maxAdContentRating:
'Y' as GoogleAdsTypes.MaxAdContentRating[keyof GoogleAdsTypes.MaxAdContentRating],
maxAdContentRating: 'Y' as MaxAdContentRating,
}),
).toThrowError(
"setRequestConfiguration(*) 'requestConfiguration.maxAdContentRating' expected on of MaxAdContentRating.G, MaxAdContentRating.PG, MaxAdContentRating.T or MaxAdContentRating.MA",
Expand Down
2 changes: 1 addition & 1 deletion __tests__/interstitial.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { InterstitialAd } from '../lib';
import { InterstitialAd } from '../src';

describe('Google Ads Interstitial', function () {
describe('createForAdRequest', function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,13 @@ public ReactNativeModule(ReactApplicationContext reactContext, String moduleName
this.executorService = new TaskExecutorService(getName());
}

public static void rejectPromiseWithExceptionMap(Promise promise, Exception exception) {
promise.reject(exception, SharedUtils.getExceptionMap(exception));
}

public static void rejectPromiseWithCodeAndMessage(Promise promise, String code, String message) {
WritableMap userInfoMap = Arguments.createMap();
userInfoMap.putString("code", code);
userInfoMap.putString("message", message);
promise.reject(code, message, userInfoMap);
}

public static void rejectPromiseWithCodeAndMessage(
Promise promise, String code, String message, String nativeErrorMessage) {
WritableMap userInfoMap = Arguments.createMap();
userInfoMap.putString("code", code);
userInfoMap.putString("message", message);
userInfoMap.putString("nativeErrorMessage", nativeErrorMessage);
promise.reject(code, message, userInfoMap);
}

@Override
public void initialize() {
super.initialize();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,6 @@ public static Uri getUri(String uri) {
return parsed;
}

public static WritableMap getExceptionMap(Exception exception) {
WritableMap exceptionMap = Arguments.createMap();
String code = "unknown";
String message = exception.getMessage();
exceptionMap.putString("code", code);
exceptionMap.putString("nativeErrorCode", code);
exceptionMap.putString("message", message);
exceptionMap.putString("nativeErrorMessage", message);
return exceptionMap;
}

public static String timestampToUTC(long timestamp) {
long millisTimestamp = timestamp * 1000;
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
Expand Down
8 changes: 4 additions & 4 deletions docs/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ receive content suitable for children before loading any adverts.
If you need to set a custom request configuration, you must call the `setRequestConfiguration` method before initializing the Google Mobile Ads SDK:

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

admob()
mobileAds()
.setRequestConfiguration({
// Update all future requests suitable for parental guidance
maxAdContentRating: MaxAdContentRating.PG,
Expand Down Expand Up @@ -111,9 +111,9 @@ This needs to be done only once, ideally at app launch.
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.

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

admob()
mobileAds()
.initialize()
.then((adapterStatuses) => {
// Initialization complete!
Expand Down
5 changes: 0 additions & 5 deletions ios/RNGoogleAds/common/RNSharedUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@

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

+ (void)rejectPromiseWithExceptionDict:(RCTPromiseRejectBlock)reject
exception:(NSException *)exception;

+ (void)rejectPromiseWithNSError:(RCTPromiseRejectBlock)reject error:(NSError *)error;

+ (void)rejectPromiseWithUserInfo:(RCTPromiseRejectBlock)reject
userInfo:(NSMutableDictionary *)userInfo;

Expand Down
30 changes: 0 additions & 30 deletions ios/RNGoogleAds/common/RNSharedUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,36 +27,6 @@ @implementation RNSharedUtils
#pragma mark -
#pragma mark Methods

+ (void)rejectPromiseWithExceptionDict:(RCTPromiseRejectBlock)reject
exception:(NSException *)exception {
NSMutableDictionary *userInfo = [NSMutableDictionary dictionary];

[userInfo setValue:@(YES) forKey:@"fatal"];
[userInfo setValue:@"unknown" forKey:@"code"];
[userInfo setValue:exception.reason forKey:@"message"];
[userInfo setValue:exception.name forKey:@"nativeErrorCode"];
[userInfo setValue:exception.reason forKey:@"nativeErrorMessage"];

NSError *error = [NSError errorWithDomain:RNErrorDomain code:666 userInfo:userInfo];

reject(exception.name, exception.reason, error);
}

+ (void)rejectPromiseWithNSError:(RCTPromiseRejectBlock)reject error:(NSError *)error {
NSMutableDictionary *userInfo = [NSMutableDictionary dictionary];

[userInfo setValue:@(NO) forKey:@"fatal"];
[userInfo setValue:@"unknown" forKey:@"code"];
[userInfo setValue:error.localizedDescription forKey:@"message"];
[userInfo setValue:@(error.code) forKey:@"nativeErrorCode"];
[userInfo setValue:error.localizedDescription forKey:@"nativeErrorMessage"];

NSError *newErrorWithUserInfo = [NSError errorWithDomain:RNErrorDomain
code:666
userInfo:userInfo];
reject(@"unknown", error.localizedDescription, newErrorWithUserInfo);
}

+ (void)rejectPromiseWithUserInfo:(RCTPromiseRejectBlock)reject
userInfo:(NSMutableDictionary *)userInfo {
NSError *error = [NSError errorWithDomain:RNErrorDomain code:666 userInfo:userInfo];
Expand Down
11 changes: 2 additions & 9 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
module.exports = {
maxConcurrency: 10,
preset: './node_modules/react-native/jest-preset.js',
transform: {
'^.+\\.(js)$': '<rootDir>/node_modules/babel-jest',
'\\.(ts|tsx)$': 'ts-jest',
},
preset: 'react-native',
modulePathIgnorePatterns: ['<rootDir>/example/node_modules', '<rootDir>/lib/'],
setupFiles: ['./jest.setup.ts'],
testRegex: '(/^__tests__/.*|(\\.|/)(test|spec))\\.[jt]sx?$',
modulePaths: ['node_modules'],
moduleDirectories: ['node_modules'],
moduleFileExtensions: ['ts', 'tsx', 'js'],
};
24 changes: 0 additions & 24 deletions lib/AdEventType.js

This file was deleted.

23 changes: 0 additions & 23 deletions lib/MaxAdContentRating.js

This file was deleted.

21 changes: 0 additions & 21 deletions lib/RewardedAdEventType.js

This file was deleted.

77 changes: 0 additions & 77 deletions lib/ads/InterstitialAd.js

This file was deleted.

Loading

0 comments on commit 4114e4b

Please sign in to comment.