@upeex/ads-sdk 1.1.14 → 1.1.16
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/README.md +32 -7
- package/dist/AdBanner.d.ts +1 -1
- package/dist/index.js +97 -14
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -4,13 +4,38 @@ SDK para aplicaçõe React Native rodarem anúncios:
|
|
|
4
4
|
# Comando para inciar
|
|
5
5
|
npm i @upeex/ads-sdk
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
## Como usar
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
### Importação
|
|
10
|
+
|
|
11
|
+
```javascript
|
|
10
12
|
import AdBanner from '@upeex/ads-sdk';
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
### 1. Anúncio Tipo Banner (Padrão)
|
|
16
|
+
Exibe um banner na posição onde o componente é colocado.
|
|
17
|
+
|
|
18
|
+
```javascript
|
|
19
|
+
<AdBanner
|
|
20
|
+
client="CLIENT_ID"
|
|
21
|
+
slot="SLOT_ID"
|
|
22
|
+
typeAds="banner" // Opcional (padrão é banner)
|
|
23
|
+
/>
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### 2. Anúncio Tipo Popup (Tela Cheia)
|
|
27
|
+
Exibe um modal em tela cheia sobrepondo o conteúdo.
|
|
28
|
+
- O botão de fechar aparece após **5 segundos**.
|
|
29
|
+
- Não possui refresh automático.
|
|
30
|
+
|
|
31
|
+
```javascript
|
|
32
|
+
<AdBanner
|
|
33
|
+
client="CLIENT_ID"
|
|
34
|
+
slot="SLOT_ID"
|
|
35
|
+
typeAds="popup"
|
|
36
|
+
/>
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Props Disponíveis
|
|
11
40
|
|
|
12
|
-
|
|
13
|
-
<AdBanner
|
|
14
|
-
client="SEU_CLIENTE"
|
|
15
|
-
slot="SEU_SLOT"
|
|
16
|
-
/
|
|
41
|
+
| `debug` | `boolean` | Ativa logs no console |
|
package/dist/AdBanner.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { jsx } from 'react/jsx-runtime';
|
|
2
|
-
import { useState, useEffect } from 'react';
|
|
3
|
-
import { Platform, Dimensions, StyleSheet, View, Text, TouchableOpacity, Image, Linking } from 'react-native';
|
|
1
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
2
|
+
import { useState, useRef, useEffect } from 'react';
|
|
3
|
+
import { Platform, Dimensions, Animated, StyleSheet, View, Text, Modal, TouchableOpacity, Image, ActivityIndicator, Linking } from 'react-native';
|
|
4
4
|
|
|
5
5
|
async function getSignals() {
|
|
6
6
|
var _a, _b, _c, _d, _e, _f;
|
|
@@ -79,10 +79,20 @@ async function fetchAd({ baseUrl, client, slot, debug = false, typeAds, }) {
|
|
|
79
79
|
return ad;
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
+
const { width: screenWidth, height: screenHeight } = Dimensions.get('window');
|
|
83
|
+
// Workaround for TS2604: JSX element type 'Animated.View' does not have any construct or call signatures.
|
|
84
|
+
const AnimatedView = Animated.View;
|
|
82
85
|
function AdBanner({ client, slot, baseUrl = 'https://app.upeex.com.br/ad', theme = 'light', typeAds, typeads, // Receive alias
|
|
83
86
|
style = {}, debug = false, }) {
|
|
87
|
+
var _a;
|
|
84
88
|
const [ad, setAd] = useState(null);
|
|
85
89
|
const [error, setError] = useState(null);
|
|
90
|
+
const [modalVisible, setModalVisible] = useState(false);
|
|
91
|
+
const [canClose, setCanClose] = useState(false);
|
|
92
|
+
const progressAnim = useRef(new Animated.Value(0)).current;
|
|
93
|
+
// Normalize typeAds: prefer typeAds, fallback to typeads, default undefined.
|
|
94
|
+
// Ensure lowercase for backend compatibility (POPUP -> popup)
|
|
95
|
+
const effectiveTypeAds = (_a = (typeAds || typeads)) === null || _a === void 0 ? void 0 : _a.toLowerCase();
|
|
86
96
|
const log = (...args) => {
|
|
87
97
|
if (debug)
|
|
88
98
|
console.log('[UPEEX ADS]', ...args);
|
|
@@ -90,12 +100,8 @@ style = {}, debug = false, }) {
|
|
|
90
100
|
useEffect(() => {
|
|
91
101
|
let refreshTimer;
|
|
92
102
|
const load = async () => {
|
|
93
|
-
var _a;
|
|
94
103
|
try {
|
|
95
104
|
log('Buscando anúncio', { client, slot });
|
|
96
|
-
// Normalize typeAds: prefer typeAds, fallback to typeads, default undefined.
|
|
97
|
-
// Ensure lowercase for backend compatibility (POPUP -> popup)
|
|
98
|
-
const effectiveTypeAds = (_a = (typeAds || typeads)) === null || _a === void 0 ? void 0 : _a.toLowerCase();
|
|
99
105
|
const data = await fetchAd({
|
|
100
106
|
baseUrl,
|
|
101
107
|
client,
|
|
@@ -111,12 +117,29 @@ style = {}, debug = false, }) {
|
|
|
111
117
|
}
|
|
112
118
|
setAd(data);
|
|
113
119
|
setError(null);
|
|
114
|
-
if (
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
+
if (effectiveTypeAds === 'popup') {
|
|
121
|
+
setModalVisible(true);
|
|
122
|
+
setCanClose(false);
|
|
123
|
+
progressAnim.setValue(0);
|
|
124
|
+
Animated.timing(progressAnim, {
|
|
125
|
+
toValue: 1,
|
|
126
|
+
duration: 5000,
|
|
127
|
+
useNativeDriver: false,
|
|
128
|
+
}).start(({ finished }) => {
|
|
129
|
+
if (finished) {
|
|
130
|
+
setCanClose(true);
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
// Only enable refresh if it's NOT a popup
|
|
135
|
+
if (effectiveTypeAds !== 'popup') {
|
|
136
|
+
if (data.refresh && data.refresh > 0) {
|
|
137
|
+
log(`Refresh ativo: ${data.refresh}s`);
|
|
138
|
+
refreshTimer = setTimeout(() => {
|
|
139
|
+
log('Refazendo request do anúncio');
|
|
140
|
+
load();
|
|
141
|
+
}, data.refresh * 1000);
|
|
142
|
+
}
|
|
120
143
|
}
|
|
121
144
|
}
|
|
122
145
|
catch (err) {
|
|
@@ -132,7 +155,7 @@ style = {}, debug = false, }) {
|
|
|
132
155
|
if (refreshTimer)
|
|
133
156
|
clearTimeout(refreshTimer);
|
|
134
157
|
};
|
|
135
|
-
}, [client, slot, baseUrl]);
|
|
158
|
+
}, [client, slot, baseUrl, effectiveTypeAds]);
|
|
136
159
|
if (error) {
|
|
137
160
|
return debug ? (jsx(View, { style: [styles.container, styles.debug], children: jsx(Text, { style: styles.debugText, children: error }) })) : null;
|
|
138
161
|
}
|
|
@@ -150,6 +173,20 @@ style = {}, debug = false, }) {
|
|
|
150
173
|
Linking.openURL(ad.clickUrl);
|
|
151
174
|
}
|
|
152
175
|
};
|
|
176
|
+
if (effectiveTypeAds === 'popup') {
|
|
177
|
+
return (jsx(Modal, { visible: modalVisible, transparent: true, animationType: "fade", onRequestClose: () => {
|
|
178
|
+
if (canClose)
|
|
179
|
+
setModalVisible(false);
|
|
180
|
+
}, children: jsxs(View, { style: styles.modalBackground, children: [!canClose && (jsx(View, { style: styles.progressBarContainer, children: jsx(AnimatedView, { style: [
|
|
181
|
+
styles.progressBar,
|
|
182
|
+
{
|
|
183
|
+
width: progressAnim.interpolate({
|
|
184
|
+
inputRange: [0, 1],
|
|
185
|
+
outputRange: ['0%', '100%'],
|
|
186
|
+
}),
|
|
187
|
+
},
|
|
188
|
+
] }) })), jsx(TouchableOpacity, { style: styles.fullScreenTouch, activeOpacity: 1, onPress: handlePress, children: jsx(Image, { source: { uri: ad.image }, style: styles.fullScreenImage, resizeMode: "contain" }) }), jsx(TouchableOpacity, { style: styles.closeButton, onPress: () => setModalVisible(false), disabled: !canClose, children: !canClose ? (jsx(ActivityIndicator, { size: "small", color: "#fff" })) : (jsx(Text, { style: styles.closeButtonText, children: "X" })) })] }) }));
|
|
189
|
+
}
|
|
153
190
|
return (jsx(TouchableOpacity, { activeOpacity: 0.9, style: [
|
|
154
191
|
styles.container,
|
|
155
192
|
theme === 'dark' && styles.dark,
|
|
@@ -184,6 +221,52 @@ const styles = StyleSheet.create({
|
|
|
184
221
|
fontSize: 11,
|
|
185
222
|
color: '#c00',
|
|
186
223
|
},
|
|
224
|
+
modalBackground: {
|
|
225
|
+
flex: 1,
|
|
226
|
+
backgroundColor: 'rgba(0,0,0,0.9)',
|
|
227
|
+
justifyContent: 'center',
|
|
228
|
+
alignItems: 'center',
|
|
229
|
+
},
|
|
230
|
+
fullScreenTouch: {
|
|
231
|
+
flex: 1,
|
|
232
|
+
width: '100%',
|
|
233
|
+
height: '100%',
|
|
234
|
+
justifyContent: 'center',
|
|
235
|
+
alignItems: 'center',
|
|
236
|
+
},
|
|
237
|
+
fullScreenImage: {
|
|
238
|
+
width: '90%',
|
|
239
|
+
height: '90%',
|
|
240
|
+
},
|
|
241
|
+
closeButton: {
|
|
242
|
+
position: 'absolute',
|
|
243
|
+
top: 50,
|
|
244
|
+
right: 20,
|
|
245
|
+
backgroundColor: 'rgba(0,0,0,0.6)',
|
|
246
|
+
width: 40,
|
|
247
|
+
height: 40,
|
|
248
|
+
borderRadius: 20,
|
|
249
|
+
justifyContent: 'center',
|
|
250
|
+
alignItems: 'center',
|
|
251
|
+
zIndex: 999,
|
|
252
|
+
},
|
|
253
|
+
closeButtonText: {
|
|
254
|
+
color: '#fff',
|
|
255
|
+
fontSize: 18,
|
|
256
|
+
fontWeight: 'bold',
|
|
257
|
+
},
|
|
258
|
+
progressBarContainer: {
|
|
259
|
+
position: 'absolute',
|
|
260
|
+
top: 0,
|
|
261
|
+
left: 0,
|
|
262
|
+
width: '100%',
|
|
263
|
+
height: 5,
|
|
264
|
+
backgroundColor: 'rgba(255,255,255,0.3)',
|
|
265
|
+
zIndex: 1000,
|
|
266
|
+
},
|
|
267
|
+
progressBar: {
|
|
268
|
+
height: '100%',
|
|
269
|
+
},
|
|
187
270
|
});
|
|
188
271
|
|
|
189
272
|
export { AdBanner, AdBanner as default };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@upeex/ads-sdk",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.16",
|
|
4
4
|
"description": "Upeex Ads SDK for React Native and universal apps",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -27,13 +27,14 @@
|
|
|
27
27
|
"author": "Upeex",
|
|
28
28
|
"license": "MIT",
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@upeex/ads-sdk": "^1.1.10",
|
|
31
30
|
"expo-localization": "^17.0.8"
|
|
32
31
|
},
|
|
33
32
|
"devDependencies": {
|
|
33
|
+
"@types/react": "^19.2.13",
|
|
34
|
+
"@types/react-native": "^0.73.0",
|
|
34
35
|
"rollup": "^4.57.0",
|
|
35
36
|
"rollup-plugin-typescript2": "^0.36.0",
|
|
36
37
|
"tslib": "^2.8.1",
|
|
37
38
|
"typescript": "^5.9.3"
|
|
38
39
|
}
|
|
39
|
-
}
|
|
40
|
+
}
|