@kontextso/sdk-react-native 3.2.0-rc.2 → 3.2.0-rc.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/dist/index.mjs CHANGED
@@ -1,57 +1,48 @@
1
1
  // ../sdk-common/dist/index.mjs
2
2
  function makeIframeMessage(type, opts) {
3
- const { data, code, component } = opts;
4
- const message = { type, data: { ...data || {}, code, component } };
5
- return message;
3
+ const { data, code, component } = opts
4
+ const message = { type, data: { ...(data || {}), code, component } }
5
+ return message
6
6
  }
7
7
  function handleIframeMessage(handler, opts) {
8
- const { origin, code, component } = opts;
8
+ const { origin, code, component } = opts
9
9
  return (event) => {
10
- var _a, _b;
11
- if (origin && event.origin !== origin) return;
12
- const eventCode = (_a = event.data.data) == null ? void 0 : _a.code;
13
- if (eventCode && code && eventCode !== code) return;
14
- const eventComponent = (_b = event.data.data) == null ? void 0 : _b.component;
15
- if (eventComponent && component && eventComponent !== component) return;
16
- handler(event.data);
17
- };
10
+ var _a, _b
11
+ if (origin && event.origin !== origin) return
12
+ const eventCode = (_a = event.data.data) == null ? void 0 : _a.code
13
+ if (eventCode && code && eventCode !== code) return
14
+ const eventComponent = (_b = event.data.data) == null ? void 0 : _b.component
15
+ if (eventComponent && component && eventComponent !== component) return
16
+ handler(event.data)
17
+ }
18
18
  }
19
19
 
20
20
  // src/formats/Format.tsx
21
- import {
22
- AdsContext,
23
- convertParamsToString,
24
- ErrorBoundary,
25
- useBid,
26
- useIframeUrl
27
- } from "@kontextso/sdk-react";
28
- import { useContext, useEffect, useRef, useState } from "react";
29
- import { Keyboard, Linking, Modal, useWindowDimensions, View } from "react-native";
21
+ import { AdsContext, convertParamsToString, ErrorBoundary, useBid, useIframeUrl } from '@kontextso/sdk-react'
22
+ import { useContext, useEffect, useRef, useState } from 'react'
23
+ import { Keyboard, Linking, Modal, useWindowDimensions, View } from 'react-native'
30
24
 
31
25
  // src/frame-webview.tsx
