react-native-applovin-max 5.7.2 → 6.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/README.md +1 -1
  2. package/android/build.gradle +2 -2
  3. package/android/src/main/java/com/applovin/mediation/adapters/GoogleAdManagerMediationAdapter.java.saved +1616 -0
  4. package/android/src/main/java/com/applovin/mediation/adapters/{GoogleMediationAdapter.java.saved → GoogleMediationAdapter.java.old} +126 -49
  5. package/android/src/main/java/com/applovin/mediation/adapters/MintegralMediationAdapter.java.old +1481 -0
  6. package/ios/AppLovinMAX.m +1 -9
  7. package/ios/AppLovinMAX.xcodeproj/project.pbxproj +4 -4
  8. package/ios/AppLovinMAX.xcworkspace/xcuserdata/hiroshi.watanabe.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
  9. package/ios/AppLovinMAXNativeAdView.m +8 -1
  10. package/ios/Podfile +2 -2
  11. package/ios/Podfile.lock +5 -5
  12. package/package.json +2 -1
  13. package/react-native-applovin-max.podspec +2 -2
  14. package/src/AdView.tsx +251 -0
  15. package/src/AppLovinMAX.ts +24 -0
  16. package/src/AppOpenAd.ts +128 -0
  17. package/src/BannerAd.ts +175 -0
  18. package/src/EventEmitter.ts +27 -0
  19. package/src/InterstitialAd.ts +128 -0
  20. package/src/MRecAd.ts +147 -0
  21. package/src/Privacy.ts +6 -0
  22. package/src/RewardedAd.ts +144 -0
  23. package/src/TargetingData.ts +214 -0
  24. package/src/index.ts +21 -0
  25. package/src/nativeAd/NativeAdView.tsx +162 -0
  26. package/src/nativeAd/NativeAdViewComponents.tsx +185 -0
  27. package/src/nativeAd/NativeAdViewProvider.tsx +35 -0
  28. package/src/types/AdEvent.ts +26 -0
  29. package/src/types/AdInfo.ts +348 -0
  30. package/src/types/AdProps.ts +60 -0
  31. package/src/types/AdViewProps.ts +36 -0
  32. package/src/types/AppLovinMAX.ts +87 -0
  33. package/src/types/AppOpenAd.ts +3 -0
  34. package/src/types/BannerAd.ts +47 -0
  35. package/src/types/Configuration.ts +11 -0
  36. package/src/types/FullscreenAd.ts +141 -0
  37. package/src/types/InterstitialAd.ts +3 -0
  38. package/src/types/MRecAd.ts +13 -0
  39. package/src/types/NativeAd.ts +50 -0
  40. package/src/types/NativeAdViewProps.ts +17 -0
  41. package/src/types/Privacy.ts +74 -0
  42. package/src/types/RewardedAd.ts +20 -0
  43. package/src/types/TargetingData.ts +51 -0
  44. package/src/types/ViewAd.ts +162 -0
  45. package/src/types/index.ts +4 -0
  46. package/src/AppLovinMAXAdView.js +0 -231
  47. package/src/AppLovinMAXEventListeners.js +0 -419
  48. package/src/NativeAdComponents.js +0 -208
  49. package/src/NativeAdView.js +0 -164
  50. package/src/NativeAdViewProvider.js +0 -19
  51. package/src/TargetingData.js +0 -104
  52. package/src/index.js +0 -291
