@vynix-org/react-native-ads-sdk 0.2.1 → 0.2.3
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/src/main/AndroidManifest.xml +1 -3
- package/lib/module/ads-manager/NativeAdsManager.js +26 -8
- package/lib/module/ads-manager/NativeAdsManager.js.map +1 -1
- package/lib/module/analytics/AdjustTrackingManager.js +91 -141
- package/lib/module/analytics/AdjustTrackingManager.js.map +1 -1
- package/lib/module/analytics/TrackingManager.js +2 -2
- package/lib/module/analytics/TrackingManager.js.map +1 -1
- package/lib/module/components/NativeAdComponent.js +78 -69
- package/lib/module/components/NativeAdComponent.js.map +1 -1
- package/lib/module/components/NativeStyles.js +20 -0
- package/lib/module/components/NativeStyles.js.map +1 -1
- package/lib/module/event/config.js +27 -0
- package/lib/module/event/config.js.map +1 -0
- package/lib/module/hook/useNativeAd.js +4 -2
- package/lib/module/hook/useNativeAd.js.map +1 -1
- package/lib/module/index.js +1 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/stores/native-ads-store.js +35 -4
- package/lib/module/stores/native-ads-store.js.map +1 -1
- package/lib/module/types/ads-types.js +1 -0
- package/lib/module/types/ads-types.js.map +1 -1
- package/lib/typescript/src/ads-manager/NativeAdsManager.d.ts.map +1 -1
- package/lib/typescript/src/analytics/AdjustTrackingManager.d.ts +22 -0
- package/lib/typescript/src/analytics/AdjustTrackingManager.d.ts.map +1 -1
- package/lib/typescript/src/components/NativeAdComponent.d.ts.map +1 -1
- package/lib/typescript/src/components/NativeStyles.d.ts +24 -0
- package/lib/typescript/src/components/NativeStyles.d.ts.map +1 -1
- package/lib/typescript/src/event/config.d.ts +11 -0
- package/lib/typescript/src/event/config.d.ts.map +1 -0
- package/lib/typescript/src/hook/useNativeAd.d.ts +1 -0
- package/lib/typescript/src/hook/useNativeAd.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +1 -0
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/stores/native-ads-store.d.ts +3 -0
- package/lib/typescript/src/stores/native-ads-store.d.ts.map +1 -1
- package/lib/typescript/src/types/ads-types.d.ts +4 -0
- package/lib/typescript/src/types/ads-types.d.ts.map +1 -1
- package/package.json +2 -1
- package/src/ads-manager/NativeAdsManager.ts +32 -8
- package/src/analytics/AdjustTrackingManager.ts +146 -141
- package/src/analytics/TrackingManager.ts +2 -2
- package/src/components/NativeAdComponent.tsx +97 -79
- package/src/components/NativeStyles.ts +20 -0
- package/src/event/config.ts +36 -0
- package/src/hook/useNativeAd.ts +6 -4
- package/src/index.tsx +2 -0
- package/src/stores/native-ads-store.ts +37 -2
- package/src/types/ads-types.ts +4 -0
|
@@ -52,19 +52,30 @@ export const NativeAdComponent: React.FC<NativeAdComponentProps> = ({
|
|
|
52
52
|
headlineStyles,
|
|
53
53
|
bodyStyles,
|
|
54
54
|
}) => {
|
|
55
|
-
const { ad, isLoading, error, isLoaded } =
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
55
|
+
const { ad, isLoading, error, isLoaded, isRefreshing, refreshAd } =
|
|
56
|
+
useNativeAd({
|
|
57
|
+
adKey,
|
|
58
|
+
adId,
|
|
59
|
+
autoLoad,
|
|
60
|
+
onLoad,
|
|
61
|
+
onDisplay,
|
|
62
|
+
onError,
|
|
63
|
+
onClicked: (ads: AdInstance) => {
|
|
64
|
+
refreshAd();
|
|
65
|
+
onClicked?.(ads);
|
|
66
|
+
},
|
|
67
|
+
onImpression,
|
|
68
|
+
});
|
|
65
69
|
|
|
66
|
-
//
|
|
67
|
-
|
|
70
|
+
// useEffect(() => {
|
|
71
|
+
// loadAd();
|
|
72
|
+
// }, [loadAd]);
|
|
73
|
+
|
|
74
|
+
const hasNativeAd = Boolean(ad?.data?.nativeAd);
|
|
75
|
+
const shouldShowSkeleton = !hasNativeAd && isLoading;
|
|
76
|
+
|
|
77
|
+
// Render loading state (only when chưa có dữ liệu cũ)
|
|
78
|
+
if (shouldShowSkeleton) {
|
|
68
79
|
return (
|
|
69
80
|
<View style={[styles.wrapper, style]}>
|
|
70
81
|
<View style={[styles.container, styles.centerContent]}>
|
|
@@ -75,90 +86,97 @@ export const NativeAdComponent: React.FC<NativeAdComponentProps> = ({
|
|
|
75
86
|
);
|
|
76
87
|
}
|
|
77
88
|
|
|
78
|
-
// Render error state
|
|
79
|
-
if (error) {
|
|
80
|
-
return null;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
89
|
// Render empty state
|
|
84
|
-
if (!isLoaded || !
|
|
90
|
+
if (!ad || !isLoaded || !hasNativeAd || error) {
|
|
85
91
|
return null;
|
|
86
92
|
}
|
|
87
93
|
|
|
88
|
-
const nativeAd = ad.data
|
|
94
|
+
const nativeAd = ad.data?.nativeAd as NativeAd;
|
|
89
95
|
|
|
90
96
|
return (
|
|
91
97
|
<View style={[styles.wrapper, style]}>
|
|
92
|
-
<
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
{nativeAd
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
98
|
+
<View style={styles.overlayContainer}>
|
|
99
|
+
<NativeAdView
|
|
100
|
+
key={nativeAd.responseId}
|
|
101
|
+
nativeAd={nativeAd}
|
|
102
|
+
style={[styles.container]}
|
|
103
|
+
>
|
|
104
|
+
{/* Ad Badge và Advertiser */}
|
|
105
|
+
<View style={styles.adHeader}>
|
|
106
|
+
{/* {nativeAd.advertiser && (
|
|
107
|
+
<NativeAsset assetType={NativeAssetType.ADVERTISER}>
|
|
108
|
+
<Text style={styles.advertiserText} numberOfLines={1}>
|
|
109
|
+
{nativeAd.advertiser}
|
|
110
|
+
</Text>
|
|
111
|
+
</NativeAsset>
|
|
112
|
+
)} */}
|
|
113
|
+
</View>
|
|
114
|
+
|
|
115
|
+
{nativeAd.callToAction && (
|
|
116
|
+
<NativeAsset assetType={NativeAssetType.CALL_TO_ACTION}>
|
|
117
|
+
<View style={[styles.ctaButton, buttonActionStyles]}>
|
|
118
|
+
<Text style={styles.ctaText}>{nativeAd.callToAction}</Text>
|
|
119
|
+
</View>
|
|
100
120
|
</NativeAsset>
|
|
101
121
|
)}
|
|
102
|
-
</View>
|
|
103
122
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
style={[
|
|
117
|
-
styles.mediaView,
|
|
118
|
-
nativeAd.mediaContent?.aspectRatio
|
|
119
|
-
? { aspectRatio: nativeAd.mediaContent.aspectRatio }
|
|
120
|
-
: { aspectRatio: 16 / 9 },
|
|
121
|
-
]}
|
|
122
|
-
/>
|
|
123
|
-
)}
|
|
123
|
+
{/* Media View - Hiển thị ảnh hoặc video */}
|
|
124
|
+
{((nativeAd.images?.length && nativeAd.images.length > 0) ||
|
|
125
|
+
nativeAd.mediaContent) && (
|
|
126
|
+
<NativeMediaView
|
|
127
|
+
style={[
|
|
128
|
+
styles.mediaView,
|
|
129
|
+
nativeAd.mediaContent?.aspectRatio
|
|
130
|
+
? { aspectRatio: nativeAd.mediaContent.aspectRatio }
|
|
131
|
+
: { aspectRatio: 16 / 9 },
|
|
132
|
+
]}
|
|
133
|
+
/>
|
|
134
|
+
)}
|
|
124
135
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
136
|
+
{/* Ad Content */}
|
|
137
|
+
<View style={styles.contentContainer}>
|
|
138
|
+
{nativeAd.icon && (
|
|
139
|
+
<NativeAsset assetType={NativeAssetType.ICON}>
|
|
140
|
+
<View style={styles.iconContainer}>
|
|
141
|
+
<Image
|
|
142
|
+
source={{ uri: nativeAd.icon?.url }}
|
|
143
|
+
style={styles.icon}
|
|
144
|
+
/>
|
|
145
|
+
</View>
|
|
146
|
+
</NativeAsset>
|
|
147
|
+
)}
|
|
148
|
+
<View style={styles.contentBody}>
|
|
149
|
+
<View style={styles.vHeader}>
|
|
150
|
+
<Text style={[styles.adBadge, adBadgeStyles]}>Ad</Text>
|
|
151
|
+
{nativeAd.headline && (
|
|
152
|
+
<NativeAsset assetType={NativeAssetType.HEADLINE}>
|
|
153
|
+
<Text
|
|
154
|
+
style={[styles.headline, headlineStyles]}
|
|
155
|
+
numberOfLines={1}
|
|
156
|
+
>
|
|
157
|
+
{nativeAd.headline}
|
|
158
|
+
</Text>
|
|
159
|
+
</NativeAsset>
|
|
160
|
+
)}
|
|
134
161
|
</View>
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
{nativeAd.headline && (
|
|
141
|
-
<NativeAsset assetType={NativeAssetType.HEADLINE}>
|
|
142
|
-
<Text
|
|
143
|
-
style={[styles.headline, headlineStyles]}
|
|
144
|
-
numberOfLines={1}
|
|
145
|
-
>
|
|
146
|
-
{nativeAd.headline}
|
|
162
|
+
|
|
163
|
+
{nativeAd.body && (
|
|
164
|
+
<NativeAsset assetType={NativeAssetType.BODY}>
|
|
165
|
+
<Text numberOfLines={2} style={[styles.bodyText, bodyStyles]}>
|
|
166
|
+
{nativeAd.body}
|
|
147
167
|
</Text>
|
|
148
168
|
</NativeAsset>
|
|
149
169
|
)}
|
|
150
170
|
</View>
|
|
151
|
-
|
|
152
|
-
{nativeAd.body && (
|
|
153
|
-
<NativeAsset assetType={NativeAssetType.BODY}>
|
|
154
|
-
<Text numberOfLines={2} style={[styles.bodyText, bodyStyles]}>
|
|
155
|
-
{nativeAd.body}
|
|
156
|
-
</Text>
|
|
157
|
-
</NativeAsset>
|
|
158
|
-
)}
|
|
159
171
|
</View>
|
|
160
|
-
</
|
|
161
|
-
|
|
172
|
+
</NativeAdView>
|
|
173
|
+
{isRefreshing && (
|
|
174
|
+
<View style={styles.refreshOverlay}>
|
|
175
|
+
<ActivityIndicator size="small" color="#FFFFFF" />
|
|
176
|
+
<Text style={styles.refreshText}>Đang tải quảng cáo mới...</Text>
|
|
177
|
+
</View>
|
|
178
|
+
)}
|
|
179
|
+
</View>
|
|
162
180
|
</View>
|
|
163
181
|
);
|
|
164
182
|
};
|
|
@@ -5,6 +5,10 @@ export const styles = StyleSheet.create({
|
|
|
5
5
|
width: '100%',
|
|
6
6
|
alignItems: 'center',
|
|
7
7
|
},
|
|
8
|
+
overlayContainer: {
|
|
9
|
+
width: '100%',
|
|
10
|
+
position: 'relative',
|
|
11
|
+
},
|
|
8
12
|
container: {
|
|
9
13
|
width: '100%',
|
|
10
14
|
backgroundColor: '#FFFFFF',
|
|
@@ -82,6 +86,9 @@ export const styles = StyleSheet.create({
|
|
|
82
86
|
alignItems: 'center',
|
|
83
87
|
padding: 12,
|
|
84
88
|
},
|
|
89
|
+
contentBody: {
|
|
90
|
+
flex: 1,
|
|
91
|
+
},
|
|
85
92
|
headline: {
|
|
86
93
|
fontSize: 16,
|
|
87
94
|
fontWeight: '700',
|
|
@@ -146,4 +153,17 @@ export const styles = StyleSheet.create({
|
|
|
146
153
|
flexDirection: 'row',
|
|
147
154
|
alignItems: 'center',
|
|
148
155
|
},
|
|
156
|
+
refreshOverlay: {
|
|
157
|
+
...StyleSheet.absoluteFillObject,
|
|
158
|
+
backgroundColor: 'rgba(0,0,0,0.35)',
|
|
159
|
+
justifyContent: 'center',
|
|
160
|
+
alignItems: 'center',
|
|
161
|
+
padding: 16,
|
|
162
|
+
},
|
|
163
|
+
refreshText: {
|
|
164
|
+
marginTop: 8,
|
|
165
|
+
fontSize: 12,
|
|
166
|
+
color: '#FFFFFF',
|
|
167
|
+
fontWeight: '500',
|
|
168
|
+
},
|
|
149
169
|
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { adjustTrackingManager } from '../analytics/AdjustTrackingManager';
|
|
2
|
+
import { analyticsManager } from '../analytics/AnalyticsManager';
|
|
3
|
+
|
|
4
|
+
export class ConfigManager {
|
|
5
|
+
private static instance: ConfigManager;
|
|
6
|
+
|
|
7
|
+
private constructor() {}
|
|
8
|
+
|
|
9
|
+
static getInstance(): ConfigManager {
|
|
10
|
+
if (!ConfigManager.instance) {
|
|
11
|
+
ConfigManager.instance = new ConfigManager();
|
|
12
|
+
}
|
|
13
|
+
return ConfigManager.instance;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
initAdjustTracking(
|
|
17
|
+
appToken: string,
|
|
18
|
+
environment: 'sandbox' | 'production' = 'production'
|
|
19
|
+
) {
|
|
20
|
+
adjustTrackingManager.initialize(appToken, environment);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
setEnableAdjustTracking(enable: boolean) {
|
|
24
|
+
adjustTrackingManager.setTrackingEnabled(enable);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
setEnableAnalyticsTracking(enable: boolean) {
|
|
28
|
+
analyticsManager.setEnabled(enable);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
setAdjustEventToken(eventToken: string) {
|
|
32
|
+
adjustTrackingManager.setEventToken(eventToken);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export const SdkConfig = ConfigManager.getInstance();
|
package/src/hook/useNativeAd.ts
CHANGED
|
@@ -36,6 +36,7 @@ export const useNativeAd = (config: UseNativeAdConfig) => {
|
|
|
36
36
|
const hasTriedHighPriority = useNativeAdStore((state) =>
|
|
37
37
|
state.hasTriedHighPriority(adKey)
|
|
38
38
|
);
|
|
39
|
+
const isRefreshing = useNativeAdStore((state) => state.isRefreshing(adKey));
|
|
39
40
|
|
|
40
41
|
// Zustand actions
|
|
41
42
|
const preloadAd = useNativeAdStore((state) => state.preloadAd);
|
|
@@ -121,8 +122,8 @@ export const useNativeAd = (config: UseNativeAdConfig) => {
|
|
|
121
122
|
useEffect(() => {
|
|
122
123
|
if (!ad || !onClicked) return;
|
|
123
124
|
|
|
124
|
-
const handleClick = (data:
|
|
125
|
-
if (data.
|
|
125
|
+
const handleClick = (data: { adKey?: string; adId?: string }) => {
|
|
126
|
+
if (data.adKey === ad.adKey) {
|
|
126
127
|
onClicked(ad);
|
|
127
128
|
}
|
|
128
129
|
};
|
|
@@ -138,8 +139,8 @@ export const useNativeAd = (config: UseNativeAdConfig) => {
|
|
|
138
139
|
useEffect(() => {
|
|
139
140
|
if (!ad || !onImpression) return;
|
|
140
141
|
|
|
141
|
-
const handleImpression = (data:
|
|
142
|
-
if (data.
|
|
142
|
+
const handleImpression = (data: { adKey?: string; adId?: string }) => {
|
|
143
|
+
if (data.adKey === ad.adKey) {
|
|
143
144
|
onImpression(ad);
|
|
144
145
|
}
|
|
145
146
|
};
|
|
@@ -160,6 +161,7 @@ export const useNativeAd = (config: UseNativeAdConfig) => {
|
|
|
160
161
|
isLoaded: ad?.status === AdStatus.LOADED,
|
|
161
162
|
isDisplayed: ad?.status === AdStatus.DISPLAYED,
|
|
162
163
|
hasError: ad?.status === AdStatus.ERROR,
|
|
164
|
+
isRefreshing,
|
|
163
165
|
isUsingHighPriority,
|
|
164
166
|
hasTriedHighPriority,
|
|
165
167
|
|
package/src/index.tsx
CHANGED
|
@@ -9,6 +9,8 @@ export { BannerAdComponent } from './components/BannerAdComponent';
|
|
|
9
9
|
export { NativeAdComponent } from './components/NativeAdComponent';
|
|
10
10
|
export { NativeAdFullscreenComponent } from './components/NativeAdFullscreenComponent';
|
|
11
11
|
|
|
12
|
+
export { SdkConfig } from './event/config';
|
|
13
|
+
|
|
12
14
|
// Export types
|
|
13
15
|
export type {
|
|
14
16
|
AdStatus,
|
|
@@ -9,6 +9,7 @@ interface NativeAdStore {
|
|
|
9
9
|
ads: Map<string, AdInstance>;
|
|
10
10
|
loadingKeys: Set<string>;
|
|
11
11
|
errors: Map<string, string>;
|
|
12
|
+
refreshingKeys: Set<string>;
|
|
12
13
|
|
|
13
14
|
// Actions - CHỈ NHẬN CONFIG OBJECT
|
|
14
15
|
preloadAd: (config: AdConfig) => Promise<void>;
|
|
@@ -27,11 +28,13 @@ interface NativeAdStore {
|
|
|
27
28
|
getErrorAds: () => AdInstance[];
|
|
28
29
|
isUsingHighPriority: (adKey: string) => boolean;
|
|
29
30
|
hasTriedHighPriority: (adKey: string) => boolean;
|
|
31
|
+
isRefreshing: (adKey: string) => boolean;
|
|
30
32
|
|
|
31
33
|
// Internal actions
|
|
32
34
|
_updateAd: (ad: AdInstance) => void;
|
|
33
35
|
_removeAd: (adKey: string) => void;
|
|
34
36
|
_setLoading: (adKey: string, loading: boolean) => void;
|
|
37
|
+
_setRefreshing: (adKey: string, refreshing: boolean) => void;
|
|
35
38
|
_setError: (adKey: string, error: string | null) => void;
|
|
36
39
|
_clearError: (adKey: string) => void;
|
|
37
40
|
}
|
|
@@ -42,6 +45,7 @@ export const useNativeAdStore = create<NativeAdStore>()(
|
|
|
42
45
|
ads: new Map(),
|
|
43
46
|
loadingKeys: new Set(),
|
|
44
47
|
errors: new Map(),
|
|
48
|
+
refreshingKeys: new Set(),
|
|
45
49
|
|
|
46
50
|
// Public actions
|
|
47
51
|
preloadAd: async (config) => {
|
|
@@ -94,7 +98,8 @@ export const useNativeAdStore = create<NativeAdStore>()(
|
|
|
94
98
|
|
|
95
99
|
refreshAd: async (adKey) => {
|
|
96
100
|
try {
|
|
97
|
-
get()._setLoading(adKey, true);
|
|
101
|
+
// get()._setLoading(adKey, true);
|
|
102
|
+
get()._setRefreshing(adKey, true);
|
|
98
103
|
get()._clearError(adKey);
|
|
99
104
|
|
|
100
105
|
await nativeAdsManager.refreshAd(adKey);
|
|
@@ -109,7 +114,8 @@ export const useNativeAdStore = create<NativeAdStore>()(
|
|
|
109
114
|
get()._setError(adKey, errorMessage);
|
|
110
115
|
console.error(`Failed to refresh ad ${adKey}:`, errorMessage);
|
|
111
116
|
} finally {
|
|
112
|
-
get()._setLoading(adKey, false);
|
|
117
|
+
// get()._setLoading(adKey, false);
|
|
118
|
+
get()._setRefreshing(adKey, false);
|
|
113
119
|
}
|
|
114
120
|
},
|
|
115
121
|
|
|
@@ -119,6 +125,7 @@ export const useNativeAdStore = create<NativeAdStore>()(
|
|
|
119
125
|
ads: new Map(),
|
|
120
126
|
loadingKeys: new Set(),
|
|
121
127
|
errors: new Map(),
|
|
128
|
+
refreshingKeys: new Set(),
|
|
122
129
|
});
|
|
123
130
|
},
|
|
124
131
|
|
|
@@ -161,6 +168,10 @@ export const useNativeAdStore = create<NativeAdStore>()(
|
|
|
161
168
|
return ad?.hasTriedHighPriority || false;
|
|
162
169
|
},
|
|
163
170
|
|
|
171
|
+
isRefreshing: (adKey) => {
|
|
172
|
+
return get().refreshingKeys.has(adKey);
|
|
173
|
+
},
|
|
174
|
+
|
|
164
175
|
// Internal actions - GIỮ NGUYÊN
|
|
165
176
|
_updateAd: (ad) => {
|
|
166
177
|
set((state) => ({
|
|
@@ -173,15 +184,18 @@ export const useNativeAdStore = create<NativeAdStore>()(
|
|
|
173
184
|
const newAds = new Map(state.ads);
|
|
174
185
|
const newLoadingKeys = new Set(state.loadingKeys);
|
|
175
186
|
const newErrors = new Map(state.errors);
|
|
187
|
+
const newRefreshing = new Set(state.refreshingKeys);
|
|
176
188
|
|
|
177
189
|
newAds.delete(adKey);
|
|
178
190
|
newLoadingKeys.delete(adKey);
|
|
179
191
|
newErrors.delete(adKey);
|
|
192
|
+
newRefreshing.delete(adKey);
|
|
180
193
|
|
|
181
194
|
return {
|
|
182
195
|
ads: newAds,
|
|
183
196
|
loadingKeys: newLoadingKeys,
|
|
184
197
|
errors: newErrors,
|
|
198
|
+
refreshingKeys: newRefreshing,
|
|
185
199
|
};
|
|
186
200
|
});
|
|
187
201
|
},
|
|
@@ -198,6 +212,18 @@ export const useNativeAdStore = create<NativeAdStore>()(
|
|
|
198
212
|
});
|
|
199
213
|
},
|
|
200
214
|
|
|
215
|
+
_setRefreshing: (adKey, refreshing) => {
|
|
216
|
+
set((state) => {
|
|
217
|
+
const newRefreshing = new Set(state.refreshingKeys);
|
|
218
|
+
if (refreshing) {
|
|
219
|
+
newRefreshing.add(adKey);
|
|
220
|
+
} else {
|
|
221
|
+
newRefreshing.delete(adKey);
|
|
222
|
+
}
|
|
223
|
+
return { refreshingKeys: newRefreshing };
|
|
224
|
+
});
|
|
225
|
+
},
|
|
226
|
+
|
|
201
227
|
_setError: (adKey, error) => {
|
|
202
228
|
set((state) => {
|
|
203
229
|
const newErrors = new Map(state.errors);
|
|
@@ -233,23 +259,32 @@ const setupNativeListeners = () => {
|
|
|
233
259
|
nativeAdsManager.on('adLoaded', (ad: AdInstance) => {
|
|
234
260
|
useNativeAdStore.getState()._updateAd(ad);
|
|
235
261
|
useNativeAdStore.getState()._setLoading(ad.adKey, false);
|
|
262
|
+
useNativeAdStore.getState()._setRefreshing(ad.adKey, false);
|
|
236
263
|
useNativeAdStore.getState()._clearError(ad.adKey);
|
|
237
264
|
});
|
|
238
265
|
|
|
239
266
|
nativeAdsManager.on('adDisplayed', (ad: AdInstance) => {
|
|
240
267
|
useNativeAdStore.getState()._updateAd(ad);
|
|
268
|
+
useNativeAdStore.getState()._setRefreshing(ad.adKey, false);
|
|
241
269
|
});
|
|
242
270
|
|
|
243
271
|
nativeAdsManager.on('adError', (ad: AdInstance) => {
|
|
244
272
|
useNativeAdStore.getState()._updateAd(ad);
|
|
245
273
|
useNativeAdStore.getState()._setLoading(ad.adKey, false);
|
|
274
|
+
useNativeAdStore.getState()._setRefreshing(ad.adKey, false);
|
|
246
275
|
useNativeAdStore
|
|
247
276
|
.getState()
|
|
248
277
|
._setError(ad.adKey, ad.error || 'Unknown error');
|
|
249
278
|
});
|
|
250
279
|
|
|
280
|
+
nativeAdsManager.on('adRefreshing', (ad: AdInstance) => {
|
|
281
|
+
useNativeAdStore.getState()._updateAd(ad);
|
|
282
|
+
useNativeAdStore.getState()._setRefreshing(ad.adKey, true);
|
|
283
|
+
});
|
|
284
|
+
|
|
251
285
|
nativeAdsManager.on('adRemoved', (adKey: string) => {
|
|
252
286
|
useNativeAdStore.getState()._removeAd(adKey);
|
|
287
|
+
useNativeAdStore.getState()._setRefreshing(adKey, false);
|
|
253
288
|
});
|
|
254
289
|
|
|
255
290
|
nativeAdsManager.on('allAdsCleared', () => {
|
package/src/types/ads-types.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export enum AdStatus {
|
|
2
2
|
IDLE = 'idle',
|
|
3
3
|
LOADING = 'loading',
|
|
4
|
+
REFRESHING = 'refreshing',
|
|
4
5
|
LOADED = 'loaded',
|
|
5
6
|
DISPLAYED = 'displayed',
|
|
6
7
|
ERROR = 'error',
|
|
@@ -45,12 +46,14 @@ export interface AdInstance {
|
|
|
45
46
|
retryCount: number;
|
|
46
47
|
isUsingHighPriority?: boolean; // Track xem đang load high priority hay không
|
|
47
48
|
hasTriedHighPriority?: boolean; // Track xem đã thử high priority chưa
|
|
49
|
+
isRefreshing?: boolean;
|
|
48
50
|
}
|
|
49
51
|
|
|
50
52
|
export interface AdManagerState {
|
|
51
53
|
ads: Map<string, AdInstance>;
|
|
52
54
|
loadingKeys: Set<string>;
|
|
53
55
|
displayedKeys: Set<string>;
|
|
56
|
+
refreshingKeys: Set<string>;
|
|
54
57
|
}
|
|
55
58
|
|
|
56
59
|
export interface AdManagerActions {
|
|
@@ -164,6 +167,7 @@ export interface GenericAdManagerState {
|
|
|
164
167
|
ads: Map<string, AnyAdInstance>;
|
|
165
168
|
loadingKeys: Set<string>;
|
|
166
169
|
displayedKeys: Set<string>;
|
|
170
|
+
refreshingKeys: Set<string>;
|
|
167
171
|
}
|
|
168
172
|
|
|
169
173
|
export interface GenericAdManagerActions {
|