32
- import { forwardRef } from "react";
33
- import { WebView } from "react-native-webview";
34
- import { jsx } from "react/jsx-runtime";
35
- var FrameWebView = forwardRef(
36
- ({ iframeUrl, onMessage, style, onError, onLoad }, forwardedRef) => {
37
- return /* @__PURE__ */ jsx(
38
- WebView,
39
- {
40
- ref: forwardedRef,
41
- source: {
42
- uri: iframeUrl
43
- },
44
- onMessage,
45
- style,
46
- allowsInlineMediaPlayback: true,
47
- mediaPlaybackRequiresUserAction: false,
48
- javaScriptEnabled: true,
49
- domStorageEnabled: true,
50
- allowsFullscreenVideo: false,
51
- originWhitelist: ["*"],
52
- sharedCookiesEnabled: true,
53
- thirdPartyCookiesEnabled: true,
54
- injectedJavaScript: `
26
+ import { forwardRef } from 'react'
27
+ import { WebView } from 'react-native-webview'
28
+ import { jsx } from 'react/jsx-runtime'
29
+ var FrameWebView = forwardRef(({ iframeUrl, onMessage, style, onError, onLoad }, forwardedRef) => {
30
+ return /* @__PURE__ */ jsx(WebView, {
31
+ ref: forwardedRef,
32
+ source: {
33
+ uri: iframeUrl,
34
+ },
35
+ onMessage,
36
+ style,
37
+ allowsInlineMediaPlayback: true,
38
+ mediaPlaybackRequiresUserAction: false,
39
+ javaScriptEnabled: true,
40
+ domStorageEnabled: true,
41
+ allowsFullscreenVideo: false,
42
+ originWhitelist: ['*'],
43
+ sharedCookiesEnabled: true,
44
+ thirdPartyCookiesEnabled: true,
45
+ injectedJavaScript: `
55
46
  window.addEventListener("message", function(event) {
56
47
  if (window.ReactNativeWebView && event.data) {
57
48
  // ReactNativeWebView.postMessage only supports string data
@@ -59,135 +50,133 @@ var FrameWebView = forwardRef(
59
50
  }
60
51
  }, false);
61
52
  `,
62
- onError,
63
- onLoad
64
- }
65
- );
66
- }
67
- );
68
- var frame_webview_default = FrameWebView;
53
+ onError,
54
+ onLoad,
55
+ })
56
+ })
57
+ var frame_webview_default = FrameWebView
69
58
 
70
59
  // src/services/SkOverlay.ts
71
- import { Platform } from "react-native";
60
+ import { Platform } from 'react-native'
72
61
 
73
62
  // src/NativeRNKontext.ts
74
- import { TurboModuleRegistry } from "react-native";
75
- var NativeRNKontext_default = TurboModuleRegistry.getEnforcing("RNKontext");
63
+ import { TurboModuleRegistry } from 'react-native'
64
+ var NativeRNKontext_default = TurboModuleRegistry.getEnforcing('RNKontext')
76
65
 
77
66
  // src/services/utils.ts
78
67
  var isValidAppStoreId = (id) => {
79
- return typeof id === "string" && /^\d+$/.test(id);
80
- };
68
+ return typeof id === 'string' && /^\d+$/.test(id)
69
+ }
81
70
 
82
71
  // src/services/SkOverlay.ts
83
72
  var isValidPosition = (p) => {
84
- return p === "bottom" || p === "bottomRaised";
85
- };
73
+ return p === 'bottom' || p === 'bottomRaised'
74
+ }
86
75
  async function presentSKOverlay(params) {
87
- if (Platform.OS !== "ios") {
88
- return false;
76
+ if (Platform.OS !== 'ios') {
77
+ return false
89
78
  }
90
- let { appStoreId, position, dismissible } = params;
79
+ let { appStoreId, position, dismissible } = params
91
80
  if (!isValidAppStoreId(appStoreId)) {
92
- return false;
81
+ return false
93
82
  }
94
83
  if (!isValidPosition(position)) {
95
- position = "bottom";
84
+ position = 'bottom'
96
85
  }
97
- if (typeof dismissible !== "boolean") {
98
- dismissible = Boolean(dismissible);
86
+ if (typeof dismissible !== 'boolean') {
87
+ dismissible = Boolean(dismissible)
99
88
  }
100
- return NativeRNKontext_default.presentSKOverlay(appStoreId, position, dismissible);
89
+ return NativeRNKontext_default.presentSKOverlay(appStoreId, position, dismissible)
101
90
  }
102
91
  async function dismissSKOverlay() {
103
- if (Platform.OS !== "ios") {
104
- return false;
92
+ if (Platform.OS !== 'ios') {
93
+ return false
105
94
  }
106
- return NativeRNKontext_default.dismissSKOverlay();
95
+ return NativeRNKontext_default.dismissSKOverlay()
107
96
  }
108
97
 
109
98
  // src/services/SkStoreProduct.ts
110
- import { Platform as Platform2 } from "react-native";
99
+ import { Platform as Platform2 } from 'react-native'
111
100
  async function presentSKStoreProduct(appStoreId) {
112
- if (Platform2.OS !== "ios") {
113
- return false;
101
+ if (Platform2.OS !== 'ios') {
102
+ return false
114
103
  }
115
104
  if (!isValidAppStoreId(appStoreId)) {
116
- return false;
105
+ return false
117
106
  }
118
- return NativeRNKontext_default.presentSKStoreProduct(appStoreId);
107
+ return NativeRNKontext_default.presentSKStoreProduct(appStoreId)
119
108
  }
120
109
  async function dismissSKStoreProduct() {
121
- if (Platform2.OS !== "ios") {
122
- return false;
110
+ if (Platform2.OS !== 'ios') {
111
+ return false
123
112
  }
124
- return NativeRNKontext_default.dismissSKStoreProduct();
113
+ return NativeRNKontext_default.dismissSKStoreProduct()
125
114
  }
126
115
 
127
116
  // src/formats/Format.tsx
128
- import { Fragment, jsx as jsx2, jsxs } from "react/jsx-runtime";
117
+ import { Fragment, jsx as jsx2, jsxs } from 'react/jsx-runtime'
129
118
  var sendMessage = (webViewRef, type, code, data) => {
130
119
  const message = makeIframeMessage(type, {
131
120
  data,
132
- code
133
- });
121
+ code,
122
+ })
134
123
  webViewRef.current?.injectJavaScript(`
135
124
  window.dispatchEvent(new MessageEvent('message', {
136
125
  data: ${JSON.stringify(message)}
137
126
  }));
138
- `);
139
- };
127
+ `)
128
+ }
140
129
  var getCachedContent = (context, bidId) => {
141
130
  if (!bidId) {
142
- return null;
131
+ return null
143
132
  }
144
- return context?.cachedContentRef?.current?.get(bidId) ?? null;
145
- };
133
+ return context?.cachedContentRef?.current?.get(bidId) ?? null
134
+ }
146
135
  var Format = ({ code, messageId, wrapper, onEvent, ...otherParams }) => {
147
- const context = useContext(AdsContext);
148
- const bid = useBid({ code, messageId });
149
- const [height, setHeight] = useState(0);
150
- const cachedContent = getCachedContent(context, bid?.bidId);
151
- const iframeUrl = useIframeUrl(bid, code, messageId, "sdk-react-native", otherParams.theme, cachedContent);
152
- const modalUrl = iframeUrl.replace("/api/frame/", "/api/modal/");
153
- const [showIframe, setShowIframe] = useState(false);
154
- const [iframeLoaded, setIframeLoaded] = useState(false);
155
- const [modalOpen, setModalOpen] = useState(false);
156
- const [modalShown, setModalShown] = useState(false);
157
- const [modalLoaded, setModalLoaded] = useState(false);
158
- const [containerStyles, setContainerStyles] = useState({});
159
- const [iframeStyles, setIframeStyles] = useState({});
160
- const containerRef = useRef(null);
161
- const webViewRef = useRef(null);
162
- const modalWebViewRef = useRef(null);
163
- const messageStatusRef = useRef("none" /* None */);
164
- const modalInitTimeoutRef = useRef(null);
165
- const isModalInitRef = useRef(false);
166
- const { height: windowHeight, width: windowWidth } = useWindowDimensions();
167
- const keyboardHeightRef = useRef(0);
168
- const isAdViewVisible = showIframe && iframeLoaded;
136
+ const context = useContext(AdsContext)
137
+ const bid = useBid({ code, messageId })
138
+ const [height, setHeight] = useState(0)
139
+ const cachedContent = getCachedContent(context, bid?.bidId)
140
+ const iframeUrl = useIframeUrl(bid, code, messageId, 'sdk-react-native', otherParams.theme, cachedContent)
141
+ const modalUrl = iframeUrl.replace('/api/frame/', '/api/modal/')
142
+ const [showIframe, setShowIframe] = useState(false)
143
+ const [iframeLoaded, setIframeLoaded] = useState(false)
144
+ const [modalOpen, setModalOpen] = useState(false)
145
+ const [modalShown, setModalShown] = useState(false)
146
+ const [modalLoaded, setModalLoaded] = useState(false)
147
+ const [containerStyles, setContainerStyles] = useState({})
148
+ const [iframeStyles, setIframeStyles] = useState({})
149
+ const containerRef = useRef(null)
150
+ const webViewRef = useRef(null)
151
+ const modalWebViewRef = useRef(null)
152
+ const messageStatusRef = useRef('none' /* None */)
153
+ const modalInitTimeoutRef = useRef(null)
154
+ const isModalInitRef = useRef(false)
155
+ const { height: windowHeight, width: windowWidth } = useWindowDimensions()
156
+ const keyboardHeightRef = useRef(0)
157
+ const isAdViewVisible = showIframe && iframeLoaded
169
158
  const reset = () => {
170
- setHeight(0);
171
- setShowIframe(false);
172
- setContainerStyles({});
173
- setIframeStyles({});
174
- setIframeLoaded(false);
175
- resetModal();
176
- context?.resetAll();
177
- context?.captureError(new Error("Processing iframe error"));
178
- };
159
+ setHeight(0)
160
+ setShowIframe(false)
161
+ setContainerStyles({})
162
+ setIframeStyles({})
163
+ setIframeLoaded(false)
164
+ resetModal()
165
+ context?.resetAll()
166
+ context?.captureError(new Error('Processing iframe error'))
167
+ }
179
168
  const resetModal = () => {
180
169
  if (modalInitTimeoutRef.current) {
181
- clearTimeout(modalInitTimeoutRef.current);
182
- modalInitTimeoutRef.current = null;
170
+ clearTimeout(modalInitTimeoutRef.current)
171
+ modalInitTimeoutRef.current = null
183
172
  }
184
- isModalInitRef.current = false;
185
- closeSkOverlay();
186
- closeSkStoreProduct();
187
- setModalOpen(false);
188
- setModalLoaded(false);
189
- setModalShown(false);
190
- };
173
+ isModalInitRef.current = false
174
+ closeSkOverlay()
175
+ closeSkStoreProduct()
176
+ setModalOpen(false)
177
+ setModalLoaded(false)
178
+ setModalShown(false)
179
+ }
191
180
  const debug = (name, data = {}) => {
192
181
  context?.onDebugEventInternal?.(name, {
193
182
  code,
@@ -200,9 +189,9 @@ var Format = ({ code, messageId, wrapper, onEvent, ...otherParams }) => {
200
189
  height,
201
190
  containerStyles,
202
191
  iframeStyles,
203
- ...data
204
- });
205
- };
192
+ ...data,
193
+ })
194
+ }
206
195
  const debugModal = (name, data = {}) => {
207
196
  context?.onDebugEventInternal?.(name, {
208
197
  code,
@@ -213,527 +202,505 @@ var Format = ({ code, messageId, wrapper, onEvent, ...otherParams }) => {
213
202
  modalOpen,
214
203
  modalShown,
215
204
  modalLoaded,
216
- ...data
217
- });
218
- };
205
+ ...data,
206
+ })
207
+ }
219
208
  const openSkOverlay = async (appStoreId, position, dismissible) => {
220
209
  try {
221
- if (!await presentSKOverlay({ appStoreId, position, dismissible })) {
222
- return;
210
+ if (!(await presentSKOverlay({ appStoreId, position, dismissible }))) {
211
+ return
223
212
  }
224
- sendMessage(webViewRef, "update-skoverlay-iframe", code, {
225
- open: true
226
- });
213
+ sendMessage(webViewRef, 'update-skoverlay-iframe', code, {
214
+ open: true,
215
+ })
227
216
  } catch (e) {
228
- debug("error-open-skoverlay-iframe", {
229
- error: e
230
- });
231
- console.error("error opening sk overlay", e);
217
+ debug('error-open-skoverlay-iframe', {
218
+ error: e,
219
+ })
220
+ console.error('error opening sk overlay', e)
232
221
  }
233
- };
222
+ }
234
223
  const closeSkOverlay = async () => {
235
224
  try {
236
- if (!await dismissSKOverlay()) {
237
- return;
225
+ if (!(await dismissSKOverlay())) {
226
+ return
238
227
  }
239
- sendMessage(webViewRef, "update-skoverlay-iframe", code, {
240
- open: false
241
- });
228
+ sendMessage(webViewRef, 'update-skoverlay-iframe', code, {
229
+ open: false,
230
+ })
242
231
  } catch (e) {
243
- debug("error-dismiss-skoverlay-iframe", {
244
- error: e
245
- });
246
- console.error("error dismissing sk overlay", e);
232
+ debug('error-dismiss-skoverlay-iframe', {
233
+ error: e,
234
+ })
235
+ console.error('error dismissing sk overlay', e)
247
236
  }
248
- };
237
+ }
249
238
  const openSkStoreProduct = async (appStoreId) => {
250
239
  try {
251
- if (!await presentSKStoreProduct(appStoreId)) {
252
- return false;
240
+ if (!(await presentSKStoreProduct(appStoreId))) {
241
+ return false
253
242
  }
254
- sendMessage(webViewRef, "update-skstoreproduct-iframe", code, {
255
- open: true
256
- });
257
- return true;
243
+ sendMessage(webViewRef, 'update-skstoreproduct-iframe', code, {
244
+ open: true,
245
+ })
246
+ return true
258
247
  } catch (e) {
259
- debug("error-open-skstoreproduct-iframe", {
260
- error: e
261
- });
262
- console.error("error opening sk store product", e);
263
- return false;
248
+ debug('error-open-skstoreproduct-iframe', {
249
+ error: e,
250
+ })
251
+ console.error('error opening sk store product', e)
252
+ return false
264
253
  }
265
- };
254
+ }
266
255
  const closeSkStoreProduct = async () => {
267
256
  try {
268
- if (!await dismissSKStoreProduct()) {
269
- return false;
257
+ if (!(await dismissSKStoreProduct())) {
258
+ return false
270
259
  }
271
- sendMessage(webViewRef, "update-skstoreproduct-iframe", code, {
272
- open: false
273
- });
274
- return true;
260
+ sendMessage(webViewRef, 'update-skstoreproduct-iframe', code, {
261
+ open: false,
262
+ })
263
+ return true
275
264
  } catch (e) {
276
- debug("error-close-skstoreproduct-iframe", {
277
- error: e
278
- });
279
- console.error("error closing sk store product", e);
280
- return false;
265
+ debug('error-close-skstoreproduct-iframe', {
266
+ error: e,
267
+ })
268
+ console.error('error closing sk store product', e)
269
+ return false
281
270
  }
282
- };
271
+ }
283
272
  const openUrl = async (message) => {
284
273
  if (!message.data.url) {
285
- return;
274
+ return
286
275
  }
287
276
  try {
288
- await Linking.openURL(`${context?.adServerUrl}${message.data.url}`);
277
+ await Linking.openURL(`${context?.adServerUrl}${message.data.url}`)
289
278
  } catch (e) {
290
- console.error("error opening url", e);
279
+ console.error('error opening url', e)
291
280
  }
292
- };
281
+ }
293
282
  const handleClick = async (message) => {
294
283
  if (message.data.appStoreId) {
295
284
  try {
296
- if (!await openSkStoreProduct(message.data.appStoreId)) {
297
- await openUrl(message);
285
+ if (!(await openSkStoreProduct(message.data.appStoreId))) {
286
+ await openUrl(message)
298
287
  }
299
288
  } catch (e) {
300
- console.error("error opening sk store product", e);
301
- await openUrl(message);
289
+ console.error('error opening sk store product', e)
290
+ await openUrl(message)
302
291
  }
303
292
  } else {
304
- await openUrl(message);
293
+ await openUrl(message)
305
294
  }
306
- context?.onAdClickInternal(message.data);
307
- };
308
- debug("format-update-state");
295
+ context?.onAdClickInternal(message.data)
296
+ }
297
+ debug('format-update-state')
309
298
  const onMessage = (event) => {
310
299
  try {
311
- const data = JSON.parse(event.nativeEvent.data);
312
- debug("iframe-message", {
313
- message: data
314
- });
300
+ const data = JSON.parse(event.nativeEvent.data)
301
+ debug('iframe-message', {
302
+ message: data,
303
+ })
315
304
  const messageHandler = handleIframeMessage(
316
305
  (message) => {
317
306
  switch (message.type) {
318
- case "init-iframe":
319
- setIframeLoaded(true);
320
- debug("iframe-post-message");
321
- messageStatusRef.current = "message-received" /* MessageReceived */;
322
- sendMessage(webViewRef, "update-iframe", code, {
307
+ case 'init-iframe':
308
+ setIframeLoaded(true)
309
+ debug('iframe-post-message')
310
+ messageStatusRef.current = 'message-received' /* MessageReceived */
311
+ sendMessage(webViewRef, 'update-iframe', code, {
323
312
  messages: context?.messages,
324
- sdk: "sdk-react-native",
313
+ sdk: 'sdk-react-native',
325
314
  otherParams,
326
- messageId
327
- });
328
- break;
329
- case "error-iframe":
330
- reset();
331
- break;
332
- case "resize-iframe":
333
- setHeight(message.data.height);
334
- break;
335
- case "click-iframe":
336
- handleClick(message);
337
- break;
338
- case "view-iframe":
339
- context?.onAdViewInternal(message.data);
340
- break;
341
- case "ad-done-iframe":
315
+ messageId,
316
+ })
317
+ break
318
+ case 'error-iframe':
319
+ reset()
320
+ break
321
+ case 'resize-iframe':
322
+ setHeight(message.data.height)
323
+ break
324
+ case 'click-iframe':
325
+ handleClick(message)
326
+ break
327
+ case 'view-iframe':
328
+ context?.onAdViewInternal(message.data)
329
+ break
330
+ case 'ad-done-iframe':
342
331
  if (bid?.bidId && message.data.cachedContent) {
343
- context?.cachedContentRef?.current?.set(bid.bidId, message.data.cachedContent);
332
+ context?.cachedContentRef?.current?.set(bid.bidId, message.data.cachedContent)
344
333
  }
345
- break;
346
- case "show-iframe":
347
- setShowIframe(true);
348
- break;
349
- case "hide-iframe":
350
- setShowIframe(false);
351
- break;
352
- case "set-styles-iframe":
353
- setContainerStyles(message.data.containerStyles);
354
- setIframeStyles(message.data.iframeStyles);
355
- break;
356
- case "open-component-iframe":
357
- setModalOpen(true);
334
+ break
335
+ case 'show-iframe':
336
+ setShowIframe(true)
337
+ break
338
+ case 'hide-iframe':
339
+ setShowIframe(false)
340
+ break
341
+ case 'set-styles-iframe':
342
+ setContainerStyles(message.data.containerStyles)
343
+ setIframeStyles(message.data.iframeStyles)
344
+ break
345
+ case 'open-component-iframe':
346
+ setModalOpen(true)
358
347
  modalInitTimeoutRef.current = setTimeout(() => {
359
348
  if (!isModalInitRef.current) {
360
- resetModal();
349
+ resetModal()
361
350
  }
362
- }, message.data.timeout ?? 5e3);
363
- break;
364
- case "event-iframe":
365
- onEvent?.(message.data);
366
- context?.onAdEventInternal(message.data);
367
- messageStatusRef.current = "message-received" /* MessageReceived */;
368
- break;
369
- case "open-skoverlay-iframe":
370
- openSkOverlay(
371
- message.data.appStoreId,
372
- message.data.position,
373
- message.data.dismissible
374
- );
375
- break;
376
- case "close-skoverlay-iframe":
377
- closeSkOverlay();
378
- break;
379
- case "open-skstoreproduct-iframe":
380
- openSkStoreProduct(message.data.appStoreId);
381
- break;
382
- case "close-skstoreproduct-iframe":
383
- closeSkStoreProduct();
384
- break;
351
+ }, message.data.timeout ?? 5e3)
352
+ break
353
+ case 'event-iframe':
354
+ onEvent?.(message.data)
355
+ context?.onAdEventInternal(message.data)
356
+ messageStatusRef.current = 'message-received' /* MessageReceived */
357
+ break
358
+ case 'open-skoverlay-iframe':
359
+ openSkOverlay(message.data.appStoreId, message.data.position, message.data.dismissible)
360
+ break
361
+ case 'close-skoverlay-iframe':
362
+ closeSkOverlay()
363
+ break
364
+ case 'open-skstoreproduct-iframe':
365
+ openSkStoreProduct(message.data.appStoreId)
366
+ break
367
+ case 'close-skstoreproduct-iframe':
368
+ closeSkStoreProduct()
369
+ break
385
370
  }
386
371
  },
387
372
  {
388
- code
373
+ code,
389
374
  }
390
- );
391
- messageHandler({ data });
375
+ )
376
+ messageHandler({ data })
392
377
  } catch (e) {
393
- debug("iframe-message-error", {
394
- error: e
395
- });
396
- console.error("error parsing message from webview", e);
397
- reset();
378
+ debug('iframe-message-error', {
379
+ error: e,
380
+ })
381
+ console.error('error parsing message from webview', e)
382
+ reset()
398
383
  }
