forked from izetmolla/react-native-admob-next
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
24,064 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
declare const _default: any; | ||
export default _default; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { NativeModules, NativeEventEmitter } from "react-native"; | ||
import { createErrorFromErrorData } from "./utils"; | ||
const RNAdMobInterstitial = NativeModules.RNAdMobInterstitial; | ||
const eventEmitter = new NativeEventEmitter(RNAdMobInterstitial); | ||
const eventMap = { | ||
adLoaded: "interstitialAdLoaded", | ||
adFailedToLoad: "interstitialAdFailedToLoad", | ||
adOpened: "interstitialAdOpened", | ||
adFailedToOpen: "interstitialAdFailedToOpen", | ||
adClosed: "interstitialAdClosed", | ||
adImpression: "interstitialAdImpression", | ||
}; | ||
const _subscriptions = new Map(); | ||
const addEventListener = (event, handler) => { | ||
const mappedEvent = eventMap[event]; | ||
if (mappedEvent) { | ||
let listener; | ||
if (event === "adFailedToLoad") { | ||
listener = eventEmitter.addListener(mappedEvent, (error) => handler(createErrorFromErrorData(error))); | ||
} | ||
else { | ||
listener = eventEmitter.addListener(mappedEvent, handler); | ||
} | ||
_subscriptions.set(handler, listener); | ||
return { | ||
remove: () => removeEventListener(event, handler), | ||
}; | ||
} | ||
else { | ||
console.warn(`Trying to subscribe to unknown event: "${event}"`); | ||
return { | ||
remove: () => { }, | ||
}; | ||
} | ||
}; | ||
const removeEventListener = (type, handler) => { | ||
const listener = _subscriptions.get(handler); | ||
if (!listener) { | ||
return; | ||
} | ||
listener.remove(); | ||
_subscriptions.delete(handler); | ||
}; | ||
const removeAllListeners = () => { | ||
_subscriptions.forEach((listener, key, map) => { | ||
listener.remove(); | ||
map.delete(key); | ||
}); | ||
}; | ||
export default { | ||
...RNAdMobInterstitial, | ||
addEventListener, | ||
removeEventListener, | ||
removeAllListeners, | ||
simulatorId: "SIMULATOR", | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
declare const _default: any; | ||
export default _default; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { NativeModules, NativeEventEmitter } from "react-native"; | ||
import { createErrorFromErrorData } from "./utils"; | ||
const RNAdMobRewarded = NativeModules.RNAdMobRewarded; | ||
const eventEmitter = new NativeEventEmitter(RNAdMobRewarded); | ||
const eventMap = { | ||
adLoaded: "rewardedVideoAdLoaded", | ||
adFailedToLoad: "rewardedVideoAdFailedToLoad", | ||
adOpened: "rewardedVideoAdOpened", | ||
adFailedToOpen: "rewardedVideoAdFailedToOpen", | ||
adClosed: "rewardedVideoAdClosed", | ||
rewarded: "rewardedVideoAdRewarded", | ||
adImpression: "rewardedVideoAdImpression", | ||
}; | ||
const _subscriptions = new Map(); | ||
const addEventListener = (event, handler) => { | ||
const mappedEvent = eventMap[event]; | ||
if (mappedEvent) { | ||
let listener; | ||
if (event === "adFailedToLoad") { | ||
listener = eventEmitter.addListener(mappedEvent, (error) => handler(createErrorFromErrorData(error))); | ||
} | ||
else { | ||
listener = eventEmitter.addListener(mappedEvent, handler); | ||
} | ||
_subscriptions.set(handler, listener); | ||
return { | ||
remove: () => removeEventListener(event, handler), | ||
}; | ||
} | ||
else { | ||
console.warn(`Trying to subscribe to unknown event: "${event}"`); | ||
return { | ||
remove: () => { }, | ||
}; | ||
} | ||
}; | ||
const removeEventListener = (type, handler) => { | ||
const listener = _subscriptions.get(handler); | ||
if (!listener) { | ||
return; | ||
} | ||
listener.remove(); | ||
_subscriptions.delete(handler); | ||
}; | ||
const removeAllListeners = () => { | ||
_subscriptions.forEach((listener, key, map) => { | ||
listener.remove(); | ||
map.delete(key); | ||
}); | ||
}; | ||
export default { | ||
...RNAdMobRewarded, | ||
addEventListener, | ||
removeEventListener, | ||
removeAllListeners, | ||
simulatorId: "SIMULATOR", | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
declare const _default: { | ||
BANNER: string; | ||
FULL_BANNER: string; | ||
LARGE_BANNER: string; | ||
FLUID: string; | ||
SKYSCRAPER: string; | ||
LEADERBOARD: string; | ||
MEDIUM_RECTANGLE: string; | ||
ADAPTIVE_BANNER: string; | ||
}; | ||
export default _default; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export default { | ||
BANNER: "banner", | ||
FULL_BANNER: "fullBanner", | ||
LARGE_BANNER: "largeBanner", | ||
FLUID: "fluid", | ||
SKYSCRAPER: "skyscraper", | ||
LEADERBOARD: "leaderboard", | ||
MEDIUM_RECTANGLE: "mediumRectangle", | ||
ADAPTIVE_BANNER: "adaptiveBanner", | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
declare const _default: { | ||
BANNER?: string | undefined; | ||
INTERSTITIAL?: string | undefined; | ||
REWARDED?: string | undefined; | ||
}; | ||
export default _default; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { Platform } from 'react-native'; | ||
export default { | ||
...Platform.select({ | ||
android: { | ||
BANNER: 'ca-app-pub-3940256099942544/6300978111', | ||
INTERSTITIAL: 'ca-app-pub-3940256099942544/1033173712', | ||
REWARDED: 'ca-app-pub-3940256099942544/5224354917', | ||
}, | ||
ios: { | ||
BANNER: 'ca-app-pub-3940256099942544/2934735716', | ||
INTERSTITIAL: 'ca-app-pub-3940256099942544/4411468910', | ||
REWARDED: 'ca-app-pub-3940256099942544/1712485313', | ||
}, | ||
}), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { FC } from "react"; | ||
declare type AdmobBannerTypes = { | ||
style?: any | {}; | ||
onSizeChange?: any; | ||
onAdFailedToLoad?: any; | ||
adSize?: string; | ||
adUnitID?: string; | ||
testDevices?: any; | ||
onAdLoaded?: any; | ||
onAdRecordImpression?: any; | ||
onAdOpened?: any; | ||
onAdClosed?: any; | ||
simulatorId?: string | "SIMULATOR"; | ||
}; | ||
declare const AdmobBanner: FC<AdmobBannerTypes>; | ||
export default AdmobBanner; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import React, { useEffect, useRef, useState } from "react"; | ||
import { requireNativeComponent, UIManager, findNodeHandle, } from "react-native"; | ||
import { createErrorFromErrorData } from "./utils"; | ||
const AdmobBanner = ({ style, onSizeChange, onAdFailedToLoad, ...res }) => { | ||
const _bannerView = useRef(null); | ||
const [custonStyle, setCustomStyle] = useState({}); | ||
useEffect(() => { | ||
loadBanner(); | ||
}); | ||
const loadBanner = () => { | ||
UIManager.dispatchViewManagerCommand(findNodeHandle(_bannerView), UIManager.getViewManagerConfig("RNGADBannerView").Commands | ||
.loadBanner, undefined); | ||
}; | ||
const handleSizeChange = (event) => { | ||
const { height, width } = event.nativeEvent; | ||
setCustomStyle({ width, height }); | ||
if (onSizeChange) { | ||
onSizeChange({ width, height }); | ||
} | ||
}; | ||
const handleAdFailedToLoad = (event) => { | ||
if (onAdFailedToLoad) { | ||
onAdFailedToLoad(createErrorFromErrorData(event.nativeEvent.error)); | ||
} | ||
}; | ||
return (React.createElement(RNGADBannerView, { ...res, style: [style, custonStyle], onSizeChange: handleSizeChange, onAdFailedToLoad: handleAdFailedToLoad, ref: _bannerView })); | ||
}; | ||
AdmobBanner.simulatorId = "SIMULATOR"; | ||
const RNGADBannerView = requireNativeComponent("RNGADBannerView"); | ||
export default AdmobBanner; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import AdMobBanner from "./AdmobBanner"; | ||
import AdMobInterstitial from "./AdMobInterstitial"; | ||
import AdMobRewarded from "./AdMobRewarded"; | ||
import AdSize from "./AdSize"; | ||
import AdTestIds from "./AdTestIds"; | ||
export { AdMobBanner, AdMobInterstitial, AdMobRewarded, AdTestIds, AdSize }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import AdMobBanner from "./AdmobBanner"; | ||
import AdMobInterstitial from "./AdMobInterstitial"; | ||
import AdMobRewarded from "./AdMobRewarded"; | ||
import AdSize from "./AdSize"; | ||
import AdTestIds from "./AdTestIds"; | ||
export { AdMobBanner, AdMobInterstitial, AdMobRewarded, AdTestIds, AdSize }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export declare const createErrorFromErrorData: (errorData: any) => any; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export const createErrorFromErrorData = (errorData) => { | ||
const { message, ...extraErrorInfo } = errorData || {}; | ||
const error = new Error(message); | ||
error.framesToPop = 1; | ||
return Object.assign(error, extraErrorInfo); | ||
}; |
Oops, something went wrong.