react-native-applovin-max 8.0.0 → 8.0.2

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 (71) hide show
  1. package/android/build.gradle +2 -2
  2. package/android/src/main/java/com/applovin/reactnative/AppLovinMAXModule.java +71 -2
  3. package/ios/AppLovinMAX.m +38 -7
  4. package/lib/commonjs/AdView.js +86 -98
  5. package/lib/commonjs/AdView.js.map +1 -1
  6. package/lib/commonjs/AppLovinMAX.js +1 -1
  7. package/lib/commonjs/AppOpenAd.js +7 -7
  8. package/lib/commonjs/AppOpenAd.js.map +1 -1
  9. package/lib/commonjs/BannerAd.js +8 -8
  10. package/lib/commonjs/BannerAd.js.map +1 -1
  11. package/lib/commonjs/EventEmitter.js.map +1 -1
  12. package/lib/commonjs/InterstitialAd.js +7 -7
  13. package/lib/commonjs/InterstitialAd.js.map +1 -1
  14. package/lib/commonjs/MRecAd.js +6 -6
  15. package/lib/commonjs/MRecAd.js.map +1 -1
  16. package/lib/commonjs/RewardedAd.js +8 -8
  17. package/lib/commonjs/RewardedAd.js.map +1 -1
  18. package/lib/commonjs/nativeAd/NativeAdView.js +26 -29
  19. package/lib/commonjs/nativeAd/NativeAdView.js.map +1 -1
  20. package/lib/commonjs/nativeAd/NativeAdViewComponents.js +69 -102
  21. package/lib/commonjs/nativeAd/NativeAdViewComponents.js.map +1 -1
  22. package/lib/commonjs/nativeAd/NativeAdViewProvider.js +13 -13
  23. package/lib/commonjs/nativeAd/NativeAdViewProvider.js.map +1 -1
  24. package/lib/module/AdView.js +87 -99
  25. package/lib/module/AdView.js.map +1 -1
  26. package/lib/module/AppLovinMAX.js +1 -1
  27. package/lib/module/AppOpenAd.js +7 -7
  28. package/lib/module/AppOpenAd.js.map +1 -1
  29. package/lib/module/BannerAd.js +8 -8
  30. package/lib/module/BannerAd.js.map +1 -1
  31. package/lib/module/EventEmitter.js.map +1 -1
  32. package/lib/module/InterstitialAd.js +7 -7
  33. package/lib/module/InterstitialAd.js.map +1 -1
  34. package/lib/module/MRecAd.js +6 -6
  35. package/lib/module/MRecAd.js.map +1 -1
  36. package/lib/module/RewardedAd.js +8 -8
  37. package/lib/module/RewardedAd.js.map +1 -1
  38. package/lib/module/nativeAd/NativeAdView.js +27 -30
  39. package/lib/module/nativeAd/NativeAdView.js.map +1 -1
  40. package/lib/module/nativeAd/NativeAdViewComponents.js +71 -104
  41. package/lib/module/nativeAd/NativeAdViewComponents.js.map +1 -1
  42. package/lib/module/nativeAd/NativeAdViewProvider.js +13 -13
  43. package/lib/module/nativeAd/NativeAdViewProvider.js.map +1 -1
  44. package/lib/typescript/src/AdView.d.ts +2 -2
  45. package/lib/typescript/src/AdView.d.ts.map +1 -1
  46. package/lib/typescript/src/EventEmitter.d.ts.map +1 -1
  47. package/lib/typescript/src/nativeAd/NativeAdView.d.ts.map +1 -1
  48. package/lib/typescript/src/nativeAd/NativeAdViewComponents.d.ts.map +1 -1
  49. package/lib/typescript/src/nativeAd/NativeAdViewProvider.d.ts +3 -2
  50. package/lib/typescript/src/nativeAd/NativeAdViewProvider.d.ts.map +1 -1
  51. package/lib/typescript/src/types/AdInfo.d.ts +2 -2
  52. package/lib/typescript/src/types/NativeAd.d.ts +3 -3
  53. package/lib/typescript/src/types/NativeAd.d.ts.map +1 -1
  54. package/lib/typescript/src/types/Privacy.d.ts +0 -2
  55. package/lib/typescript/src/types/Privacy.d.ts.map +1 -1
  56. package/package.json +1 -1
  57. package/react-native-applovin-max.podspec +1 -1
  58. package/src/AdView.tsx +103 -92
  59. package/src/AppLovinMAX.ts +1 -1
  60. package/src/AppOpenAd.ts +21 -21
  61. package/src/BannerAd.ts +20 -20
  62. package/src/EventEmitter.ts +2 -2
  63. package/src/InterstitialAd.ts +21 -21
  64. package/src/MRecAd.ts +18 -18
  65. package/src/RewardedAd.ts +24 -24
  66. package/src/nativeAd/NativeAdView.tsx +41 -29
  67. package/src/nativeAd/NativeAdViewComponents.tsx +72 -98
  68. package/src/nativeAd/NativeAdViewProvider.tsx +21 -15
  69. package/src/types/AdInfo.ts +2 -2
  70. package/src/types/NativeAd.ts +3 -3
  71. package/src/types/Privacy.ts +0 -4