399
- };
384
+ }
400
385
  const onModalMessage = (event) => {
401
386
  try {
402
- const data = JSON.parse(event.nativeEvent.data);
403
- debugModal("modal-iframe-message", {
404
- message: data
405
- });
387
+ const data = JSON.parse(event.nativeEvent.data)
388
+ debugModal('modal-iframe-message', {
389
+ message: data,
390
+ })
406
391
  const messageHandler = handleIframeMessage(
407
392
  (message) => {
408
393
  switch (message.type) {
409
- case "close-component-iframe":
410
- resetModal();
411
- break;
412
- case "init-component-iframe":
413
- isModalInitRef.current = true;
394
+ case 'close-component-iframe':
395
+ resetModal()
396
+ break
397
+ case 'init-component-iframe':
398
+ isModalInitRef.current = true
414
399
  if (modalInitTimeoutRef.current) {
415
- clearTimeout(modalInitTimeoutRef.current);
416
- modalInitTimeoutRef.current = null;
400
+ clearTimeout(modalInitTimeoutRef.current)
401
+ modalInitTimeoutRef.current = null
417
402
  }
418
- setModalShown(true);
419
- break;
420
- case "error-component-iframe":
421
- case "error-iframe":
422
- resetModal();
423
- context?.captureError(new Error("Processing modal iframe error"));
424
- break;
425
- case "open-skoverlay-iframe":
426
- openSkOverlay(
427
- message.data.appStoreId,
428
- message.data.position,
429
- message.data.dismissible
430
- );
431
- break;
432
- case "close-skoverlay-iframe":
433
- closeSkOverlay();
434
- break;
435
- case "click-iframe":
436
- handleClick(message);
437
- break;
438
- case "event-iframe":
439
- onEvent?.(message.data);
440
- context?.onAdEventInternal(message.data);
441
- break;
442
- case "open-skstoreproduct-iframe":
443
- openSkStoreProduct(message.data.appStoreId);
444
- break;
445
- case "close-skstoreproduct-iframe":
446
- closeSkStoreProduct();
447
- break;
403
+ setModalShown(true)
404
+ break
405
+ case 'error-component-iframe':
406
+ case 'error-iframe':
407
+ resetModal()
408
+ context?.captureError(new Error('Processing modal iframe error'))
409
+ break
410
+ case 'open-skoverlay-iframe':
411
+ openSkOverlay(message.data.appStoreId, message.data.position, message.data.dismissible)
412
+ break
413
+ case 'close-skoverlay-iframe':
414
+ closeSkOverlay()
415
+ break
416
+ case 'click-iframe':
417
+ handleClick(message)
418
+ break
419
+ case 'event-iframe':
420
+ onEvent?.(message.data)
421
+ context?.onAdEventInternal(message.data)
422
+ break
423
+ case 'open-skstoreproduct-iframe':
424
+ openSkStoreProduct(message.data.appStoreId)
425
+ break
426
+ case 'close-skstoreproduct-iframe':
427
+ closeSkStoreProduct()
428
+ break
448
429
  }
449
430
  },
450
431
  {
451
432
  code,
452
- component: "modal"
433
+ component: 'modal',
453
434
  }
454
- );
455
- messageHandler({ data });
435
+ )
436
+ messageHandler({ data })
456
437
  } catch (e) {
457
- debugModal("modal-iframe-message-error", {
458
- error: e
459
- });
460
- console.error("error parsing message from webview", e);
461
- resetModal();
438
+ debugModal('modal-iframe-message-error', {
439
+ error: e,
440
+ })
441
+ console.error('error parsing message from webview', e)
442
+ resetModal()
462
443
  }