@@ -0,0 +1,214 @@
1
+ import { NativeModules } from "react-native";
2
+ import type { TargetingDataType } from "./types/TargetingData";
3
+
4
+ const { AppLovinMAX } = NativeModules;
5
+
6
+ type NativeTargetingDataType = {
7
+ setTargetingDataYearOfBirth(value: number): void;
8
+ getTargetingDataYearOfBirth(): Promise<number>;
9
+ setTargetingDataGender(value: string): void;
10
+ getTargetingDataGender(): Promise<string>;
11
+ setTargetingDataMaximumAdContentRating(value: number): void;
12
+ getTargetingDataMaximumAdContentRating(): Promise<number>;
13
+ setTargetingDataEmail(value: string | null): void;
14
+ getTargetingDataEmail(): Promise<string | null>;
15
+ setTargetingDataPhoneNumber(value: string | null): void;
16
+ getTargetingDataPhoneNumber(): Promise<string | null>;
17
+ setTargetingDataKeywords(value: string[] | null): void;
18
+ getTargetingDataKeywords(): Promise<string[] | null>;
19
+ setTargetingDataInterests(value: string[] | null): void;
20
+ getTargetingDataInterests(): Promise<string[] | null>;
21
+ clearAllTargetingData(): void;
22
+ };
23
+
24
+ const nativeMethods: NativeTargetingDataType = AppLovinMAX;
25
+
26
+ /**
27
+ * This enumeration represents content ratings for the ads shown to users.
28
+ */
29
+ export enum AdContentRating {
30
+ None = 0,
31
+ AllAudiences = 1,
32
+ EveryoneOverTwelve = 2,
33
+ MatureAudiences = 3,
34
+ }
35
+
36
+ /**
37
+ * This enumeration represents gender.
38
+ */
39
+ export enum UserGender {
40
+ Unknown = 'U',
41
+ Female = 'F',
42
+ Male = 'M',
43
+ Other = 'O',
44
+ }
45
+
46
+ /**
47
+ * Defines additional data for the publisher to send to AppLovin.
48
+ *
49
+ * @see {@link https://support.applovin.com/hc/en-us/articles/13964925614733-Data-and-Keyword-Passing}
50
+ */
51
+ export const TargetingData: TargetingDataType = {
52
+
53
+ /**
54
+ * Sets the year of birth of the user. Set this to 0 to clear this value.
55
+ */
56
+ set yearOfBirth(value: number | Promise<number>) {
57
+ if (typeof value === 'number') {
58
+ nativeMethods.setTargetingDataYearOfBirth(value);
59
+ } else {
60
+ printError("TargetingData.yearOfBirth", "number", typeof value);
61
+ }
62
+ },
63
+
64
+ /**
65
+ * Gets the year of birth of the user.
66
+ */
67
+ get yearOfBirth(): number | Promise<number> {
68
+ return nativeMethods.getTargetingDataYearOfBirth();
69
+ },
70
+
71
+ /**
72
+ * Sets the gender of the user. Set this to {@link UserGender.Unknown} to clear this value.
73
+ */
74
+ set gender(value: UserGender | Promise<UserGender>) {
75
+ if (value === UserGender.Unknown ||
76
+ value === UserGender.Female ||
77
+ value === UserGender.Male ||
78
+ value === UserGender.Other) {
79
+ nativeMethods.setTargetingDataGender(value);
80
+ } else {
81
+ printError("TargetingData.gender", "UserGender", typeof value);
82
+ }
83
+ },
84
+
85
+ /**
86
+ * Gets the gender of the user.
87
+ */
88
+ get gender(): UserGender | Promise<UserGender> {
89
+ return nativeMethods.getTargetingDataGender().then((value: string) => {
90
+ return value as UserGender;
91
+ });
92
+ },
93
+
94
+ /**
95
+ * Sets the maximum ad content rating shown to the user. The levels are based on IQG Media
96
+ * Ratings: 1=All Audiences, 2=Everyone Over 12, 3=Mature Audiences.
97
+ * Set this to {@link AdContentRating.None} to clear this value.
98
+ */
99
+ set maximumAdContentRating(value: AdContentRating | Promise<AdContentRating>) {
100
+ if (value === AdContentRating.None ||
101
+ value === AdContentRating.AllAudiences ||
102
+ value === AdContentRating.EveryoneOverTwelve ||
103
+ value === AdContentRating.MatureAudiences) {
104
+ nativeMethods.setTargetingDataMaximumAdContentRating(value);
105
+ } else {
106
+ printError("TargetingData.maximumAdContentRating", "AdContentRating", typeof value);
107
+ }
108
+ },
109
+
110
+ /**
111
+ * Gets the maximum ad content rating shown to the user. The levels are based on IQG Media
112
+ * Ratings: 1=All Audiences, 2=Everyone Over 12, 3=Mature Audiences.
113
+ */
114
+ get maximumAdContentRating(): AdContentRating | Promise<AdContentRating> {
115
+ return nativeMethods.getTargetingDataMaximumAdContentRating().then((value: number) => {
116
+ return value as AdContentRating;
117
+ });
118
+ },
119
+
120
+ /**
121
+ * Sets the email of the user. Set this to null to clear this value.
122
+ */
123
+ set email(value: string | null | Promise<string | null>) {
124
+ if (value === null) {
125
+ nativeMethods.setTargetingDataEmail(null);
126
+ } else if (typeof value === 'string') {
127
+ nativeMethods.setTargetingDataEmail(value as string);
128
+ } else {
129
+ printError("TargetingData.email", "string or null", typeof value);
130
+ }
131
+ },
132
+
133
+ /**
134
+ * Gets the email of the user.
135
+ */
136
+ get email(): string | null | Promise<string | null> {
137
+ return nativeMethods.getTargetingDataEmail();
138
+ },
139
+
140
+ /**
141
+ * Sets the phone number of the user. Set this to null to clear this value.
142
+ */
143
+ set phoneNumber(value: string | null | Promise<string | null>) {
144
+ if (value === null) {
145
+ nativeMethods.setTargetingDataPhoneNumber(null);
146
+ } else if ( typeof value === 'string') {
147
+ nativeMethods.setTargetingDataPhoneNumber(value as string);
148
+ } else {
149
+ printError("TargetingData.phoneNumber", "string or null", typeof value);
150
+ }
151
+ },
152
+
153
+ /**
154
+ * Gets the phone number of the user.
155
+ */
156
+ get phoneNumber(): string | null | Promise<string | null> {
157
+ return nativeMethods.getTargetingDataPhoneNumber();
158
+ },
159
+
160
+ /**
161
+ * Sets the keywords describing the application. Set this to null to clear this value.
162
+ */
163
+ set keywords(value: string[] | null | Promise<string[]> | null) {
164
+ if (value === null) {
165
+ nativeMethods.setTargetingDataKeywords(null);
166
+ } else if (isStringArray(value)) {
167
+ nativeMethods.setTargetingDataKeywords(value as string[]);
168
+ } else {
169
+ printError("TargetingData.keywords", "string[] or null", typeof value);
170
+ }
171
+ },
172
+
173
+ /**
174
+ * Gets the keywords describing the application.
175
+ */
176
+ get keywords(): string[] | null | Promise<string[] | null> {
177
+ return nativeMethods.getTargetingDataKeywords();
178
+ },
179
+
180
+ /**
181
+ * Sets the interests of the user. Set this to null to clear this value.
182
+ */
183
+ set interests(value: string[] | null | Promise<string[] | null>) {
184
+ if (value === null) {
185
+ nativeMethods.setTargetingDataInterests(null);
186
+ } else if (isStringArray(value)) {
187
+ nativeMethods.setTargetingDataInterests(value as string[]);
188
+ } else {
189
+ printError("TargetingData.interests", "string[] or null", typeof value);
190
+ }
191
+ },
192
+
193
+ /**
194
+ * Gets the interests of the user.
195
+ */
196
+ get interests(): string[] | null | Promise<string[] | null> {
197
+ return nativeMethods.getTargetingDataInterests();
198
+ },
199
+
200
+ /**
201
+ * Clears all saved data from this class.
202
+ */
203
+ clearAll(): void {
204
+ nativeMethods.clearAllTargetingData();
205
+ },
206
+ }
207
+
208
+ const isStringArray = (strs: any): boolean => {
209
+ return Array.isArray(strs) && strs.every((value) => typeof value === 'string')
210
+ }
211
+
212
+ const printError = (fieldName: string, correctType: string, wrongType: string) => {
213
+ console.error("Cannot set value to " + fieldName + " with unsupported type: " + wrongType + ". Value has to be of type " + correctType + ".");
214
+ }
package/src/index.ts ADDED
@@ -0,0 +1,21 @@
1
+ export { default, AppLovinMAX } from "./AppLovinMAX";
2
+ export { Privacy } from "./Privacy";
3
+ export { TargetingData, AdContentRating, UserGender } from "./TargetingData";
4
+ export { InterstitialAd } from "./InterstitialAd";
5
+ export { RewardedAd } from "./RewardedAd";
6
+ export { AppOpenAd } from "./AppOpenAd";
7
+ export { BannerAd } from "./BannerAd";
8
+ export { MRecAd } from "./MRecAd";
9
+ export { AdView, AdFormat, AdViewPosition } from "./AdView";
10
+ export { NativeAdView } from "./nativeAd/NativeAdView";
11
+ export {
12
+ TitleView,
13
+ AdvertiserView,
14
+ BodyView,
15
+ CallToActionView,
16
+ IconView,
17
+ OptionsView,
18
+ MediaView,
19
+ StarRatingView,
20
+ } from "./nativeAd/NativeAdViewComponents";
21
+ export * from "./types";
@@ -0,0 +1,162 @@
1
+ import React, { forwardRef, useContext, useImperativeHandle, useRef, useState, useEffect, useCallback } from "react";
2
+ import { NativeModules, requireNativeComponent, UIManager, findNodeHandle } from "react-native";
3
+ import type { ViewProps } from "react-native";
4
+ import { NativeAdViewContext, NativeAdViewProvider } from "./NativeAdViewProvider";
5
+ import type { AdInfo, AdLoadFailedInfo, AdRevenueInfo } from "../types/AdInfo";
6
+ import type { AdNativeEvent } from "../types/AdEvent";
7
+ import type { NativeAd } from "../types/NativeAd";
8
+ import type { NativeAdViewHandler, NativeAdViewProps } from "../types/NativeAdViewProps";
9
+ import type { NativeAdViewType, NativeAdViewContextType } from "./NativeAdViewProvider";
10
+
11
+ const { AppLovinMAX } = NativeModules;
12
+
13
+ type NativeAdViewNativeEvents = {
14
+ onAdLoadedEvent(event: { nativeEvent: { nativeAd: NativeAd; adInfo: AdInfo; } }): void
15
+ onAdLoadFailedEvent(event: AdNativeEvent<AdLoadFailedInfo>): void
16
+ onAdClickedEvent(event: AdNativeEvent<AdInfo>): void
17
+ onAdRevenuePaidEvent(event: AdNativeEvent<AdRevenueInfo>): void
18
+ };
19
+
20
+ const NativeAdViewComponent = requireNativeComponent<NativeAdViewProps & ViewProps & NativeAdViewNativeEvents>('AppLovinMAXNativeAdView');
21
+
22
+ /**
23
+ * The {@link NativeAdView} component that you use building a native ad. This loads a native ad and
24
+ * renders it with the asset views:
25
+ *
26
+ * - {@link IconView}
27
+ * - {@link TitleView}
28
+ * - {@link AdvertiserView}
29
+ * - {@link StarRatingView}
30
+ * - {@link BodyView}
31
+ * - {@link MediaView}
32
+ * - {@link CallToActionView}
33
+ *
34
+ * {@link NativeAdView} fills each asset view with the data of a native ad as soon as it loads the native
35
+ * ad, but you need to provide the layout and style of the asset views.
36
+ * {@link NativeAdView} can reload a new native ad by using the ref handler.
37
+ *
38
+ * ### Example:
39
+ * ```js
40
+ * <NativeAdView
41
+ * ref={nativeAdViewHandler}
42
+ * adUnitId={adUnitId}
43
+ * style={styles.nativead}
44
+ * onAdLoaded={(adInfo: AdInfo) => { ... }}
45
+ * >
46
+ * <View style={ ... }>
47
+ * <IconView style={styles.icon} />
48
+ * <TitleView style={styles.title} />
49
+ * <AdvertiserView style={styles.advertiser} />
50
+ * <StarRatingView style={styles.starRatingView} />
51
+ * <OptionsView style={styles.optionsView} />
52
+ * <BodyView style={styles.body} />
53
+ * <MediaView style={styles.mediaView} />
54
+ * <CallToActionView style={styles.callToAction} />
55
+ * </View>
56
+ * </NativeAdView>
57
+ * ```
58
+ */
59
+ export const NativeAdView = forwardRef<NativeAdViewHandler, NativeAdViewProps & ViewProps>((props, ref) => {
60
+ const [isInitialized, setIsInitialized] = useState<boolean>(false);
61
+
62
+ useEffect(() => {
63
+ // check that AppLovinMAX has been initialized
64
+ AppLovinMAX.isInitialized().then((result: boolean) => {
65
+ setIsInitialized(result);
66
+ if (!result) {
67
+ console.warn("ERROR: NativeAdView is mounted before the initialization of the AppLovin MAX React Native module");
68
+ }
69
+ });
70
+ }, []);
71
+
72
+ // Not ready to render NativeAdView
73
+ if (!isInitialized) {
74
+ return null;
75
+ }
76
+
77
+ return (
78
+ <NativeAdViewProvider>
79
+ <NativeAdViewImpl {...props} ref={ref} />
80
+ </NativeAdViewProvider>
81
+ );
82
+ });
83
+
84
+ const NativeAdViewImpl = forwardRef<NativeAdViewHandler, NativeAdViewProps & ViewProps>(({
85
+ adUnitId,
86
+ placement,
87
+ customData,
88
+ extraParameters,
89
+ localExtraParameters,
90
+ onAdLoaded,
91
+ onAdLoadFailed,
92
+ onAdClicked,
93
+ onAdRevenuePaid,
94
+ children,
95
+ style,
96
+ ...otherProps
97
+ }, ref) => {
98
+
99
+ // context from NativeAdViewProvider
100
+ const { setNativeAd, setNativeAdView } = useContext(NativeAdViewContext) as NativeAdViewContextType;
101
+
102
+ // keep the nativeAdView ref
103
+ const nativeAdViewRef = useRef<NativeAdViewType | null>(null);
104
+
105
+ // invoke the native ad loader
106
+ const loadAd = () => {
107
+ if (nativeAdViewRef) {
108
+ UIManager.dispatchViewManagerCommand(
109
+ findNodeHandle(nativeAdViewRef.current),
110
+ UIManager.getViewManagerConfig("AppLovinMAXNativeAdView").Commands.loadAd,
111
+ undefined
112
+ );
113
+ }
114
+ };
115
+
116
+ // expose a list of functions via the provided ref
117
+ useImperativeHandle(ref, () => ({ loadAd }), []);
118
+
119
+ // save the DOM element via the ref callback
120
+ const saveElement = useCallback((element: NativeAdViewType | null) => {
121
+ if (element) {
122
+ nativeAdViewRef.current = element;
123
+ setNativeAdView(element);
124
+ }
125
+ }, []);
126
+
127
+ const onAdLoadedEvent = (event: { nativeEvent: { nativeAd: NativeAd; adInfo: AdInfo; } }) => {
128
+ setNativeAd(event.nativeEvent.nativeAd);
129
+ if (onAdLoaded) onAdLoaded(event.nativeEvent.adInfo);
130
+ };
131
+
132
+ const onAdLoadFailedEvent = (event: AdNativeEvent<AdLoadFailedInfo>) => {
133
+ if (onAdLoadFailed) onAdLoadFailed(event.nativeEvent);
134
+ };
135
+
136
+ const onAdClickedEvent = (event: AdNativeEvent<AdInfo>) => {
137
+ if (onAdClicked) onAdClicked(event.nativeEvent);
138
+ };
139
+
140
+ const onAdRevenuePaidEvent = (event: AdNativeEvent<AdRevenueInfo>) => {
141
+ if (onAdRevenuePaid) onAdRevenuePaid(event.nativeEvent);
142
+ };
143
+
144
+ return (
145
+ <NativeAdViewComponent
146
+ ref={saveElement}
147
+ adUnitId={adUnitId}
148
+ placement={placement}
149
+ customData={customData}
150
+ extraParameters={extraParameters}
151
+ localExtraParameters={localExtraParameters}
152
+ onAdLoadedEvent={onAdLoadedEvent}
153
+ onAdLoadFailedEvent={onAdLoadFailedEvent}
154
+ onAdClickedEvent={onAdClickedEvent}
155
+ onAdRevenuePaidEvent={onAdRevenuePaidEvent}
156
+ style={style}
157
+ {...otherProps}
158
+ >
159
+ {children}
160
+ </NativeAdViewComponent>
161
+ );
162
+ });
@@ -0,0 +1,185 @@
1
+ import React, { useContext, useRef, useEffect, type ReactNode } from "react";
2
+ import { findNodeHandle, Text, Image, View, TouchableOpacity, StyleSheet } from "react-native";
3
+ import type { ViewProps, ImageProps, TextStyle, StyleProp } from "react-native";
4
+ import { NativeAdViewContext } from "./NativeAdViewProvider";
5
+
6
+ export const TitleView = (props: ViewProps) => {
7
+ const titleRef = useRef(null);
8
+ const { nativeAd, nativeAdView } = useContext(NativeAdViewContext);
9
+
10
+ useEffect(() => {
11
+ if (!nativeAd.title || !titleRef.current) return;
12
+
13
+ nativeAdView?.setNativeProps({
14
+ titleView: findNodeHandle(titleRef.current),
15
+ });
16
+ }, [nativeAd]);
17
+
18
+ return (
19
+ <Text {...props} ref={titleRef}>
20
+ {nativeAd.title || null}
21
+ </Text>
22
+ );
23
+ };
24
+
25
+ export const AdvertiserView = (props: ViewProps) => {
26
+ const advertiserRef = useRef(null);
27
+ const { nativeAd, nativeAdView } = useContext(NativeAdViewContext);
28
+
29
+ useEffect(() => {
30
+ if (!nativeAd.advertiser || !advertiserRef.current) return;
31
+
32
+ nativeAdView?.setNativeProps({
33
+ advertiserView: findNodeHandle(advertiserRef.current),
34
+ });
35
+ }, [nativeAd]);
36
+
37
+ return (
38
+ <Text {...props} ref={advertiserRef}>
39
+ {nativeAd.advertiser || null}
40
+ </Text>
41
+ );
42
+ };
43
+
44
+ export const BodyView = (props: ViewProps) => {
45
+ const bodyRef = useRef(null);
46
+ const { nativeAd, nativeAdView } = useContext(NativeAdViewContext);
47
+
48
+ useEffect(() => {
49
+ if (!nativeAd.body || !bodyRef.current) return;
50
+
51
+ nativeAdView?.setNativeProps({
52
+ bodyView: findNodeHandle(bodyRef.current),
53
+ });
54
+ }, [nativeAd]);
55
+
56
+ return (
57
+ <Text {...props} ref={bodyRef}>
58
+ {nativeAd.body || null}
59
+ </Text>
60
+ );
61
+ };
62
+
63
+ export const CallToActionView = (props: ViewProps) => {
64
+ const callToActionRef = useRef(null);
65
+ const { nativeAd, nativeAdView } = useContext(NativeAdViewContext);
66
+
67
+ useEffect(() => {
68
+ if (!nativeAd.callToAction || !callToActionRef.current) return;
69
+
70
+ nativeAdView?.setNativeProps({
71
+ callToActionView: findNodeHandle(callToActionRef.current),
72
+ });
73
+ }, [nativeAd]);
74
+
75
+ return (
76
+ <TouchableOpacity {...props}>
77
+ <Text {...props} ref={callToActionRef}>
78
+ {nativeAd.callToAction || null}
79
+ </Text>
80
+ </TouchableOpacity>
81
+ );
82
+ };
83
+
84
+ export const IconView = (props: Omit<ImageProps, | 'source'>) => {
85
+ const imageRef = useRef(null);
86
+ const { nativeAd, nativeAdView } = useContext(NativeAdViewContext);
87
+
88
+ useEffect(() => {
89
+ if (!nativeAd.image || !imageRef.current) return;
90
+
91
+ nativeAdView?.setNativeProps({
92
+ iconView: findNodeHandle(imageRef.current),
93
+ });
94
+ }, [nativeAd]);
95
+
96
+ return (
97
+ nativeAd.url ? <Image {...props} source={{ uri: nativeAd.url }} /> :
98
+ nativeAd.image ? <Image {...props} ref={imageRef} source={0} /> :
99
+ <View {...props} />
100
+ );
101
+ };
102
+
103
+ export const OptionsView = (props: ViewProps) => {
104
+ const viewRef = useRef(null);
105
+ const { nativeAd, nativeAdView } = useContext(NativeAdViewContext);
106
+
107
+ useEffect(() => {
108
+ if (!nativeAd.isOptionsViewAvailable || !viewRef.current) return;
109
+ nativeAdView?.setNativeProps({
110
+ optionsView: findNodeHandle(viewRef.current),
111
+ });
112
+ }, [nativeAd]);
113
+
114
+ return (
115
+ <View {...props} ref={viewRef} />
116
+ );
117
+ };
118
+
119
+ export const MediaView = (props: ViewProps) => {
120
+ const viewRef = useRef(null);
121
+ const { nativeAd, nativeAdView } = useContext(NativeAdViewContext);
122
+
123
+ useEffect(() => {
124
+ if (!nativeAd.isMediaViewAvailable || !viewRef.current) return;
125
+
126
+ nativeAdView?.setNativeProps({
127
+ mediaView: findNodeHandle(viewRef.current),
128
+ });
129
+ }, [nativeAd]);
130
+
131
+ return (
132
+ <View {...props} ref={viewRef} />
133
+ );
134
+ };
135
+
136
+ export const StarRatingView = (props: ViewProps) => {
137
+ const { style, ...restProps } = props;
138
+
139
+ const maxStarCount = 5;
140
+ const starColor = StyleSheet.flatten(style as StyleProp<TextStyle> || {}).color ?? "#ffe234";
141
+ const starSize = StyleSheet.flatten(style as StyleProp<TextStyle> || {}).fontSize ?? 10;
142
+
143
+ const { nativeAd } = useContext(NativeAdViewContext);
144
+
145
+ const FilledStar = () => {
146
+ return (
147
+ // black star in unicode
148
+ <Text style={{ fontSize: starSize, color: starColor }}>{String.fromCodePoint(0x2605)}</Text>
149
+ );
150
+ };
151
+
152
+ const EmptyStar = () => {
153
+ return (
154
+ // white star in unicode
155
+ <Text style={{ fontSize: starSize, color: starColor }}>{String.fromCodePoint(0x2606)}</Text>
156
+ );
157
+ };
158
+
159
+ return (
160
+ <View {...restProps} style={[style, { flexDirection: 'row', alignItems: 'center' }]}>
161
+ {(() => {
162
+ let stars: ReactNode[] = [];
163
+ for (let index = 0; index < maxStarCount; index++) {
164
+ if (nativeAd.starRating) {
165
+ const width = (nativeAd.starRating - index) * starSize;
166
+ stars.push(
167
+ <View key={index}>
168
+ <EmptyStar />
169
+ {
170
+ (nativeAd.starRating > index) &&
171
+ <View style={{ width: width, overflow: 'hidden', position: 'absolute' }}>
172
+ <FilledStar />
173
+ </View>
174
+ }
175
+ </View>
176
+ );
177
+ } else {
178
+ stars.push(<Text key={index} style={{ fontSize: starSize }}> </Text>);
179
+ }
180
+ }
181
+ return stars;
182
+ })()}
183
+ </View>
184
+ );
185
+ };
@@ -0,0 +1,35 @@
1
+ import React, { useState, createContext } from "react";
2
+ import type { NativeMethods } from "react-native";
3
+ import type { NativeAd } from "../types/NativeAd";
4
+ import type { NativeAdViewProps } from "../types/NativeAdViewProps";
5
+
6
+ export type NativeAdViewType = React.Component<NativeAdViewProps> & NativeMethods;
7
+
8
+ export type NativeAdViewContextType = {
9
+ nativeAd: NativeAd;
10
+ nativeAdView: NativeAdViewType | null;
11
+ setNativeAd: React.Dispatch<React.SetStateAction<NativeAd>>;
12
+ setNativeAdView: React.Dispatch<React.SetStateAction<NativeAdViewType>>;
13
+ };
14
+
15
+ export const NativeAdViewContext = createContext<NativeAdViewContextType>({
16
+ nativeAd: { isOptionsViewAvailable: false, isMediaViewAvailable: false },
17
+ nativeAdView: null,
18
+ setNativeAd: () => { },
19
+ setNativeAdView: () => { }
20
+ });
21
+
22
+ export const NativeAdViewProvider: React.FC<{ children: React.ReactNode }> = (props) => {
23
+ const [nativeAd, setNativeAd] = useState({ isOptionsViewAvailable: false, isMediaViewAvailable: false });
24
+ const [nativeAdView, setNativeAdView] = useState(Object);
25
+
26
+ const providerValue = {
27
+ nativeAd, nativeAdView, setNativeAd, setNativeAdView,
28
+ };
29
+
30
+ return (
31
+ <NativeAdViewContext.Provider value={providerValue}>
32
+ {props.children}
33
+ </NativeAdViewContext.Provider>
34
+ );
35
+ };
@@ -0,0 +1,26 @@
1
+ import type {
2
+ AdInfo,
3
+ AdLoadFailedInfo,
4
+ AdDisplayFailedInfo,
5
+ AdRevenueInfo,
6
+ AdRewardInfo
7
+ } from "./AdInfo";
8
+
9
+ export type AdEventObject =
10
+ AdInfo |
11
+ AdLoadFailedInfo |
12
+ AdDisplayFailedInfo |
13
+ AdRevenueInfo |
14
+ AdRewardInfo;
15
+
16
+ /**
17
+ * Defines a generic event listener for the pragrammatic methods to receive an event from the native
18
+ * module.
19
+ */
20
+ export type AdEventListener<T extends AdEventObject> = (event: T) => void;
21
+
22
+ /**
23
+ * Defines a generic event object for the UI components i.e. AdView and NativeAdView to receive an
24
+ * event from the native module.
25
+ */
26
+ export type AdNativeEvent<T extends AdEventObject> = { nativeEvent: T };