package/src/RewardedAd.ts CHANGED
@@ -37,69 +37,69 @@ const setLocalExtraParameter = (adUnitId: string, key: string, value: LocalExtra
37
37
  AppLovinMAX.setRewardedAdLocalExtraParameter(adUnitId, { [key]: value });
38
38
  };
39
39
 
40
- const addAdLoadedEventListener = (listener: (adInfo: AdInfo) => void) => {
41
- addEventListener(ON_REWARDED_AD_LOADED_EVENT, (adInfo: AdInfo) => listener(adInfo));
40
+ const addAdLoadedEventListener = (listener: (adInfo: AdInfo) => void): void => {
41
+ addEventListener(ON_REWARDED_AD_LOADED_EVENT, listener);
42
42
  };
43
43
 
44
- const removeAdLoadedEventListener = () => {
44
+ const removeAdLoadedEventListener = (): void => {
45
45
  removeEventListener(ON_REWARDED_AD_LOADED_EVENT);
46
46
  };
47
47
 
48
- const addAdLoadFailedEventListener = (listener: (errorInfo: AdLoadFailedInfo) => void) => {
49
- addEventListener(ON_REWARDED_AD_LOAD_FAILED_EVENT, (errorInfo: AdLoadFailedInfo) => listener(errorInfo));
48
+ const addAdLoadFailedEventListener = (listener: (errorInfo: AdLoadFailedInfo) => void): void => {
49
+ addEventListener(ON_REWARDED_AD_LOAD_FAILED_EVENT, listener);
50
50
  };
51
51
 
52
- const removeAdLoadFailedEventListener = () => {
52
+ const removeAdLoadFailedEventListener = (): void => {
53
53
  removeEventListener(ON_REWARDED_AD_LOAD_FAILED_EVENT);
54
54
  };
55
55
 
56
- const addAdClickedEventListener = (listener: (adInfo: AdInfo) => void) => {
57
- addEventListener(ON_REWARDED_AD_CLICKED_EVENT, (adInfo: AdInfo) => listener(adInfo));
56
+ const addAdClickedEventListener = (listener: (adInfo: AdInfo) => void): void => {
57
+ addEventListener(ON_REWARDED_AD_CLICKED_EVENT, listener);
58
58
  };
59
59
 
60
- const removeAdClickedEventListener = () => {
60
+ const removeAdClickedEventListener = (): void => {
61
61
  removeEventListener(ON_REWARDED_AD_CLICKED_EVENT);
62
62
  };
63
63
 
64
- const addAdDisplayedEventListener = (listener: (adInfo: AdInfo) => void) => {
65
- addEventListener(ON_REWARDED_AD_DISPLAYED_EVENT, (adInfo: AdInfo) => listener(adInfo));
64
+ const addAdDisplayedEventListener = (listener: (adInfo: AdInfo) => void): void => {
65
+ addEventListener(ON_REWARDED_AD_DISPLAYED_EVENT, listener);
66
66
  };
67
67
 
68
- const removeAdDisplayedEventListener = () => {
68
+ const removeAdDisplayedEventListener = (): void => {
69
69
  removeEventListener(ON_REWARDED_AD_DISPLAYED_EVENT);
70
70
  };
71
71
 
72
- const addAdFailedToDisplayEventListener = (listener: (errorInfo: AdDisplayFailedInfo) => void) => {
73
- addEventListener(ON_REWARDED_AD_FAILED_TO_DISPLAY_EVENT, (errorInfo: AdDisplayFailedInfo) => listener(errorInfo));
72
+ const addAdFailedToDisplayEventListener = (listener: (errorInfo: AdDisplayFailedInfo) => void): void => {
73
+ addEventListener(ON_REWARDED_AD_FAILED_TO_DISPLAY_EVENT, listener);
74
74
  };
75
75
 
76
- const removeAdFailedToDisplayEventListener = () => {
76
+ const removeAdFailedToDisplayEventListener = (): void => {
77
77
  removeEventListener(ON_REWARDED_AD_FAILED_TO_DISPLAY_EVENT);
78
78
  };
79
79
 
80
- const addAdHiddenEventListener = (listener: (adInfo: AdInfo) => void) => {
81
- addEventListener(ON_REWARDED_AD_HIDDEN_EVENT, (adInfo: AdInfo) => listener(adInfo));
80
+ const addAdHiddenEventListener = (listener: (adInfo: AdInfo) => void): void => {
81
+ addEventListener(ON_REWARDED_AD_HIDDEN_EVENT, listener);
82
82
  };
83
83
 
84
- const removeAdHiddenEventListener = () => {
84
+ const removeAdHiddenEventListener = (): void => {
85
85
  removeEventListener(ON_REWARDED_AD_HIDDEN_EVENT);
86
86
  };
87
87
 
88
- const addAdRevenuePaidListener = (listener: (adInfo: AdRevenueInfo) => void) => {
89
- addEventListener(ON_REWARDED_AD_REVENUE_PAID, (adInfo: AdRevenueInfo) => listener(adInfo));
88
+ const addAdRevenuePaidListener = (listener: (adInfo: AdRevenueInfo) => void): void => {
89
+ addEventListener(ON_REWARDED_AD_REVENUE_PAID, listener);
90
90
  };
91
91
 
92
- const removeAdRevenuePaidListener = () => {
92
+ const removeAdRevenuePaidListener = (): void => {
93
93
  removeEventListener(ON_REWARDED_AD_REVENUE_PAID);
94
94
  };
95
95
 
96
96
  // Rewarded specific APIs
97
97
 
98
- const addAdReceivedRewardEventListener = (listener: (adInfo: AdRewardInfo) => void) => {
99
- addEventListener(ON_REWARDED_AD_RECEIVED_REWARD_EVENT, (adInfo: AdRewardInfo) => listener(adInfo));
98
+ const addAdReceivedRewardEventListener = (listener: (adInfo: AdRewardInfo) => void): void => {
99
+ addEventListener(ON_REWARDED_AD_RECEIVED_REWARD_EVENT, listener);
100
100
  };
101
101
 
102
- const removeAdReceivedRewardEventListener = () => {
102
+ const removeAdReceivedRewardEventListener = (): void => {
103
103
  removeEventListener(ON_REWARDED_AD_RECEIVED_REWARD_EVENT);
104
104
  };
105
105
 
@@ -1,6 +1,6 @@
1
1
  import * as React from 'react';
2
2
  import { forwardRef, useContext, useImperativeHandle, useRef, useState, useEffect, useCallback } from 'react';
3
- import { NativeModules, requireNativeComponent, UIManager, findNodeHandle } from 'react-native';
3
+ import { NativeModules, requireNativeComponent, UIManager, findNodeHandle, View } from 'react-native';
4
4
  import type { ViewProps } from 'react-native';
5
5
  import { NativeAdViewContext, NativeAdViewProvider } from './NativeAdViewProvider';
6
6
  import type { AdInfo, AdLoadFailedInfo, AdRevenueInfo } from '../types/AdInfo';
@@ -61,18 +61,20 @@ export const NativeAdView = forwardRef<NativeAdViewHandler, NativeAdViewProps &
61
61
  const [isInitialized, setIsInitialized] = useState<boolean>(false);
62
62
 
63
63
  useEffect(() => {
64
- // check that AppLovinMAX has been initialized
65
- AppLovinMAX.isInitialized().then((result: boolean) => {
64
+ const checkInitialization = async () => {
65
+ const result = await AppLovinMAX.isInitialized();
66
66
  setIsInitialized(result);
67
67
  if (!result) {
68
- console.warn('NativeAdView is mounted before the initialization of the AppLovin MAX React Native module');
68
+ console.warn('NativeAdView is mounted before the initialization of the AppLovin MAX React Native module.');
69
69
  }
70
- });
70
+ };
71
+
72
+ checkInitialization();
71
73
  }, []);
72
74
 
73
- // Not ready to render NativeAdView
75
+ // Avoid rendering the NativeAdView if the SDK is not initialized
74
76
  if (!isInitialized) {
75
- return null;
77
+ return <View {...props} />;
76
78
  }
77
79
 
78
80
  return (
@@ -86,15 +88,14 @@ const NativeAdViewImpl = forwardRef<NativeAdViewHandler, NativeAdViewProps & Vie
86
88
  { adUnitId, placement, customData, extraParameters, localExtraParameters, onAdLoaded, onAdLoadFailed, onAdClicked, onAdRevenuePaid, children, style, ...otherProps },
87
89
  ref
88
90
  ) {
89
- // context from NativeAdViewProvider
91
+ // Context provides functions to manage native ad and native ad view state
90
92
  const { setNativeAd, setNativeAdView } = useContext(NativeAdViewContext) as NativeAdViewContextType;
91
93
 
92
- // keep the nativeAdView ref
93
94
  const nativeAdViewRef = useRef<NativeAdViewType | null>(null);
94
95
 
95
- // invoke the native ad loader
96
- const loadAd = () => {
97
- if (nativeAdViewRef) {
96
+ // Load a new ad
97
+ const loadAd = useCallback(() => {
98
+ if (nativeAdViewRef.current) {
98
99
  UIManager.dispatchViewManagerCommand(
99
100
  findNodeHandle(nativeAdViewRef.current),
100
101
  // @ts-ignore: Issue in RN ts defs
@@ -102,12 +103,11 @@ const NativeAdViewImpl = forwardRef<NativeAdViewHandler, NativeAdViewProps & Vie
102
103
  undefined
103
104
  );
104
105
  }
105
- };
106
+ }, []);
106
107
 
107
- // expose a list of functions via the provided ref
108
- useImperativeHandle(ref, () => ({ loadAd }), []);
108
+ useImperativeHandle(ref, () => ({ loadAd }), [loadAd]);
109
109
 
110
- // save the DOM element via the ref callback
110
+ // Save the DOM element reference
111
111
  const saveElement = useCallback(
112
112
  (element: NativeAdViewType | null) => {
113
113
  if (element) {
@@ -118,22 +118,34 @@ const NativeAdViewImpl = forwardRef<NativeAdViewHandler, NativeAdViewProps & Vie
118
118
  [setNativeAdView]
119
119
  );
120
120
 
121
- const onAdLoadedEvent = (event: { nativeEvent: { nativeAd: NativeAd; adInfo: AdInfo } }) => {
122
- setNativeAd(event.nativeEvent.nativeAd);
123
- if (onAdLoaded) onAdLoaded(event.nativeEvent.adInfo);
124
- };
121
+ const onAdLoadedEvent = useCallback(
122
+ (event: { nativeEvent: { nativeAd: NativeAd; adInfo: AdInfo } }) => {
123
+ setNativeAd(event.nativeEvent.nativeAd);
124
+ onAdLoaded?.(event.nativeEvent.adInfo);
125
+ },
126
+ [onAdLoaded, setNativeAd]
127
+ );
125
128
 
126
- const onAdLoadFailedEvent = (event: AdNativeEvent<AdLoadFailedInfo>) => {
127
- if (onAdLoadFailed) onAdLoadFailed(event.nativeEvent);
128
- };
129
+ const onAdLoadFailedEvent = useCallback(
130
+ (event: AdNativeEvent<AdLoadFailedInfo>) => {
131
+ onAdLoadFailed?.(event.nativeEvent);
132
+ },
133
+ [onAdLoadFailed]
134
+ );
129
135
 
130
- const onAdClickedEvent = (event: AdNativeEvent<AdInfo>) => {
131
- if (onAdClicked) onAdClicked(event.nativeEvent);
132
- };
136
+ const onAdClickedEvent = useCallback(
137
+ (event: AdNativeEvent<AdInfo>) => {
138
+ onAdClicked?.(event.nativeEvent);
139
+ },
140
+ [onAdClicked]
141
+ );
133
142
 
134
- const onAdRevenuePaidEvent = (event: AdNativeEvent<AdRevenueInfo>) => {
135
- if (onAdRevenuePaid) onAdRevenuePaid(event.nativeEvent);
136
- };
143
+ const onAdRevenuePaidEvent = useCallback(
144
+ (event: AdNativeEvent<AdRevenueInfo>) => {
145
+ onAdRevenuePaid?.(event.nativeEvent);
146
+ },
147
+ [onAdRevenuePaid]
148
+ );
137
149
 
138
150
  return (
139
151
  <NativeAdViewComponent
@@ -1,21 +1,31 @@
1
1
  import * as React from 'react';
2
- import { useContext, useRef, useEffect } from 'react';
3
- import type { ReactNode } from 'react';
4
- import { findNodeHandle, Text, Image, View, TouchableOpacity, StyleSheet } from 'react-native';
2
+ import { useContext, useRef, useEffect, useCallback, useMemo } from 'react';
3
+ import { findNodeHandle, Text, Image, View, TouchableOpacity, StyleSheet, Platform } from 'react-native';
5
4
  import type { ViewProps, ImageProps, TextStyle, StyleProp, TextProps } from 'react-native';
6
5
  import { NativeAdViewContext } from './NativeAdViewProvider';
6
+ import type { NativeAd } from '../types/NativeAd';
7
7
 
8
- export const TitleView = (props: TextProps) => {
9
- const titleRef = useRef(null);
8
+ // Custom hook to handle setting native ad view properties and return nativeAd
9
+ const useNativeAdViewProps = (nativeAdProp: keyof NativeAd, ref: React.RefObject<any>, nativePropKey: string) => {
10
10
  const { nativeAd, nativeAdView } = useContext(NativeAdViewContext);
11
11
 
12
- useEffect(() => {
13
- if (!nativeAd.title || !titleRef.current) return;
14
-
12
+ const setNativeProps = useCallback(() => {
13
+ if (!nativeAd[nativeAdProp] || !ref.current) return;
15
14
  nativeAdView?.setNativeProps({
16
- titleView: findNodeHandle(titleRef.current),
15
+ [nativePropKey]: findNodeHandle(ref.current),
17
16
  });
18
- }, [nativeAd, nativeAdView]);
17
+ }, [nativeAd, nativeAdProp, nativeAdView, ref, nativePropKey]);
18
+
19
+ useEffect(() => {
20
+ setNativeProps();
21
+ }, [setNativeProps]);
22
+
23
+ return nativeAd;
24
+ };
25
+
26
+ export const TitleView = (props: TextProps) => {
27
+ const titleRef = useRef<Text | null>(null);
28
+ const nativeAd = useNativeAdViewProps('title', titleRef, 'titleView');
19
29
 
20
30
  return (
21
31
  <Text {...props} ref={titleRef}>
@@ -25,16 +35,8 @@ export const TitleView = (props: TextProps) => {
25
35
  };
26
36
 
27
37
  export const AdvertiserView = (props: TextProps) => {
28
- const advertiserRef = useRef(null);
29
- const { nativeAd, nativeAdView } = useContext(NativeAdViewContext);
30
-
31
- useEffect(() => {
32
- if (!nativeAd.advertiser || !advertiserRef.current) return;
33
-
34
- nativeAdView?.setNativeProps({
35
- advertiserView: findNodeHandle(advertiserRef.current),
36
- });
37
- }, [nativeAd, nativeAdView]);
38
+ const advertiserRef = useRef<Text | null>(null);
39
+ const nativeAd = useNativeAdViewProps('advertiser', advertiserRef, 'advertiserView');
38
40
 
39
41
  return (
40
42
  <Text {...props} ref={advertiserRef}>
@@ -44,16 +46,8 @@ export const AdvertiserView = (props: TextProps) => {
44
46
  };
45
47
 
46
48
  export const BodyView = (props: TextProps) => {
47
- const bodyRef = useRef(null);
48
- const { nativeAd, nativeAdView } = useContext(NativeAdViewContext);
49
-
50
- useEffect(() => {
51
- if (!nativeAd.body || !bodyRef.current) return;
52
-
53
- nativeAdView?.setNativeProps({
54
- bodyView: findNodeHandle(bodyRef.current),
55
- });
56
- }, [nativeAd, nativeAdView]);
49
+ const bodyRef = useRef<Text | null>(null);
50
+ const nativeAd = useNativeAdViewProps('body', bodyRef, 'bodyView');
57
51
 
58
52
  return (
59
53
  <Text {...props} ref={bodyRef}>
@@ -63,37 +57,30 @@ export const BodyView = (props: TextProps) => {
63
57
  };
64
58
 
65
59
  export const CallToActionView = (props: TextProps) => {
66
- const callToActionRef = useRef(null);
67
- const { nativeAd, nativeAdView } = useContext(NativeAdViewContext);
68
-
69
- useEffect(() => {
70
- if (!nativeAd.callToAction || !callToActionRef.current) return;
60
+ const callToActionRef = useRef<Text | null>(null);
61
+ const nativeAd = useNativeAdViewProps('callToAction', callToActionRef, 'callToActionView');
71
62
 
72
- nativeAdView?.setNativeProps({
73
- callToActionView: findNodeHandle(callToActionRef.current),
74
- });
75
- }, [nativeAd, nativeAdView]);
76
-
77
- return (
78
- <TouchableOpacity>
63
+ // TouchableOpacity disables clicking on certain Android devices.
64
+ if (Platform.OS === 'android') {
65
+ return (
79
66
  <Text {...props} ref={callToActionRef}>
80
67
  {nativeAd.callToAction || null}
81
68
  </Text>
82
- </TouchableOpacity>
83
- );
69
+ );
70
+ } else {
71
+ return (
72
+ <TouchableOpacity>
73
+ <Text {...props} ref={callToActionRef}>
74
+ {nativeAd.callToAction || null}
75
+ </Text>
76
+ </TouchableOpacity>
77
+ );
78
+ }
84
79
  };
85
80
 
86
81
  export const IconView = (props: Omit<ImageProps, 'source'>) => {
87
- const imageRef = useRef(null);
88
- const { nativeAd, nativeAdView } = useContext(NativeAdViewContext);
89
-
90
- useEffect(() => {
91
- if (!(nativeAd.image || nativeAd.url) || !imageRef.current) return;
92
-
93
- nativeAdView?.setNativeProps({
94
- iconView: findNodeHandle(imageRef.current),
95
- });
96
- }, [nativeAd, nativeAdView]);
82
+ const imageRef = useRef<Image | null>(null);
83
+ const nativeAd = useNativeAdViewProps('image', imageRef, 'iconView');
97
84
 
98
85
  return nativeAd.url ? (
99
86
  <Image {...props} ref={imageRef} source={{ uri: nativeAd.url }} />
@@ -105,30 +92,15 @@ export const IconView = (props: Omit<ImageProps, 'source'>) => {
105
92
  };
106
93
 
107
94
  export const OptionsView = (props: ViewProps) => {
108
- const viewRef = useRef(null);
109
- const { nativeAd, nativeAdView } = useContext(NativeAdViewContext);
110
-
111
- useEffect(() => {
112
- if (!nativeAd.isOptionsViewAvailable || !viewRef.current) return;
113
- nativeAdView?.setNativeProps({
114
- optionsView: findNodeHandle(viewRef.current),
115
- });
116
- }, [nativeAd, nativeAdView]);
95
+ const viewRef = useRef<View | null>(null);
96
+ useNativeAdViewProps('isOptionsViewAvailable', viewRef, 'optionsView');
117
97
 
118
98
  return <View {...props} ref={viewRef} />;
119
99
  };
120
100
 
121
101
  export const MediaView = (props: ViewProps) => {
122
- const viewRef = useRef(null);
123
- const { nativeAd, nativeAdView } = useContext(NativeAdViewContext);
124
-
125
- useEffect(() => {
126
- if (!nativeAd.isMediaViewAvailable || !viewRef.current) return;
127
-
128
- nativeAdView?.setNativeProps({
129
- mediaView: findNodeHandle(viewRef.current),
130
- });
131
- }, [nativeAd, nativeAdView]);
102
+ const viewRef = useRef<View | null>(null);
103
+ useNativeAdViewProps('isMediaViewAvailable', viewRef, 'mediaView');
132
104
 
133
105
  return <View {...props} ref={viewRef} />;
134
106
  };
@@ -142,33 +114,35 @@ export const StarRatingView = (props: ViewProps) => {
142
114
 
143
115
  const { nativeAd } = useContext(NativeAdViewContext);
144
116
 
117
+ // Memoize the star rendering process
118
+ const stars = useMemo(() => {
119
+ if (!nativeAd.starRating) {
120
+ return Array.from({ length: maxStarCount }).map((_, index) => (
121
+ <Text key={index} style={{ fontSize: starSize }}>
122
+ {' '}
123
+ </Text>
124
+ ));
125
+ }
126
+
127
+ return Array.from({ length: maxStarCount }).map((_, index) => {
128
+ const starRating = nativeAd.starRating!;
129
+ const width = (starRating - index) * starSize;
130
+ return (
131
+ <View key={index}>
132
+ <Text style={{ fontSize: starSize, color: starColor }}>{String.fromCodePoint(0x2606)}</Text>
133
+ {starRating > index && (
134
+ <View style={[{ width: width }, styles.starRating]}>
135
+ <Text style={{ fontSize: starSize, color: starColor }}>{String.fromCodePoint(0x2605)}</Text>
136
+ </View>
137
+ )}
138
+ </View>
139
+ );
140
+ });
141
+ }, [nativeAd.starRating, starColor, starSize]);
142
+
145
143
  return (
146
144
  <View {...restProps} style={[style, styles.starRatingContainer]}>
147
- {(() => {
148
- const stars: ReactNode[] = [];
149
- for (let index = 0; index < maxStarCount; index++) {
150
- if (nativeAd.starRating) {
151
- const width = (nativeAd.starRating - index) * starSize;
152
- stars.push(
153
- <View key={index}>
154
- <Text style={{ fontSize: starSize, color: starColor }}>{String.fromCodePoint(0x2606)}</Text>
155
- {nativeAd.starRating > index && (
156
- <View style={[{ width: width }, styles.starRating]}>
157
- <Text style={{ fontSize: starSize, color: starColor }}>{String.fromCodePoint(0x2605)}</Text>
158
- </View>
159
- )}
160
- </View>
161
- );
162
- } else {
163
- stars.push(
164
- <Text key={index} style={{ fontSize: starSize }}>
165
- {' '}
166
- </Text>
167
- );
168
- }
169
- }
170
- return stars;
171
- })()}
145
+ {stars}
172
146
  </View>
173
147
  );
174
148
  };
@@ -1,5 +1,6 @@
1
1
  import * as React from 'react';
2
2
  import { useState, createContext } from 'react';
3
+ import type { ReactNode } from 'react';
3
4
  import type { NativeMethods } from 'react-native';
4
5
  import type { NativeAd } from '../types/NativeAd';
5
6
  import type { NativeAdViewProps } from '../types/NativeAdViewProps';
@@ -10,29 +11,34 @@ export type NativeAdViewContextType = {
10
11
  nativeAd: NativeAd;
11
12
  nativeAdView: NativeAdViewType | null;
12
13
  setNativeAd: React.Dispatch<React.SetStateAction<NativeAd>>;
13
- setNativeAdView: React.Dispatch<React.SetStateAction<NativeAdViewType>>;
14
+ setNativeAdView: React.Dispatch<React.SetStateAction<NativeAdViewType | null>>;
15
+ };
16
+
17
+ const defaultNativeAd: NativeAd = {
18
+ isOptionsViewAvailable: false,
19
+ isMediaViewAvailable: false,
14
20
  };
15
21
 
16
22
  export const NativeAdViewContext = createContext<NativeAdViewContextType>({
17
- nativeAd: { isOptionsViewAvailable: false, isMediaViewAvailable: false },
23
+ nativeAd: defaultNativeAd,
18
24
  nativeAdView: null,
19
25
  setNativeAd: () => {},
20
26
  setNativeAdView: () => {},
21
27
  });
22
28
 
23
- export const NativeAdViewProvider: React.FC<{ children: React.ReactNode }> = (props) => {
24
- const [nativeAd, setNativeAd] = useState({
25
- isOptionsViewAvailable: false,
26
- isMediaViewAvailable: false,
27
- });
28
- const [nativeAdView, setNativeAdView] = useState(Object);
29
+ export const NativeAdViewProvider: React.FC<{ children: ReactNode }> = ({ children }) => {
30
+ const [nativeAd, setNativeAd] = useState<NativeAd>(defaultNativeAd);
31
+ const [nativeAdView, setNativeAdView] = useState<NativeAdViewType | null>(null);
29
32
 
30
- const providerValue = {
31
- nativeAd,
32
- nativeAdView,
33
- setNativeAd,
34
- setNativeAdView,
35
- };
33
+ const providerValue = React.useMemo(
34
+ () => ({
35
+ nativeAd,
36
+ nativeAdView,
37
+ setNativeAd,
38
+ setNativeAdView,
39
+ }),
40
+ [nativeAd, nativeAdView]
41
+ );
36
42
 
37
- return <NativeAdViewContext.Provider value={providerValue}>{props.children}</NativeAdViewContext.Provider>;
43
+ return <NativeAdViewContext.Provider value={providerValue}>{children}</NativeAdViewContext.Provider>;
38
44
  };
@@ -32,7 +32,7 @@ export type AdInfo = {
32
32
 
33
33
  /**
34
34
  * The ad’s revenue amount. In the case where no revenue amount exists, or it is not available
35
- * yet, return 0.
35
+ * yet, returns 0.
36
36
  */
37
37
  revenue: number;
38
38
 
@@ -239,7 +239,7 @@ export type AdWaterfallInfo = {
239
239
  networkResponses: AdNetworkResponseInfo[];
240
240
 
241
241
  /**
242
- * The total latency in seconds for this waterfall to finish processing.
242
+ * The total latency in milliseconds for this waterfall to finish processing.
243
243
  */
244
244
  latencyMillis: number;
245
245
  };
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Represents a native ad for rendering `NativeAdView`. Internal use only.
2
+ * Represents a native ad for rendering in {@link NativeAdView}. This type is intended for internal use only.
3
3
  */
4
4
  export type NativeAd = {
5
5
  /**
@@ -30,12 +30,12 @@ export type NativeAd = {
30
30
  /**
31
31
  * The URL string of the icon.
32
32
  */
33
- url?: string | null;
33
+ url?: string;
34
34
 
35
35
  /**
36
36
  * The star rating of the native ad.
37
37
  */
38
- starRating?: number | null;
38
+ starRating?: number;
39
39
 
40
40
  /**
41
41
  * Whether or not the Options view is available.
@@ -1,8 +1,4 @@
1
1
  export type PrivacyType = {
2
- /**********************************************************************************/
3
- /* Privacy */
4
- /**********************************************************************************/
5
-
6
2
  /**
7
3
  * Sets whether or not the user provided consent for information-sharing with AppLovin.
8
4
  *