463
- };
444
+ }
464
445
  useEffect(() => {
465
446
  const interval = setInterval(() => {
466
- if (messageStatusRef.current === "none" /* None */) {
467
- return;
447
+ if (messageStatusRef.current === 'none' /* None */) {
448
+ return
468
449
  }
469
- if (messageStatusRef.current === "message-received" /* MessageReceived */) {
470
- clearInterval(interval);
471
- return;
450
+ if (messageStatusRef.current === 'message-received' /* MessageReceived */) {
451
+ clearInterval(interval)
452
+ return
472
453
  }
473
- debug("iframe-post-message-use-effect");
474
- setIframeLoaded(true);
475
- sendMessage(webViewRef, "update-iframe", code, {
454
+ debug('iframe-post-message-use-effect')
455
+ setIframeLoaded(true)
456
+ sendMessage(webViewRef, 'update-iframe', code, {
476
457
  messages: context?.messages,
477
- sdk: "sdk-react-native",
458
+ sdk: 'sdk-react-native',
478
459
  otherParams: {
479
460
  ...otherParams,
480
- _useEffect: true
461
+ _useEffect: true,
481
462
  },
482
- messageId
483
- });
484
- }, 500);
463
+ messageId,
464
+ })
465
+ }, 500)
485
466
  return () => {
486
- clearInterval(interval);
487
- };
488
- }, []);
489
- const paramsString = convertParamsToString(otherParams);
467
+ clearInterval(interval)
468
+ }
469
+ }, [])
470
+ const paramsString = convertParamsToString(otherParams)
490
471
  useEffect(() => {
491
472
  if (!iframeLoaded || !context?.adServerUrl || !bid || !webViewRef.current) {
492
- return;
473
+ return
493
474
  }
494
- debug("iframe-post-message");
495
- sendMessage(webViewRef, "update-iframe", code, {
475
+ debug('iframe-post-message')
476
+ sendMessage(webViewRef, 'update-iframe', code, {
496
477
  data: { otherParams },
497
- code
498
- });
499
- }, [paramsString, iframeLoaded, context?.adServerUrl, bid, code]);
478
+ code,
479
+ })
480
+ }, [paramsString, iframeLoaded, context?.adServerUrl, bid, code])
500
481
  const checkIfInViewport = () => {
501
- if (!containerRef.current) return;
482
+ if (!containerRef.current) return
502
483
  containerRef.current.measureInWindow((containerX, containerY, containerWidth, containerHeight) => {
503
- sendMessage(webViewRef, "update-dimensions-iframe", code, {
484
+ sendMessage(webViewRef, 'update-dimensions-iframe', code, {
504
485
  windowWidth,
505
486
  windowHeight,
506
487
  containerWidth,
507
488
  containerHeight,
508
489
  containerX,
509
490
  containerY,
510
- keyboardHeight: keyboardHeightRef.current
511
- });
512
- });
513
- };
491
+ keyboardHeight: keyboardHeightRef.current,
492
+ })
493
+ })
494
+ }
514
495
  useEffect(() => {
515
- if (!isAdViewVisible) return;
496
+ if (!isAdViewVisible) return
516
497
  const interval = setInterval(() => {
517
- checkIfInViewport();
518
- }, 250);
519
- return () => clearInterval(interval);
520
- }, [isAdViewVisible]);
498
+ checkIfInViewport()
499
+ }, 250)
500
+ return () => clearInterval(interval)
501
+ }, [isAdViewVisible])
521
502
  useEffect(() => {
522
- const showSubscription = Keyboard.addListener("keyboardDidShow", (e) => {
523
- keyboardHeightRef.current = e?.endCoordinates?.height ?? 0;
524
- });
525
- const hideSubscription = Keyboard.addListener("keyboardDidHide", () => {
526
- keyboardHeightRef.current = 0;
527
- });
503
+ const showSubscription = Keyboard.addListener('keyboardDidShow', (e) => {
504
+ keyboardHeightRef.current = e?.endCoordinates?.height ?? 0
505
+ })
506
+ const hideSubscription = Keyboard.addListener('keyboardDidHide', () => {
507
+ keyboardHeightRef.current = 0
508
+ })
528
509
  return () => {
529
- showSubscription.remove();
530
- hideSubscription.remove();
531
- keyboardHeightRef.current = 0;
532
- };
533
- }, []);
510
+ showSubscription.remove()
511
+ hideSubscription.remove()
512
+ keyboardHeightRef.current = 0
513
+ }
514
+ }, [])
534
515
  if (!context || !bid || !iframeUrl) {
535
- return null;
516
+ return null
536
517
  }
