react-native-applovin-max 9.0.0 → 9.2.0
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.
- package/android/build.gradle +3 -3
- package/android/src/main/java/com/applovin/reactnative/AppLovinMAXAdView.java +4 -10
- package/android/src/main/java/com/applovin/reactnative/AppLovinMAXAdViewUiComponent.java +17 -8
- package/android/src/main/java/com/applovin/reactnative/AppLovinMAXModuleImpl.java +36 -14
- package/android/src/newarch/com/applovin/reactnative/AppLovinMAXModule.java +6 -6
- package/android/src/oldarch/com/applovin/reactnative/AppLovinMAXModule.java +6 -6
- package/ios/AppLovinMAX.mm +36 -13
- package/ios/AppLovinMAXAdView.h +1 -0
- package/ios/AppLovinMAXAdView.mm +3 -9
- package/ios/AppLovinMAXAdViewUIComponent.h +1 -2
- package/ios/AppLovinMAXAdViewUIComponent.mm +18 -10
- package/lib/commonjs/AdView.js +63 -79
- package/lib/commonjs/AdView.js.map +1 -1
- package/lib/commonjs/AppLovinMAX.js +43 -29
- package/lib/commonjs/AppLovinMAX.js.map +1 -1
- package/lib/commonjs/BannerAd.js +2 -3
- package/lib/commonjs/BannerAd.js.map +1 -1
- package/lib/commonjs/ErrorCode.js +24 -31
- package/lib/commonjs/ErrorCode.js.map +1 -1
- package/lib/commonjs/EventEmitter.js +22 -1
- package/lib/commonjs/EventEmitter.js.map +1 -1
- package/lib/commonjs/Utils.js +22 -4
- package/lib/commonjs/Utils.js.map +1 -1
- package/lib/commonjs/index.js +1 -2
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/nativeAd/NativeAdView.js +34 -24
- package/lib/commonjs/nativeAd/NativeAdView.js.map +1 -1
- package/lib/commonjs/nativeAd/NativeAdViewComponents.js +85 -43
- package/lib/commonjs/nativeAd/NativeAdViewComponents.js.map +1 -1
- package/lib/commonjs/nativeAd/NativeAdViewProvider.js +30 -2
- package/lib/commonjs/nativeAd/NativeAdViewProvider.js.map +1 -1
- package/lib/commonjs/specs/AppLovinMAXAdViewNativeComponent.js +27 -0
- package/lib/commonjs/specs/AppLovinMAXAdViewNativeComponent.js.map +1 -1
- package/lib/commonjs/specs/AppLovinMAXNativeAdViewNativeComponent.js +23 -0
- package/lib/commonjs/specs/AppLovinMAXNativeAdViewNativeComponent.js.map +1 -1
- package/lib/commonjs/specs/NativeAppLovinMAXModule.js +7 -0
- package/lib/commonjs/specs/NativeAppLovinMAXModule.js.map +1 -1
- package/lib/commonjs/types/AdInfo.js +13 -16
- package/lib/commonjs/types/AdInfo.js.map +1 -1
- package/lib/module/AdView.js +62 -77
- package/lib/module/AdView.js.map +1 -1
- package/lib/module/AppLovinMAX.js +44 -29
- package/lib/module/AppLovinMAX.js.map +1 -1
- package/lib/module/BannerAd.js +2 -3
- package/lib/module/BannerAd.js.map +1 -1
- package/lib/module/ErrorCode.js +24 -31
- package/lib/module/ErrorCode.js.map +1 -1
- package/lib/module/EventEmitter.js +22 -1
- package/lib/module/EventEmitter.js.map +1 -1
- package/lib/module/Utils.js +22 -4
- package/lib/module/Utils.js.map +1 -1
- package/lib/module/nativeAd/NativeAdView.js +34 -21
- package/lib/module/nativeAd/NativeAdView.js.map +1 -1
- package/lib/module/nativeAd/NativeAdViewComponents.js +87 -40
- package/lib/module/nativeAd/NativeAdViewComponents.js.map +1 -1
- package/lib/module/nativeAd/NativeAdViewProvider.js +30 -0
- package/lib/module/nativeAd/NativeAdViewProvider.js.map +1 -1
- package/lib/module/specs/AppLovinMAXAdViewNativeComponent.js +28 -0
- package/lib/module/specs/AppLovinMAXAdViewNativeComponent.js.map +1 -1
- package/lib/module/specs/AppLovinMAXNativeAdViewNativeComponent.js +24 -0
- package/lib/module/specs/AppLovinMAXNativeAdViewNativeComponent.js.map +1 -1
- package/lib/module/specs/NativeAppLovinMAXModule.js +9 -0
- package/lib/module/specs/NativeAppLovinMAXModule.js.map +1 -1
- package/lib/module/types/AdInfo.js +13 -16
- package/lib/module/types/AdInfo.js.map +1 -1
- package/lib/typescript/src/AdView.d.ts +27 -21
- package/lib/typescript/src/AdView.d.ts.map +1 -1
- package/lib/typescript/src/AppLovinMAX.d.ts +22 -21
- package/lib/typescript/src/AppLovinMAX.d.ts.map +1 -1
- package/lib/typescript/src/BannerAd.d.ts.map +1 -1
- package/lib/typescript/src/ErrorCode.d.ts +24 -31
- package/lib/typescript/src/ErrorCode.d.ts.map +1 -1
- package/lib/typescript/src/EventEmitter.d.ts +16 -0
- package/lib/typescript/src/EventEmitter.d.ts.map +1 -1
- package/lib/typescript/src/Utils.d.ts +15 -0
- package/lib/typescript/src/Utils.d.ts.map +1 -1
- package/lib/typescript/src/nativeAd/NativeAdView.d.ts +15 -7
- package/lib/typescript/src/nativeAd/NativeAdView.d.ts.map +1 -1
- package/lib/typescript/src/nativeAd/NativeAdViewComponents.d.ts +65 -1
- package/lib/typescript/src/nativeAd/NativeAdViewComponents.d.ts.map +1 -1
- package/lib/typescript/src/nativeAd/NativeAdViewProvider.d.ts +17 -0
- package/lib/typescript/src/nativeAd/NativeAdViewProvider.d.ts.map +1 -1
- package/lib/typescript/src/specs/AppLovinMAXAdViewNativeComponent.d.ts +45 -1
- package/lib/typescript/src/specs/AppLovinMAXAdViewNativeComponent.d.ts.map +1 -1
- package/lib/typescript/src/specs/AppLovinMAXNativeAdViewNativeComponent.d.ts +57 -6
- package/lib/typescript/src/specs/AppLovinMAXNativeAdViewNativeComponent.d.ts.map +1 -1
- package/lib/typescript/src/specs/NativeAppLovinMAXModule.d.ts +13 -3
- package/lib/typescript/src/specs/NativeAppLovinMAXModule.d.ts.map +1 -1
- package/lib/typescript/src/types/AdEvent.d.ts +10 -4
- package/lib/typescript/src/types/AdEvent.d.ts.map +1 -1
- package/lib/typescript/src/types/AdInfo.d.ts +78 -85
- package/lib/typescript/src/types/AdInfo.d.ts.map +1 -1
- package/lib/typescript/src/types/AdProps.d.ts +14 -15
- package/lib/typescript/src/types/AdProps.d.ts.map +1 -1
- package/lib/typescript/src/types/AdViewProps.d.ts +32 -29
- package/lib/typescript/src/types/AdViewProps.d.ts.map +1 -1
- package/lib/typescript/src/types/AppLovinMAX.d.ts +50 -53
- package/lib/typescript/src/types/AppLovinMAX.d.ts.map +1 -1
- package/lib/typescript/src/types/BannerAd.d.ts +24 -18
- package/lib/typescript/src/types/BannerAd.d.ts.map +1 -1
- package/lib/typescript/src/types/CMPError.d.ts +7 -4
- package/lib/typescript/src/types/CMPError.d.ts.map +1 -1
- package/lib/typescript/src/types/Configuration.d.ts +12 -14
- package/lib/typescript/src/types/Configuration.d.ts.map +1 -1
- package/lib/typescript/src/types/FullscreenAd.d.ts +39 -46
- package/lib/typescript/src/types/FullscreenAd.d.ts.map +1 -1
- package/lib/typescript/src/types/MRecAd.d.ts +7 -3
- package/lib/typescript/src/types/MRecAd.d.ts.map +1 -1
- package/lib/typescript/src/types/NativeAd.d.ts +12 -11
- package/lib/typescript/src/types/NativeAd.d.ts.map +1 -1
- package/lib/typescript/src/types/NativeAdViewProps.d.ts +4 -3
- package/lib/typescript/src/types/NativeAdViewProps.d.ts.map +1 -1
- package/lib/typescript/src/types/Privacy.d.ts +13 -6
- package/lib/typescript/src/types/Privacy.d.ts.map +1 -1
- package/lib/typescript/src/types/RewardedAd.d.ts +7 -5
- package/lib/typescript/src/types/RewardedAd.d.ts.map +1 -1
- package/lib/typescript/src/types/ViewAd.d.ts +46 -50
- package/lib/typescript/src/types/ViewAd.d.ts.map +1 -1
- package/package.json +1 -1
- package/react-native-applovin-max.podspec +2 -2
- package/src/AdView.tsx +64 -82
- package/src/AppLovinMAX.ts +39 -29
- package/src/BannerAd.ts +2 -3
- package/src/ErrorCode.ts +24 -31
- package/src/EventEmitter.ts +20 -2
- package/src/Utils.ts +20 -1
- package/src/nativeAd/NativeAdView.tsx +31 -21
- package/src/nativeAd/NativeAdViewComponents.tsx +97 -38
- package/src/nativeAd/NativeAdViewProvider.tsx +23 -0
- package/src/specs/AppLovinMAXAdViewNativeComponent.ts +62 -1
- package/src/specs/AppLovinMAXNativeAdViewNativeComponent.ts +70 -6
- package/src/specs/NativeAppLovinMAXModule.ts +77 -56
- package/src/types/AdEvent.ts +10 -4
- package/src/types/AdInfo.ts +78 -85
- package/src/types/AdProps.ts +14 -15
- package/src/types/AdViewProps.ts +33 -29
- package/src/types/AppLovinMAX.ts +50 -53
- package/src/types/BannerAd.ts +24 -18
- package/src/types/CMPError.ts +7 -4
- package/src/types/Configuration.ts +12 -14
- package/src/types/FullscreenAd.ts +39 -46
- package/src/types/MRecAd.ts +7 -3
- package/src/types/NativeAd.ts +12 -11
- package/src/types/NativeAdViewProps.ts +4 -3
- package/src/types/Privacy.ts +13 -6
- package/src/types/RewardedAd.ts +7 -5
- package/src/types/ViewAd.ts +46 -50
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provides the NativeAdView component, which manages loading and rendering of native ads using the
|
|
3
|
+
* AppLovin MAX SDK in React Native.
|
|
4
|
+
*/
|
|
5
|
+
|
|
1
6
|
import * as React from 'react';
|
|
2
7
|
import { forwardRef, useContext, useImperativeHandle, useRef, useState, useEffect, useCallback } from 'react';
|
|
3
8
|
import { findNodeHandle, View } from 'react-native';
|
|
@@ -11,8 +16,7 @@ import type { NativeAdViewHandler, NativeAdViewProps } from '../types/NativeAdVi
|
|
|
11
16
|
import { makeExtraParametersArray, makeLocalExtraParametersArray } from '../Utils';
|
|
12
17
|
|
|
13
18
|
/**
|
|
14
|
-
* The {@link NativeAdView} component
|
|
15
|
-
* renders it with the asset views:
|
|
19
|
+
* The {@link NativeAdView} component renders a native ad and binds it to asset views:
|
|
16
20
|
*
|
|
17
21
|
* - {@link IconView}
|
|
18
22
|
* - {@link TitleView}
|
|
@@ -22,19 +26,21 @@ import { makeExtraParametersArray, makeLocalExtraParametersArray } from '../Util
|
|
|
22
26
|
* - {@link MediaView}
|
|
23
27
|
* - {@link CallToActionView}
|
|
24
28
|
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
29
|
+
* Each asset view must be manually laid out and styled.
|
|
30
|
+
* The component automatically populates content once an ad is loaded.
|
|
31
|
+
* You can reload the ad using the component’s ref via `loadAd()`.
|
|
32
|
+
*
|
|
33
|
+
* **Note:** The AppLovin SDK must be initialized before using this component.
|
|
28
34
|
*
|
|
29
35
|
* ### Example:
|
|
30
|
-
* ```
|
|
36
|
+
* ```tsx
|
|
31
37
|
* <NativeAdView
|
|
32
38
|
* ref={nativeAdViewHandler}
|
|
33
39
|
* adUnitId={adUnitId}
|
|
34
40
|
* style={styles.nativead}
|
|
35
41
|
* onAdLoaded={(adInfo: AdInfo) => { ... }}
|
|
36
42
|
* >
|
|
37
|
-
* <View style={
|
|
43
|
+
* <View style={...}>
|
|
38
44
|
* <IconView style={styles.icon} />
|
|
39
45
|
* <TitleView style={styles.title} />
|
|
40
46
|
* <AdvertiserView style={styles.advertiser} />
|
|
@@ -46,6 +52,9 @@ import { makeExtraParametersArray, makeLocalExtraParametersArray } from '../Util
|
|
|
46
52
|
* </View>
|
|
47
53
|
* </NativeAdView>
|
|
48
54
|
* ```
|
|
55
|
+
*
|
|
56
|
+
* For a complete implementation example, see:
|
|
57
|
+
* https://github.com/AppLovin/AppLovin-MAX-React-Native/blob/master/example/src/NativeAdViewExample.tsx
|
|
49
58
|
*/
|
|
50
59
|
export const NativeAdView = forwardRef<NativeAdViewHandler, NativeAdViewProps & ViewProps>(function NativeAdView(props, ref) {
|
|
51
60
|
const [isInitialized, setIsInitialized] = useState<boolean>(false);
|
|
@@ -72,21 +81,13 @@ export const NativeAdView = forwardRef<NativeAdViewHandler, NativeAdViewProps &
|
|
|
72
81
|
);
|
|
73
82
|
});
|
|
74
83
|
|
|
84
|
+
/**
|
|
85
|
+
* Extracts native ad info from a synthetic event and invokes the provided callback, if any.
|
|
86
|
+
* Ensures optional native ad fields have fallback defaults.
|
|
87
|
+
*/
|
|
75
88
|
const handleNativeAdViewEvent = <T extends AdInfoEvent | AdLoadFailedEvent>(event: NativeSyntheticEvent<T>, callback?: (adInfo: T) => void) => {
|
|
76
89
|
if (!callback) return;
|
|
77
|
-
|
|
78
|
-
let adInfo: any = { ...event.nativeEvent };
|
|
79
|
-
|
|
80
|
-
if ('nativeAd' in event.nativeEvent) {
|
|
81
|
-
adInfo.nativeAd = {
|
|
82
|
-
...event.nativeEvent.nativeAd,
|
|
83
|
-
isIconImageAvailable: event.nativeEvent.nativeAd?.isIconImageAvailable ?? false,
|
|
84
|
-
isOptionsViewAvailable: event.nativeEvent.nativeAd?.isOptionsViewAvailable ?? false,
|
|
85
|
-
isMediaViewAvailable: event.nativeEvent.nativeAd?.isMediaViewAvailable ?? false,
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
callback(adInfo);
|
|
90
|
+
callback(event.nativeEvent);
|
|
90
91
|
};
|
|
91
92
|
|
|
92
93
|
const NativeAdViewImpl = forwardRef<NativeAdViewHandler, NativeAdViewProps & ViewProps>(function NativeAdViewImpl(
|
|
@@ -98,13 +99,16 @@ const NativeAdViewImpl = forwardRef<NativeAdViewHandler, NativeAdViewProps & Vie
|
|
|
98
99
|
|
|
99
100
|
const nativeAdViewRef = useRef<React.ElementRef<typeof NativeAdViewComponent> | undefined>();
|
|
100
101
|
|
|
101
|
-
//
|
|
102
|
+
// Triggers a native ad load via the native command
|
|
102
103
|
const loadAd = useCallback(() => {
|
|
103
104
|
nativeAdViewRef.current && Commands.loadAd(nativeAdViewRef.current);
|
|
104
105
|
}, []);
|
|
105
106
|
|
|
106
107
|
useImperativeHandle(ref, () => ({ loadAd }), [loadAd]);
|
|
107
108
|
|
|
109
|
+
/**
|
|
110
|
+
* Updates the native asset view binding for a given view type (e.g., TitleView, MediaView).
|
|
111
|
+
*/
|
|
108
112
|
const updateAssetView = useCallback((assetViewRef: React.RefObject<View>, type: string) => {
|
|
109
113
|
if (!nativeAdViewRef.current || !assetViewRef.current) return;
|
|
110
114
|
|
|
@@ -114,6 +118,12 @@ const NativeAdViewImpl = forwardRef<NativeAdViewHandler, NativeAdViewProps & Vie
|
|
|
114
118
|
}
|
|
115
119
|
}, []);
|
|
116
120
|
|
|
121
|
+
/**
|
|
122
|
+
* Handles native ad load event:
|
|
123
|
+
* - Updates context with the new native ad data
|
|
124
|
+
* - Notifies native module of updated asset view mappings
|
|
125
|
+
* - Triggers native rendering after all asset views are registered
|
|
126
|
+
*/
|
|
117
127
|
const onAdLoadedEvent = useCallback(
|
|
118
128
|
(event: NativeSyntheticEvent<AdInfoEvent>) => {
|
|
119
129
|
const nativeAdImpl = event.nativeEvent.nativeAdImpl;
|
|
@@ -1,9 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provides pre-styled React Native components for each native ad asset view:
|
|
3
|
+
*
|
|
4
|
+
* - TitleView
|
|
5
|
+
* - AdvertiserView
|
|
6
|
+
* - BodyView
|
|
7
|
+
* - CallToActionView
|
|
8
|
+
* - IconView
|
|
9
|
+
* - OptionsView
|
|
10
|
+
* - MediaView
|
|
11
|
+
* - StarRatingView
|
|
12
|
+
*
|
|
13
|
+
* Each component pulls ad content and view refs from NativeAdView context,
|
|
14
|
+
* and must be rendered inside a {@link NativeAdView}.
|
|
15
|
+
*/
|
|
16
|
+
|
|
1
17
|
import * as React from 'react';
|
|
2
18
|
import { useContext, useMemo } from 'react';
|
|
3
19
|
import { Text, Image, View, TouchableOpacity, StyleSheet, Platform } from 'react-native';
|
|
4
|
-
import type { ViewProps, ImageProps,
|
|
20
|
+
import type { ViewProps, ImageProps, TextProps } from 'react-native';
|
|
5
21
|
import { NativeAdViewContext } from './NativeAdViewProvider';
|
|
6
22
|
|
|
23
|
+
/**
|
|
24
|
+
* Renders the native ad’s title.
|
|
25
|
+
*/
|
|
7
26
|
export const TitleView = (props: TextProps) => {
|
|
8
27
|
const { titleRef, nativeAd } = useContext(NativeAdViewContext);
|
|
9
28
|
return (
|
|
@@ -13,6 +32,9 @@ export const TitleView = (props: TextProps) => {
|
|
|
13
32
|
);
|
|
14
33
|
};
|
|
15
34
|
|
|
35
|
+
/**
|
|
36
|
+
* Renders the advertiser name.
|
|
37
|
+
*/
|
|
16
38
|
export const AdvertiserView = (props: TextProps) => {
|
|
17
39
|
const { advertiserRef, nativeAd } = useContext(NativeAdViewContext);
|
|
18
40
|
return (
|
|
@@ -22,6 +44,9 @@ export const AdvertiserView = (props: TextProps) => {
|
|
|
22
44
|
);
|
|
23
45
|
};
|
|
24
46
|
|
|
47
|
+
/**
|
|
48
|
+
* Renders the ad’s body text (description).
|
|
49
|
+
*/
|
|
25
50
|
export const BodyView = (props: TextProps) => {
|
|
26
51
|
const { bodyRef, nativeAd } = useContext(NativeAdViewContext);
|
|
27
52
|
return (
|
|
@@ -31,31 +56,39 @@ export const BodyView = (props: TextProps) => {
|
|
|
31
56
|
);
|
|
32
57
|
};
|
|
33
58
|
|
|
59
|
+
/**
|
|
60
|
+
* Renders the call-to-action label.
|
|
61
|
+
* On iOS, wraps the text with a TouchableOpacity for better click behavior.
|
|
62
|
+
*/
|
|
34
63
|
export const CallToActionView = (props: TextProps) => {
|
|
35
64
|
const { callToActionRef, nativeAd } = useContext(NativeAdViewContext);
|
|
36
|
-
|
|
65
|
+
|
|
37
66
|
if (Platform.OS === 'android') {
|
|
38
67
|
return (
|
|
39
68
|
<Text {...props} ref={callToActionRef}>
|
|
40
69
|
{nativeAd.callToAction ?? ''}
|
|
41
70
|
</Text>
|
|
42
71
|
);
|
|
43
|
-
} else {
|
|
44
|
-
return (
|
|
45
|
-
<TouchableOpacity>
|
|
46
|
-
<Text {...props} ref={callToActionRef}>
|
|
47
|
-
{nativeAd.callToAction ?? ''}
|
|
48
|
-
</Text>
|
|
49
|
-
</TouchableOpacity>
|
|
50
|
-
);
|
|
51
72
|
}
|
|
73
|
+
|
|
74
|
+
return (
|
|
75
|
+
<TouchableOpacity>
|
|
76
|
+
<Text {...props} ref={callToActionRef}>
|
|
77
|
+
{nativeAd.callToAction ?? ''}
|
|
78
|
+
</Text>
|
|
79
|
+
</TouchableOpacity>
|
|
80
|
+
);
|
|
52
81
|
};
|
|
53
82
|
|
|
83
|
+
/**
|
|
84
|
+
* Renders the icon image for the native ad.
|
|
85
|
+
* Falls back to a blank placeholder if not available.
|
|
86
|
+
*/
|
|
54
87
|
export const IconView = (props: Omit<ImageProps, 'source'>) => {
|
|
55
88
|
const { imageRef, nativeAd } = useContext(NativeAdViewContext);
|
|
56
89
|
const defaultIcon = require('./img/blank_icon.png');
|
|
57
90
|
|
|
58
|
-
const imageSource = (() => {
|
|
91
|
+
const imageSource = useMemo(() => {
|
|
59
92
|
if (nativeAd?.url) {
|
|
60
93
|
return { uri: nativeAd.url };
|
|
61
94
|
}
|
|
@@ -63,60 +96,86 @@ export const IconView = (props: Omit<ImageProps, 'source'>) => {
|
|
|
63
96
|
return { uri: `data:image/jpeg;base64,${nativeAd.imageSource}` };
|
|
64
97
|
}
|
|
65
98
|
return defaultIcon;
|
|
66
|
-
})
|
|
99
|
+
}, [nativeAd.url, nativeAd.imageSource, defaultIcon]);
|
|
67
100
|
|
|
68
101
|
return <Image {...props} ref={imageRef} source={imageSource} />;
|
|
69
102
|
};
|
|
70
103
|
|
|
104
|
+
/**
|
|
105
|
+
* Renders the native ad’s options view.
|
|
106
|
+
*/
|
|
71
107
|
export const OptionsView = (props: ViewProps) => {
|
|
72
108
|
const { optionViewRef } = useContext(NativeAdViewContext);
|
|
73
109
|
return <View {...props} ref={optionViewRef} />;
|
|
74
110
|
};
|
|
75
111
|
|
|
112
|
+
/**
|
|
113
|
+
* Renders the native ad’s media content.
|
|
114
|
+
*/
|
|
76
115
|
export const MediaView = (props: ViewProps) => {
|
|
77
116
|
const { mediaViewRef } = useContext(NativeAdViewContext);
|
|
78
117
|
return <View {...props} ref={mediaViewRef} />;
|
|
79
118
|
};
|
|
80
119
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
120
|
+
/**
|
|
121
|
+
* Props for the {@link StarRatingView} component, which displays a star rating
|
|
122
|
+
* using Unicode stars (★ and ☆) styled with color, shadow, and size.
|
|
123
|
+
*/
|
|
124
|
+
type StarRatingViewProps = ViewProps & {
|
|
125
|
+
/**
|
|
126
|
+
* The color used for filled (active) stars.
|
|
127
|
+
* Defaults to gold (#ffe234).
|
|
128
|
+
*/
|
|
129
|
+
color?: string;
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* The color used for empty (inactive) stars.
|
|
133
|
+
* Defaults to light gray (#dedede).
|
|
134
|
+
*/
|
|
135
|
+
shadowColor?: string;
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* The size of each star, which also determines their visual size.
|
|
139
|
+
* Defaults to 10.
|
|
140
|
+
*/
|
|
141
|
+
size?: number;
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Renders the star rating of the ad, using Unicode stars (★ and ☆).
|
|
146
|
+
* Filled stars are rendered over hollow stars using a clipped view.
|
|
147
|
+
*/
|
|
148
|
+
export const StarRatingView = ({ color = '#ffe234', shadowColor = '#dedede', size = 10, style }: StarRatingViewProps) => {
|
|
87
149
|
const { nativeAd } = useContext(NativeAdViewContext);
|
|
150
|
+
const maxStarCount = 5;
|
|
151
|
+
|
|
152
|
+
const containerStyle = useMemo(() => StyleSheet.flatten([style, styles.starRatingContainer]), [style]);
|
|
88
153
|
|
|
89
|
-
// Memoize the star rendering process
|
|
90
154
|
const stars = useMemo(() => {
|
|
91
|
-
|
|
92
|
-
return Array.from({ length: maxStarCount }).map((_, index) => (
|
|
93
|
-
<Text key={index} style={{ fontSize: starSize }}>
|
|
94
|
-
{' '}
|
|
95
|
-
</Text>
|
|
96
|
-
));
|
|
97
|
-
}
|
|
155
|
+
const starRating = Math.max(0, Math.min(maxStarCount, nativeAd.starRating ?? 0));
|
|
98
156
|
|
|
99
157
|
return Array.from({ length: maxStarCount }).map((_, index) => {
|
|
100
|
-
const
|
|
101
|
-
const width = (starRating - index) *
|
|
158
|
+
const isFull = starRating > index;
|
|
159
|
+
const width = Math.min(size, Math.max(0, (starRating - index) * size));
|
|
160
|
+
|
|
102
161
|
return (
|
|
103
162
|
<View key={index}>
|
|
104
|
-
<Text style={{ fontSize:
|
|
105
|
-
{
|
|
106
|
-
<View style={[{ width
|
|
107
|
-
<Text style={{ fontSize:
|
|
163
|
+
<Text style={{ fontSize: size, color: isFull ? color : shadowColor }}>{String.fromCodePoint(0x2606)}</Text>
|
|
164
|
+
{isFull && (
|
|
165
|
+
<View style={[{ width }, styles.starRating]}>
|
|
166
|
+
<Text style={{ fontSize: size, color }}>{String.fromCodePoint(0x2605)}</Text>
|
|
108
167
|
</View>
|
|
109
168
|
)}
|
|
110
169
|
</View>
|
|
111
170
|
);
|
|
112
171
|
});
|
|
113
|
-
}, [nativeAd.starRating,
|
|
172
|
+
}, [nativeAd.starRating, color, shadowColor, size]);
|
|
114
173
|
|
|
115
|
-
|
|
116
|
-
<View
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
174
|
+
if (!nativeAd.starRating) {
|
|
175
|
+
return <View style={containerStyle} />;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
return <View style={containerStyle}>{stars}</View>;
|
|
120
179
|
};
|
|
121
180
|
|
|
122
181
|
const styles = StyleSheet.create({
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provides context and state management for NativeAdView and its child asset views.
|
|
3
|
+
* Shares asset view refs and native ad data between internal components and the native SDK.
|
|
4
|
+
*/
|
|
5
|
+
|
|
1
6
|
import * as React from 'react';
|
|
2
7
|
import { useState, createContext, useRef } from 'react';
|
|
3
8
|
import type { ReactNode } from 'react';
|
|
@@ -5,12 +10,20 @@ import type { Image, NativeMethods, Text, View } from 'react-native';
|
|
|
5
10
|
import type { NativeAd } from '../types/NativeAd';
|
|
6
11
|
import type { NativeProps } from '../specs/AppLovinMAXNativeAdViewNativeComponent';
|
|
7
12
|
|
|
13
|
+
/**
|
|
14
|
+
* Native component type for the rendered NativeAdView.
|
|
15
|
+
*/
|
|
8
16
|
export type NativeAdViewType = React.Component<NativeProps> & NativeMethods;
|
|
9
17
|
|
|
18
|
+
// Ref types for native views
|
|
10
19
|
type TextRef = React.ElementRef<typeof Text>;
|
|
11
20
|
type ImageRef = React.ElementRef<typeof Image>;
|
|
12
21
|
type ViewRef = React.ElementRef<typeof View>;
|
|
13
22
|
|
|
23
|
+
/**
|
|
24
|
+
* Context type used internally by NativeAdView.
|
|
25
|
+
* Stores references to asset views and the current native ad data.
|
|
26
|
+
*/
|
|
14
27
|
export type NativeAdViewContextType = {
|
|
15
28
|
titleRef: React.RefObject<TextRef>;
|
|
16
29
|
advertiserRef: React.RefObject<TextRef>;
|
|
@@ -23,11 +36,15 @@ export type NativeAdViewContextType = {
|
|
|
23
36
|
setNativeAd: React.Dispatch<React.SetStateAction<NativeAd>>;
|
|
24
37
|
};
|
|
25
38
|
|
|
39
|
+
// Default for an uninitialized native ad
|
|
26
40
|
const defaultNativeAd: NativeAd = {
|
|
27
41
|
isOptionsViewAvailable: false,
|
|
28
42
|
isMediaViewAvailable: false,
|
|
29
43
|
};
|
|
30
44
|
|
|
45
|
+
/**
|
|
46
|
+
* Internal context used by NativeAdView to provide access to asset view refs and native ad data.
|
|
47
|
+
*/
|
|
31
48
|
export const NativeAdViewContext = createContext<NativeAdViewContextType>({
|
|
32
49
|
titleRef: { current: null },
|
|
33
50
|
advertiserRef: { current: null },
|
|
@@ -40,6 +57,9 @@ export const NativeAdViewContext = createContext<NativeAdViewContextType>({
|
|
|
40
57
|
setNativeAd: () => {},
|
|
41
58
|
});
|
|
42
59
|
|
|
60
|
+
/**
|
|
61
|
+
* React provider that wraps components requiring access to NativeAdViewContext.
|
|
62
|
+
*/
|
|
43
63
|
export const NativeAdViewProvider: React.FC<{ children: ReactNode }> = ({ children }) => {
|
|
44
64
|
const titleRef = useRef<TextRef | null>(null);
|
|
45
65
|
const advertiserRef = useRef<TextRef | null>(null);
|
|
@@ -50,6 +70,9 @@ export const NativeAdViewProvider: React.FC<{ children: ReactNode }> = ({ childr
|
|
|
50
70
|
const mediaViewRef = useRef<ViewRef | null>(null);
|
|
51
71
|
const [nativeAd, setNativeAd] = useState<NativeAd>(defaultNativeAd);
|
|
52
72
|
|
|
73
|
+
/**
|
|
74
|
+
* Memoized context value to avoid unnecessary renders.
|
|
75
|
+
*/
|
|
53
76
|
const providerValue = React.useMemo(
|
|
54
77
|
() => ({
|
|
55
78
|
titleRef,
|
|
@@ -3,6 +3,9 @@ import type { Double, DirectEventHandler, WithDefault } from 'react-native/Libra
|
|
|
3
3
|
import codegenNativeCommands from 'react-native/Libraries/Utilities/codegenNativeCommands';
|
|
4
4
|
import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* Payload for ad lifecycle events (e.g. load, display, click).
|
|
8
|
+
*/
|
|
6
9
|
export type AdInfoEvent = Readonly<{
|
|
7
10
|
adUnitId: string;
|
|
8
11
|
adFormat: string;
|
|
@@ -21,6 +24,9 @@ export type AdInfoEvent = Readonly<{
|
|
|
21
24
|
}>;
|
|
22
25
|
}>;
|
|
23
26
|
|
|
27
|
+
/**
|
|
28
|
+
* Payload for ad load failure events.
|
|
29
|
+
*/
|
|
24
30
|
export type AdLoadFailedEvent = Readonly<{
|
|
25
31
|
adUnitId: string;
|
|
26
32
|
adViewId?: Double;
|
|
@@ -31,6 +37,9 @@ export type AdLoadFailedEvent = Readonly<{
|
|
|
31
37
|
adLoadFailureInfo?: string | null;
|
|
32
38
|
}>;
|
|
33
39
|
|
|
40
|
+
/**
|
|
41
|
+
* Payload for ad display failure events.
|
|
42
|
+
*/
|
|
34
43
|
export type AdDisplayFailedEvent = Readonly<{
|
|
35
44
|
adUnitId: string;
|
|
36
45
|
adFormat: string;
|
|
@@ -53,44 +62,96 @@ export type AdDisplayFailedEvent = Readonly<{
|
|
|
53
62
|
mediatedNetworkErrorMessage: string;
|
|
54
63
|
}>;
|
|
55
64
|
|
|
65
|
+
/**
|
|
66
|
+
* Props passed to the {@link AppLovinMAXAdView} native component.
|
|
67
|
+
*/
|
|
56
68
|
export interface NativeProps extends ViewProps {
|
|
69
|
+
/** Ad unit ID used to load the ad. */
|
|
57
70
|
adUnitId: string;
|
|
71
|
+
|
|
72
|
+
/** Ad format (e.g., "BANNER", "MREC"). */
|
|
58
73
|
adFormat?: string;
|
|
74
|
+
|
|
75
|
+
/** Unique identifier for this ad view. Defaults to 0. */
|
|
59
76
|
adViewId?: WithDefault<Double, 0>;
|
|
77
|
+
|
|
78
|
+
/** Optional placement name for ad tracking. */
|
|
60
79
|
placement?: string | null;
|
|
80
|
+
|
|
81
|
+
/** Optional custom data associated with the ad. */
|
|
61
82
|
customData?: string | null;
|
|
83
|
+
|
|
84
|
+
/** Enables adaptive banner sizing. Defaults to `true`. */
|
|
62
85
|
adaptiveBannerEnabled?: WithDefault<boolean, true>;
|
|
86
|
+
|
|
87
|
+
/** Enables automatic refresh of the ad. Defaults to `true`. */
|
|
63
88
|
autoRefresh?: WithDefault<boolean, true>;
|
|
89
|
+
|
|
90
|
+
/** Whether to automatically load the ad on mount. Defaults to `true`. */
|
|
64
91
|
loadOnMount?: WithDefault<boolean, true>;
|
|
92
|
+
|
|
93
|
+
/** Extra key-value string parameters passed to the SDK. */
|
|
65
94
|
extraParameters?: ReadonlyArray<{
|
|
66
95
|
key: string;
|
|
67
96
|
value: string | null;
|
|
68
97
|
}>;
|
|
98
|
+
|
|
99
|
+
/** Local string parameters passed to the mediation adapter. */
|
|
69
100
|
strLocalExtraParameters?: ReadonlyArray<{
|
|
70
101
|
key: string;
|
|
71
102
|
value: string | null;
|
|
72
103
|
}>;
|
|
104
|
+
|
|
105
|
+
/** Local boolean parameters passed to the mediation adapter. */
|
|
73
106
|
boolLocalExtraParameters?: ReadonlyArray<{
|
|
74
107
|
key: string;
|
|
75
108
|
value: boolean | null;
|
|
76
109
|
}>;
|
|
110
|
+
|
|
111
|
+
/** Called when an ad is successfully loaded. */
|
|
77
112
|
onAdLoadedEvent: DirectEventHandler<AdInfoEvent>;
|
|
113
|
+
|
|
114
|
+
/** Called when an ad fails to load. */
|
|
78
115
|
onAdLoadFailedEvent: DirectEventHandler<AdLoadFailedEvent>;
|
|
116
|
+
|
|
117
|
+
/** Called when an ad fails to display. */
|
|
79
118
|
onAdDisplayFailedEvent: DirectEventHandler<AdDisplayFailedEvent>;
|
|
119
|
+
|
|
120
|
+
/** Called when the ad is clicked. */
|
|
80
121
|
onAdClickedEvent: DirectEventHandler<AdInfoEvent>;
|
|
122
|
+
|
|
123
|
+
/** Called when the ad expands. */
|
|
81
124
|
onAdExpandedEvent: DirectEventHandler<AdInfoEvent>;
|
|
125
|
+
|
|
126
|
+
/** Called when the ad collapses. */
|
|
82
127
|
onAdCollapsedEvent: DirectEventHandler<AdInfoEvent>;
|
|
128
|
+
|
|
129
|
+
/** Called when ad revenue is reported. */
|
|
83
130
|
onAdRevenuePaidEvent: DirectEventHandler<AdInfoEvent>;
|
|
84
131
|
}
|
|
85
132
|
|
|
86
133
|
type AppLovinMAXAdViewNativeComponentType = HostComponent<NativeProps>;
|
|
87
134
|
|
|
135
|
+
/**
|
|
136
|
+
* Native commands callable from JS for managing {@link AppLovinMAXAdView}.
|
|
137
|
+
*/
|
|
88
138
|
interface NativeCommands {
|
|
89
|
-
|
|
139
|
+
/**
|
|
140
|
+
* Manually starts loading a new ad when `loadOnMount` is `false`.
|
|
141
|
+
*
|
|
142
|
+
* @param viewRef - Reference to the native ad view component.
|
|
143
|
+
*/
|
|
144
|
+
loadAd(viewRef: React.ElementRef<AppLovinMAXAdViewNativeComponentType>): void;
|
|
90
145
|
}
|
|
91
146
|
|
|
147
|
+
/**
|
|
148
|
+
* JS interface to ad view commands for {@link AppLovinMAXAdView}.
|
|
149
|
+
*/
|
|
92
150
|
export const Commands: NativeCommands = codegenNativeCommands<NativeCommands>({
|
|
93
151
|
supportedCommands: ['loadAd'],
|
|
94
152
|
});
|
|
95
153
|
|
|
154
|
+
/**
|
|
155
|
+
* Native view component for displaying a banner or MREC ad.
|
|
156
|
+
*/
|
|
96
157
|
export default codegenNativeComponent<NativeProps>('AppLovinMAXAdView') as HostComponent<NativeProps>;
|
|
@@ -3,6 +3,9 @@ import type { Double, DirectEventHandler } from 'react-native/Libraries/Types/Co
|
|
|
3
3
|
import codegenNativeCommands from 'react-native/Libraries/Utilities/codegenNativeCommands';
|
|
4
4
|
import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* Payload for native ad lifecycle events (e.g., load, click, revenue).
|
|
8
|
+
*/
|
|
6
9
|
export type AdInfoEvent = Readonly<{
|
|
7
10
|
adUnitId: string;
|
|
8
11
|
adFormat: string;
|
|
@@ -18,6 +21,10 @@ export type AdInfoEvent = Readonly<{
|
|
|
18
21
|
width: Double;
|
|
19
22
|
height: Double;
|
|
20
23
|
}>;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Optional native ad content for display in asset views.
|
|
27
|
+
*/
|
|
21
28
|
nativeAd?: Readonly<{
|
|
22
29
|
title?: string;
|
|
23
30
|
advertiser?: string;
|
|
@@ -29,6 +36,10 @@ export type AdInfoEvent = Readonly<{
|
|
|
29
36
|
isOptionsViewAvailable: boolean;
|
|
30
37
|
isMediaViewAvailable: boolean;
|
|
31
38
|
}>;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Full internal native ad payload used for runtime rendering and view mapping.
|
|
42
|
+
*/
|
|
32
43
|
nativeAdImpl: Readonly<{
|
|
33
44
|
title?: string | null;
|
|
34
45
|
advertiser?: string | null;
|
|
@@ -43,6 +54,9 @@ export type AdInfoEvent = Readonly<{
|
|
|
43
54
|
}>;
|
|
44
55
|
}>;
|
|
45
56
|
|
|
57
|
+
/**
|
|
58
|
+
* Payload for native ad load failure events.
|
|
59
|
+
*/
|
|
46
60
|
export type AdLoadFailedEvent = Readonly<{
|
|
47
61
|
adUnitId: string;
|
|
48
62
|
code: Double;
|
|
@@ -52,38 +66,88 @@ export type AdLoadFailedEvent = Readonly<{
|
|
|
52
66
|
adLoadFailureInfo?: string | null;
|
|
53
67
|
}>;
|
|
54
68
|
|
|
69
|
+
/**
|
|
70
|
+
* Props passed to the {@link AppLovinMAXNativeAdView} native component.
|
|
71
|
+
*/
|
|
55
72
|
export interface NativeProps extends ViewProps {
|
|
73
|
+
/** Ad unit ID used to load the ad. */
|
|
56
74
|
adUnitId: string;
|
|
75
|
+
|
|
76
|
+
/** Optional placement name for ad tracking. */
|
|
57
77
|
placement?: string | null;
|
|
78
|
+
|
|
79
|
+
/** Optional custom data associated with the ad. */
|
|
58
80
|
customData?: string | null;
|
|
81
|
+
|
|
82
|
+
/** Extra key-value string parameters passed to the SDK. */
|
|
59
83
|
extraParameters?: ReadonlyArray<{
|
|
60
84
|
key: string;
|
|
61
85
|
value: string | null;
|
|
62
|
-
}
|
|
86
|
+
}>;
|
|
87
|
+
|
|
88
|
+
/** Local string parameters passed to the mediation adapter. */
|
|
63
89
|
strLocalExtraParameters?: ReadonlyArray<{
|
|
64
90
|
key: string;
|
|
65
91
|
value: string | null;
|
|
66
|
-
}
|
|
92
|
+
}>;
|
|
93
|
+
|
|
94
|
+
/** Local boolean parameters passed to the mediation adapter. */
|
|
67
95
|
boolLocalExtraParameters?: ReadonlyArray<{
|
|
68
96
|
key: string;
|
|
69
97
|
value: boolean | null;
|
|
70
|
-
}
|
|
98
|
+
}>;
|
|
99
|
+
|
|
100
|
+
/** Called when a native ad is successfully loaded. */
|
|
71
101
|
onAdLoadedEvent: DirectEventHandler<AdInfoEvent>;
|
|
102
|
+
|
|
103
|
+
/** Called when ad loading fails. */
|
|
72
104
|
onAdLoadFailedEvent: DirectEventHandler<AdLoadFailedEvent>;
|
|
105
|
+
|
|
106
|
+
/** Called when the ad is clicked. */
|
|
73
107
|
onAdClickedEvent: DirectEventHandler<AdInfoEvent>;
|
|
108
|
+
|
|
109
|
+
/** Called when ad revenue is reported. */
|
|
74
110
|
onAdRevenuePaidEvent: DirectEventHandler<AdInfoEvent>;
|
|
75
111
|
}
|
|
76
112
|
|
|
77
113
|
type AppLovinMAXNativeAdViewNativeComponentType = HostComponent<NativeProps>;
|
|
78
114
|
|
|
115
|
+
/**
|
|
116
|
+
* Native commands callable from JS for managing {@link NativeAdView}.
|
|
117
|
+
*/
|
|
79
118
|
interface NativeCommands {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
119
|
+
/**
|
|
120
|
+
* Manually loads a new native ad.
|
|
121
|
+
*
|
|
122
|
+
* @param viewRef - Reference to the native ad view.
|
|
123
|
+
*/
|
|
124
|
+
loadAd(viewRef: React.ElementRef<AppLovinMAXNativeAdViewNativeComponentType>): void;
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Binds a React Native child view to a native asset (e.g. TitleView, IconView).
|
|
128
|
+
*
|
|
129
|
+
* @param viewRef - Reference to the native ad view.
|
|
130
|
+
* @param assetViewTag - React tag for the asset view (via `findNodeHandle()`).
|
|
131
|
+
* @param assetViewName - Name of the asset (e.g., "MediaView", "CallToActionView").
|
|
132
|
+
*/
|
|
133
|
+
updateAssetView(viewRef: React.ElementRef<AppLovinMAXNativeAdViewNativeComponentType>, assetViewTag: Double, assetViewName: string): void;
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Instructs the native view to render the bound native ad after all asset views are set.
|
|
137
|
+
*
|
|
138
|
+
* @param viewRef - Reference to the native ad view.
|
|
139
|
+
*/
|
|
140
|
+
renderNativeAd(viewRef: React.ElementRef<AppLovinMAXNativeAdViewNativeComponentType>): void;
|
|
83
141
|
}
|
|
84
142
|
|
|
143
|
+
/**
|
|
144
|
+
* JS interface to native ad view commands for {@link AppLovinMAXNativeAdView}.
|
|
145
|
+
*/
|
|
85
146
|
export const Commands: NativeCommands = codegenNativeCommands<NativeCommands>({
|
|
86
147
|
supportedCommands: ['loadAd', 'updateAssetView', 'renderNativeAd'],
|
|
87
148
|
});
|
|
88
149
|
|
|
150
|
+
/**
|
|
151
|
+
* Native component for rendering a custom native ad layout using bound asset views.
|
|
152
|
+
*/
|
|
89
153
|
export default codegenNativeComponent<NativeProps>('AppLovinMAXNativeAdView') as HostComponent<NativeProps>;
|