@upeex/ads-sdk 1.1.7 → 1.1.9
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/dist/index.js +49 -38
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { jsx
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
2
|
import { useState, useEffect } from 'react';
|
|
3
3
|
import { Platform, Dimensions, StyleSheet, View, Text, TouchableOpacity, Image, Linking } from 'react-native';
|
|
4
4
|
|
|
@@ -79,7 +79,7 @@ async function fetchAd({ baseUrl, client, slot, display = 'BANNER', debug = fals
|
|
|
79
79
|
return ad;
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
function AdBanner({ client, slot, baseUrl = 'https://app.upeex.com.br', theme = 'light', style = {}, debug = false, }) {
|
|
82
|
+
function AdBanner({ client, slot, baseUrl = 'https://app.upeex.com.br/ad', theme = 'light', style = {}, debug = false, }) {
|
|
83
83
|
const [ad, setAd] = useState(null);
|
|
84
84
|
const [error, setError] = useState(null);
|
|
85
85
|
const log = (...args) => {
|
|
@@ -87,30 +87,46 @@ function AdBanner({ client, slot, baseUrl = 'https://app.upeex.com.br', theme =
|
|
|
87
87
|
console.log('[UPEEX ADS]', ...args);
|
|
88
88
|
};
|
|
89
89
|
useEffect(() => {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
90
|
+
let refreshTimer;
|
|
91
|
+
const load = async () => {
|
|
92
|
+
try {
|
|
93
|
+
log('Buscando anúncio', { client, slot });
|
|
94
|
+
const data = await fetchAd({ baseUrl, client, slot, debug });
|
|
95
|
+
log('Resposta do servidor', data);
|
|
96
|
+
if (!data || !data.image) {
|
|
97
|
+
setError('Nenhum anúncio disponível');
|
|
98
|
+
setAd(null);
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
setAd(data);
|
|
102
|
+
setError(null);
|
|
103
|
+
if (data.refresh && data.refresh > 0) {
|
|
104
|
+
log(`Refresh ativo: ${data.refresh}s`);
|
|
105
|
+
refreshTimer = setTimeout(() => {
|
|
106
|
+
log('Refazendo request do anúncio');
|
|
107
|
+
load();
|
|
108
|
+
}, data.refresh * 1000);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
catch (err) {
|
|
112
|
+
console.error('[UPEEX ADS] Erro ao carregar anúncio', err);
|
|
113
|
+
setError('Erro ao carregar anúncio');
|
|
114
|
+
setAd(null);
|
|
101
115
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
116
|
+
};
|
|
117
|
+
if (client && slot) {
|
|
118
|
+
load();
|
|
119
|
+
}
|
|
120
|
+
return () => {
|
|
121
|
+
if (refreshTimer)
|
|
122
|
+
clearTimeout(refreshTimer);
|
|
123
|
+
};
|
|
108
124
|
}, [client, slot, baseUrl]);
|
|
109
125
|
if (error) {
|
|
110
126
|
return debug ? (jsx(View, { style: [styles.container, styles.debug], children: jsx(Text, { style: styles.debugText, children: error }) })) : null;
|
|
111
127
|
}
|
|
112
128
|
if (!ad) {
|
|
113
|
-
return debug ? (jsx(View, { style: styles.loading, children: jsx(Text, { style: styles.loadingText, children: "Carregando an\u00FAncio\u2026" }) })) : null;
|
|
129
|
+
return debug ? (jsx(View, { style: [styles.container, styles.loading], children: jsx(Text, { style: styles.loadingText, children: "Carregando an\u00FAncio\u2026" }) })) : null;
|
|
114
130
|
}
|
|
115
131
|
const handlePress = () => {
|
|
116
132
|
log('Clique no anúncio', ad.clickUrl);
|
|
@@ -123,32 +139,28 @@ function AdBanner({ client, slot, baseUrl = 'https://app.upeex.com.br', theme =
|
|
|
123
139
|
Linking.openURL(ad.clickUrl);
|
|
124
140
|
}
|
|
125
141
|
};
|
|
126
|
-
return (
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
142
|
+
return (jsx(TouchableOpacity, { activeOpacity: 0.9, style: [
|
|
143
|
+
styles.container,
|
|
144
|
+
theme === 'dark' && styles.dark,
|
|
145
|
+
style,
|
|
146
|
+
], onPress: handlePress, children: jsx(Image, { source: { uri: ad.image }, style: {
|
|
147
|
+
width: ad.width || 320,
|
|
148
|
+
height: ad.height || 50,
|
|
149
|
+
resizeMode: 'contain',
|
|
150
|
+
} }) }));
|
|
131
151
|
}
|
|
132
152
|
const styles = StyleSheet.create({
|
|
133
153
|
container: {
|
|
134
|
-
alignItems: 'center',
|
|
135
|
-
paddingVertical: 6,
|
|
136
154
|
backgroundColor: '#f2f2f2',
|
|
155
|
+
padding: 8,
|
|
156
|
+
alignItems: 'center',
|
|
157
|
+
justifyContent: 'center',
|
|
137
158
|
},
|
|
138
159
|
dark: {
|
|
139
160
|
backgroundColor: '#121212',
|
|
140
161
|
},
|
|
141
|
-
label: {
|
|
142
|
-
fontSize: 10,
|
|
143
|
-
color: '#666',
|
|
144
|
-
marginBottom: 4,
|
|
145
|
-
},
|
|
146
|
-
darkText: {
|
|
147
|
-
color: '#aaa',
|
|
148
|
-
},
|
|
149
162
|
loading: {
|
|
150
|
-
|
|
151
|
-
alignItems: 'center',
|
|
163
|
+
backgroundColor: '#fafafa',
|
|
152
164
|
},
|
|
153
165
|
loadingText: {
|
|
154
166
|
fontSize: 11,
|
|
@@ -156,7 +168,6 @@ const styles = StyleSheet.create({
|
|
|
156
168
|
},
|
|
157
169
|
debug: {
|
|
158
170
|
backgroundColor: '#ffecec',
|
|
159
|
-
padding: 8,
|
|
160
171
|
},
|
|
161
172
|
debugText: {
|
|
162
173
|
fontSize: 11,
|