537
- const inlineContent = /* @__PURE__ */ jsx2(
538
- frame_webview_default,
539
- {
540
- ref: webViewRef,
541
- iframeUrl,
542
- onMessage,
518
+ const inlineContent = /* @__PURE__ */ jsx2(frame_webview_default, {
519
+ ref: webViewRef,
520
+ iframeUrl,
521
+ onMessage,
522
+ style: {
523
+ height,
524
+ width: '100%',
525
+ backgroundColor: 'transparent',
526
+ borderWidth: 0,
527
+ ...iframeStyles,
528
+ },
529
+ onError: () => {
530
+ debug('iframe-error')
531
+ reset()
532
+ },
533
+ onLoad: () => {
534
+ debug('iframe-load')
535
+ messageStatusRef.current = 'initialized' /* Initialized */
536
+ },
537
+ })
538
+ const interstitialContent = /* @__PURE__ */ jsx2(Modal, {
539
+ visible: modalOpen,
540
+ transparent: true,
541
+ onRequestClose: resetModal,
542
+ animationType: 'slide',
543
+ statusBarTranslucent: true,
544
+ children: /* @__PURE__ */ jsx2(View, {
543
545
  style: {
544
- height,
545
- width: "100%",
546
- backgroundColor: "transparent",
547
- borderWidth: 0,
548
- ...iframeStyles
549
- },
550
- onError: () => {
551
- debug("iframe-error");
552
- reset();
546
+ flex: 1,
547
+ // Don't show the modal until the modal page is loaded and sends 'init-component-iframe' message back to SDK
548
+ ...(modalShown ? { opacity: 1, pointerEvents: 'auto' } : { opacity: 0, pointerEvents: 'none' }),
553
549
  },
554
- onLoad: () => {
555
- debug("iframe-load");
556
- messageStatusRef.current = "initialized" /* Initialized */;
557
- }
558
- }
559
- );
560
- const interstitialContent = /* @__PURE__ */ jsx2(
561
- Modal,
562
- {
563
- visible: modalOpen,
564
- transparent: true,
565
- onRequestClose: resetModal,
566
- animationType: "slide",
567
- statusBarTranslucent: true,
568
- children: /* @__PURE__ */ jsx2(
569
- View,
570
- {
571
- style: {
572
- flex: 1,
573
- // Don't show the modal until the modal page is loaded and sends 'init-component-iframe' message back to SDK
574
- ...modalShown ? { opacity: 1, pointerEvents: "auto" } : { opacity: 0, pointerEvents: "none" }
575
- },
576
- children: /* @__PURE__ */ jsx2(
577
- frame_webview_default,
578
- {
579
- ref: modalWebViewRef,
580
- iframeUrl: modalUrl,
581
- onMessage: onModalMessage,
582
- style: {
583
- backgroundColor: "transparent",
584
- height: "100%",
585
- width: "100%",
586
- borderWidth: 0
587
- },
588
- onError: () => {
589
- debug("modal-error");
590
- resetModal();
591
- },
592
- onLoad: () => {
593
- debug("modal-load");
594
- setModalLoaded(true);
595
- }
596
- }
597
- )
598
- }
599
- )
600
- }
601
- );
602
- return /* @__PURE__ */ jsxs(Fragment, { children: [
603
- /* @__PURE__ */ jsx2(
604
- View,
605
- {
606
- style: isAdViewVisible ? containerStyles : {
607
- height: 0,
608
- overflow: "hidden"
550
+ children: /* @__PURE__ */ jsx2(frame_webview_default, {
551
+ ref: modalWebViewRef,
552
+ iframeUrl: modalUrl,
553
+ onMessage: onModalMessage,
554
+ style: {
555
+ backgroundColor: 'transparent',
556
+ height: '100%',
557
+ width: '100%',
558
+ borderWidth: 0,
559
+ },
560
+ onError: () => {
561
+ debug('modal-error')
562
+ resetModal()
609
563
  },
564
+ onLoad: () => {
565
+ debug('modal-load')
566
+ setModalLoaded(true)
567
+ },
568
+ }),
569
+ }),
570
+ })
571
+ return /* @__PURE__ */ jsxs(Fragment, {
572
+ children: [
573
+ /* @__PURE__ */ jsx2(View, {
574
+ style: isAdViewVisible
575
+ ? containerStyles
576
+ : {
577
+ height: 0,
578
+ overflow: 'hidden',
579
+ },
610
580
  ref: containerRef,
611
- children: wrapper ? wrapper(inlineContent) : inlineContent
612
- }
613
- ),
614
- interstitialContent
615
- ] });
616
- };
617
- var FormatWithErrorBoundary = (props) => /* @__PURE__ */ jsx2(ErrorBoundary, { children: /* @__PURE__ */ jsx2(Format, { ...props }) });
618
- var Format_default = FormatWithErrorBoundary;
581
+ children: wrapper ? wrapper(inlineContent) : inlineContent,
582
+ }),
583
+ interstitialContent,
584
+ ],
585
+ })
586
+ }
587
+ var FormatWithErrorBoundary = (props) =>
588
+ /* @__PURE__ */ jsx2(ErrorBoundary, { children: /* @__PURE__ */ jsx2(Format, { ...props }) })
589
+ var Format_default = FormatWithErrorBoundary
619
590
 
