From 4e5da905eefdb0773a5aa142498742585b56be89 Mon Sep 17 00:00:00 2001 From: nouvistiardi Date: Fri, 21 May 2021 23:28:58 +0700 Subject: [PATCH 1/2] add basic typescript definition --- index.d.ts | 124 +++++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 1 + 2 files changed, 125 insertions(+) create mode 100644 index.d.ts diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 000000000..cae58e636 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,124 @@ +import { ViewProps } from 'react-native'; + +interface AdMobBannerProps extends ViewProps { + /** + * AdMob iOS library banner size constants + * (https://developers.google.com/admob/ios/banner) + * banner (320x50, Standard Banner for Phones and Tablets) + * largeBanner (320x100, Large Banner for Phones and Tablets) + * mediumRectangle (300x250, IAB Medium Rectangle for Phones and Tablets) + * fullBanner (468x60, IAB Full-Size Banner for Tablets) + * leaderboard (728x90, IAB Leaderboard for Tablets) + * smartBannerPortrait (Screen width x 32|50|90, Smart Banner for Phones and Tablets) + * smartBannerLandscape (Screen width x 32|50|90, Smart Banner for Phones and Tablets) + * + * banner is default + */ + adSize?: + | 'banner' + | 'largeBanner' + | 'mediumRectangle' + | 'fullBanner' + | 'leaderboard' + | 'smartBannerPortrait' + | 'smartBannerLandscape'; + + /** + * AdMob ad unit ID + */ + adUnitID: string; + + /** + * Array of test devices. Use AdMobBanner.simulatorId for the simulator + */ + testDevices?: string[]; + + /** + * AdMob iOS library events + */ + onSizeChange?: Function; + + onAdLoaded?: Function; + onAdFailedToLoad?: Function; + onAdOpened?: Function; + onAdClosed?: Function; + onAdLeftApplication?: Function; +} +export const AdMobBanner: React.FC; + +export const AdMobInterstitial: { + setAdUnitID: (adUnitID: string) => void; + setTestDevices: (testDevices: string[]) => void; + requestAd: () => Promise; + showAd: () => Promise; + isReady: (callback: Function) => void; + addEventListener: (event: unknown, handler: unknown) => void; + removeEventListener: (type: unknown, handler: unknown) => void; + removeAllListeners: () => void; + simulatorId: 'SIMULATOR'; +}; + +interface PublisherBannerProps extends ViewProps { + /** + * DFP iOS library banner size constants + * (https://developers.google.com/admob/ios/banner) + * banner (320x50, Standard Banner for Phones and Tablets) + * largeBanner (320x100, Large Banner for Phones and Tablets) + * mediumRectangle (300x250, IAB Medium Rectangle for Phones and Tablets) + * fullBanner (468x60, IAB Full-Size Banner for Tablets) + * leaderboard (728x90, IAB Leaderboard for Tablets) + * smartBannerPortrait (Screen width x 32|50|90, Smart Banner for Phones and Tablets) + * smartBannerLandscape (Screen width x 32|50|90, Smart Banner for Phones and Tablets) + * + * banner is default + */ + adSize?: + | 'banner' + | 'largeBanner' + | 'mediumRectangle' + | 'fullBanner' + | 'leaderboard' + | 'smartBannerPortrait' + | 'smartBannerLandscape'; + + /** + * Optional array specifying all valid sizes that are appropriate for this slot. + */ + validAdSizes?: string[]; + + /** + * DFP ad unit ID + */ + adUnitID: string; + + /** + * Array of test devices. Use PublisherBanner.simulatorId for the simulator + */ + testDevices?: string[]; + + onSizeChange?: Function; + + /** + * DFP library events + */ + onAdLoaded?: Function; + onAdFailedToLoad?: Function; + onAdOpened?: Function; + onAdClosed?: Function; + onAdLeftApplication?: Function; + onAppEvent?: Function; +} + +export const PublisherBanner: React.FC; + +export const AdMobRewarded: { + setAdUnitID: (adUnitID: string) => void; + setTestDevices: (testDevices: string[]) => void; + requestAd: () => Promise; + showAd: () => Promise; + isReady: (callback: Function) => void; + addEventListener: (event: unknown, handler: unknown) => void; + removeEventListener: (type: unknown, handler: unknown) => void; + removeAllListeners: () => void; + simulatorId: 'SIMULATOR'; +}; diff --git a/package.json b/package.json index 358fb0cc4..6ee02be48 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,7 @@ "description": "A react-native component for Google AdMob banners and interstitials", "author": "Simon Bugert ", "main": "index.js", + "types": "index.d.ts", "license": "BSD-2-Clause", "repository": { "type": "git", From b93f79b2019537e6f784cfaf3c95249e2d2d475f Mon Sep 17 00:00:00 2001 From: nouvistiardi Date: Fri, 21 May 2021 23:41:16 +0700 Subject: [PATCH 2/2] update typescript definition --- index.d.ts | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/index.d.ts b/index.d.ts index cae58e636..691fadb37 100644 --- a/index.d.ts +++ b/index.d.ts @@ -39,7 +39,7 @@ interface AdMobBannerProps extends ViewProps { onSizeChange?: Function; onAdLoaded?: Function; - onAdFailedToLoad?: Function; + onAdFailedToLoad?: (err: Error) => any; onAdOpened?: Function; onAdClosed?: Function; onAdLeftApplication?: Function; @@ -52,8 +52,16 @@ export const AdMobInterstitial: { requestAd: () => Promise; showAd: () => Promise; isReady: (callback: Function) => void; - addEventListener: (event: unknown, handler: unknown) => void; - removeEventListener: (type: unknown, handler: unknown) => void; + addEventListener: ( + event: + | 'adLoaded' + | 'adFailedToLoad' + | 'adOpened' + | 'adClosed' + | 'adLeftApplication', + handler: Function + ) => void; + removeEventListener: (type: unknown, handler: Function) => void; removeAllListeners: () => void; simulatorId: 'SIMULATOR'; }; @@ -102,7 +110,7 @@ interface PublisherBannerProps extends ViewProps { * DFP library events */ onAdLoaded?: Function; - onAdFailedToLoad?: Function; + onAdFailedToLoad?: (err: Error) => any; onAdOpened?: Function; onAdClosed?: Function; onAdLeftApplication?: Function; @@ -117,8 +125,19 @@ export const AdMobRewarded: { requestAd: () => Promise; showAd: () => Promise; isReady: (callback: Function) => void; - addEventListener: (event: unknown, handler: unknown) => void; - removeEventListener: (type: unknown, handler: unknown) => void; + addEventListener: ( + event: + | 'adLoaded' + | 'adFailedToLoad' + | 'adOpened' + | 'adClosed' + | 'adLeftApplication' + | 'rewarded' + | 'videoStarted' + | 'videoCompleted', + handler: Function + ) => void; + removeEventListener: (type: unknown, handler: Function) => void; removeAllListeners: () => void; simulatorId: 'SIMULATOR'; };