@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.
Files changed (2) hide show
  1. package/dist/index.js +49 -38
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { jsx, jsxs } from 'react/jsx-runtime';
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
- if (!client || !slot) {
91
- log('client ou slot não informado');
92
- return;
93
- }
94
- log('Carregando anúncio', { client, slot });
95
- fetchAd({ baseUrl, client, slot, debug })
96
- .then((data) => {
97
- log('Anúncio recebido', data);
98
- if (!data || !data.image) {
99
- setError('Anúncio inválido');
100
- return;
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
- setAd(data);
103
- })
104
- .catch((err) => {
105
- console.error('[UPEEX ADS] Erro', err);
106
- setError('Erro ao carregar anúncio');
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 (jsxs(TouchableOpacity, { activeOpacity: 0.9, onPress: handlePress, style: [styles.container, theme === 'dark' && styles.dark, style], children: [jsx(Text, { style: [styles.label, theme === 'dark' && styles.darkText], children: "Publicidade" }), jsx(Image, { source: { uri: ad.image }, style: {
127
- width: ad.width || 320,
128
- height: ad.height || 50,
129
- resizeMode: 'contain',
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
- padding: 10,
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,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@upeex/ads-sdk",
3
- "version": "1.1.7",
3
+ "version": "1.1.9",
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",