620
591
  // src/formats/InlineAd.tsx
621
- import { jsx as jsx3 } from "react/jsx-runtime";
592
+ import { jsx as jsx3 } from 'react/jsx-runtime'
622
593
  var InlineAd = ({ code, messageId, wrapper, ...props }) => {
623
- return /* @__PURE__ */ jsx3(Format_default, { code, messageId, wrapper, ...props });
624
- };
625
- var InlineAd_default = InlineAd;
594
+ return /* @__PURE__ */ jsx3(Format_default, { code, messageId, wrapper, ...props })
595
+ }
596
+ var InlineAd_default = InlineAd
626
597
 
627
598
  // src/context/AdsProvider.tsx
628
- import {
629
- AdsProviderInternal,
630
- log
631
- } from "@kontextso/sdk-react";
632
- import { fetch as fetchNetworkInfo, NetInfoStateType } from "@react-native-community/netinfo";
633
- import { Appearance, Dimensions, PixelRatio, Platform as Platform3 } from "react-native";
634
- import DeviceInfo from "react-native-device-info";
599
+ import { AdsProviderInternal, log } from '@kontextso/sdk-react'
600
+ import { fetch as fetchNetworkInfo, NetInfoStateType } from '@react-native-community/netinfo'
601
+ import { Appearance, Dimensions, PixelRatio, Platform as Platform3 } from 'react-native'
602
+ import DeviceInfo from 'react-native-device-info'
635
603
 
636
604
  // package.json
637
- var version = "3.2.0-rc.1";
605
+ var version = '3.2.0-rc.1'
638
606
 
639
607
  // src/context/AdsProvider.tsx
640
- import { jsx as jsx4 } from "react/jsx-runtime";
608
+ import { jsx as jsx4 } from 'react/jsx-runtime'
641
609
  ErrorUtils.setGlobalHandler((error, isFatal) => {
642
610
  if (!isFatal) {
643
- log.warn(error);
611
+ log.warn(error)
644
612
  } else {
645
- log.error(error);
613
+ log.error(error)
646
614
  }
647
- });
615
+ })
648
616
  var getDevice = async () => {
649
617
  try {
650
- const powerState = await DeviceInfo.getPowerState();
651
- const deviceType = DeviceInfo.getDeviceType();
652
- const soundOn = await NativeRNKontext_default.isSoundOn();
653
- const screen = Dimensions.get("screen");
654
- const networkInfo = await fetchNetworkInfo();
618
+ const powerState = await DeviceInfo.getPowerState()
619
+ const deviceType = DeviceInfo.getDeviceType()
620
+ const soundOn = await NativeRNKontext_default.isSoundOn()
621
+ const screen = Dimensions.get('screen')
622
+ const networkInfo = await fetchNetworkInfo()
655
623
  const mapDeviceTypeToHardwareType = () => {
656
624
  switch (deviceType) {
657
- case "Handset":
658
- return "handset";
659
- case "Tablet":
660
- return "tablet";
661
- case "Tv":
662
- return "tv";
663
- case "Desktop":
664
- return "desktop";
625
+ case 'Handset':
626
+ return 'handset'
627
+ case 'Tablet':
628
+ return 'tablet'
629
+ case 'Tv':
630
+ return 'tv'
631
+ case 'Desktop':
632
+ return 'desktop'
665
633
  default:
666
- return "other";
634
+ return 'other'
667
635
  }
668
- };
636
+ }
669
637
  return {
670
638
  hardware: {
671
639
  brand: DeviceInfo.getBrand(),
672
640
  model: DeviceInfo.getDeviceId(),
673
- type: mapDeviceTypeToHardwareType()
641
+ type: mapDeviceTypeToHardwareType(),
674
642
  // bootTime: Not available without native module
675
643
  // sdCardAvailable: Not available without native module
676
644
  },
677
645
  audio: {
678
- muted: soundOn
646
+ muted: soundOn,
679
647
  // volume: Requires react-native-volume-manager
680
648
  // outputPluggedIn: Not available without native module
681
649
  // outputType: Not available without native module
682
650
  },
683
651
  network: {
684
- carrier: networkInfo.type === NetInfoStateType.cellular && networkInfo.details.carrier || void 0,
652
+ carrier: (networkInfo.type === NetInfoStateType.cellular && networkInfo.details.carrier) || void 0,
685
653
  userAgent: await DeviceInfo.getUserAgent(),
686
- type: [NetInfoStateType.wifi, NetInfoStateType.cellular, NetInfoStateType.ethernet].includes(networkInfo.type) ? networkInfo.type : NetInfoStateType.other,
687
- detail: networkInfo.type === NetInfoStateType.cellular && networkInfo.details.cellularGeneration || void 0
654
+ type: [NetInfoStateType.wifi, NetInfoStateType.cellular, NetInfoStateType.ethernet].includes(networkInfo.type)
655
+ ? networkInfo.type
656
+ : NetInfoStateType.other,
657
+ detail: (networkInfo.type === NetInfoStateType.cellular && networkInfo.details.cellularGeneration) || void 0,
688
658
  },
689
659
  os: {
690
660
  name: Platform3.OS,
691
661
  version: DeviceInfo.getSystemVersion(),
692
662
  locale: Intl.DateTimeFormat().resolvedOptions().locale,
693
- timezone: Intl.DateTimeFormat().resolvedOptions().timeZone
663
+ timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
694
664
  },
695
665
  screen: {
696
- darkMode: Appearance.getColorScheme() === "dark",
666
+ darkMode: Appearance.getColorScheme() === 'dark',
697
667
  dpr: PixelRatio.get(),
698
668
  height: screen.height,
699
669
  width: screen.width,
700
- orientation: screen.width > screen.height ? "landscape" : "portrait"
670
+ orientation: screen.width > screen.height ? 'landscape' : 'portrait',
701
671
  },
702
672
  power: {
703
673
  batteryLevel: powerState.batteryLevel,
704
674
  batteryState: powerState.batteryState,
705
- lowPowerMode: powerState.lowPowerMode
706
- }
707
- };
675
+ lowPowerMode: powerState.lowPowerMode,
676
+ },
677
+ }
708
678
  } catch (error) {
709
- console.error(error);
710
- return {};
679
+ console.error(error)
680
+ return {}
711
681
  }
712
- };
682
+ }
713
683
  var getApp = async () => {
714
684
  try {
715
685
  return {
716
686
  bundleId: DeviceInfo.getBundleId(),
717
687
  firstInstallTime: await DeviceInfo.getFirstInstallTime(),
718
688
  lastUpdateTime: await DeviceInfo.getLastUpdateTime(),
719
- version: DeviceInfo.getVersion()
689
+ version: DeviceInfo.getVersion(),
720
690
  // Not supported in react-native-device-info v10
721
691
  // startTime: await DeviceInfo.getStartupTime(),
722
- };
692
+ }
723
693
  } catch (error) {
724
- console.error(error);
725
- return {};
694
+ console.error(error)
695
+ return {}
726
696
  }
727
- };
697
+ }
728
698
  var getSdk = async () => ({
729
- name: "sdk-react-native",
730
- platform: Platform3.OS === "ios" ? "ios" : "android",
731
- version
732
- });
699
+ name: 'sdk-react-native',
700
+ platform: Platform3.OS === 'ios' ? 'ios' : 'android',
701
+ version,
702
+ })
733
703
  var AdsProvider = (props) => {
734
- return /* @__PURE__ */ jsx4(AdsProviderInternal, { ...props, getDevice, getSdk, getApp });
735
- };
736
- export {
737
- AdsProvider,
738
- InlineAd_default as InlineAd
739
- };
704
+ return /* @__PURE__ */ jsx4(AdsProviderInternal, { ...props, getDevice, getSdk, getApp })
705
+ }
706
+ export { AdsProvider, InlineAd_default as InlineAd }