@kontextso/sdk-react-native 3.0.1 → 3.0.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.js CHANGED
@@ -35,11 +35,6 @@ __export(index_exports, {
35
35
  });
36
36
  module.exports = __toCommonJS(index_exports);
37
37
 
38
- // src/formats/Format.tsx
39
- var import_react2 = require("react");
40
- var import_sdk_react = require("@kontextso/sdk-react");
41
- var import_react_native = require("react-native");
42
-
43
38
  // ../sdk-common/dist/index.mjs
44
39
  function makeIframeMessage(type, opts) {
45
40
  const { data, code, component } = opts;
@@ -58,6 +53,11 @@ function handleIframeMessage(handler, opts) {
58
53
  };
59
54
  }
60
55
 
56
+ // src/formats/Format.tsx
57
+ var import_sdk_react = require("@kontextso/sdk-react");
58
+ var import_react2 = require("react");
59
+ var import_react_native = require("react-native");
60
+
61
61
  // src/frame-webview.tsx
62
62
  var import_react = require("react");
63
63
  var import_react_native_webview = require("react-native-webview");
@@ -107,11 +107,18 @@ var sendMessage = (webViewRef, type, code, data) => {
107
107
  }));
108
108
  `);
109
109
  };
110
+ var getCachedContent = (context, bidId) => {
111
+ if (!bidId) {
112
+ return null;
113
+ }
114
+ return context?.cachedContentRef?.current?.get(bidId) ?? null;
115
+ };
110
116
  var Format = ({ code, messageId, wrapper, onEvent, ...otherParams }) => {
111
117
  const context = (0, import_react2.useContext)(import_sdk_react.AdsContext);
112
118
  const bid = (0, import_sdk_react.useBid)({ code, messageId });
113
119
  const [height, setHeight] = (0, import_react2.useState)(0);
114
- const iframeUrl = (0, import_sdk_react.useIframeUrl)(context, bid, code, messageId, "sdk-react-native", otherParams.theme);
120
+ const cachedContent = getCachedContent(context, bid?.bidId);
121
+ const iframeUrl = (0, import_sdk_react.useIframeUrl)(context, bid, code, messageId, "sdk-react-native", otherParams.theme, cachedContent);
115
122
  const modalUrl = iframeUrl.replace("/api/frame/", "/api/modal/");
116
123
  const [showIframe, setShowIframe] = (0, import_react2.useState)(false);
117
124
  const [iframeLoaded, setIframeLoaded] = (0, import_react2.useState)(false);
@@ -213,6 +220,11 @@ var Format = ({ code, messageId, wrapper, onEvent, ...otherParams }) => {
213
220
  case "view-iframe":
214
221
  context?.onAdViewInternal(message.data);
215
222
  break;
223
+ case "ad-done-iframe":
224
+ if (bid?.bidId && message.data.cachedContent) {
225
+ context?.cachedContentRef?.current?.set(bid.bidId, message.data.cachedContent);
226
+ }
227
+ break;
216
228
  case "show-iframe":
217
229
  setShowIframe(true);
218
230
  break;
@@ -450,7 +462,7 @@ var import_react_native2 = require("react-native");
450
462
  var NativeRNKontext_default = import_react_native2.TurboModuleRegistry.getEnforcing("RNKontext");
451
463
 
452
464
  // package.json
453
- var version = "3.0.1";
465
+ var version = "3.0.3";
454
466
 
455
467
  // src/context/AdsProvider.tsx
456
468
  var import_jsx_runtime4 = require("react/jsx-runtime");
package/dist/index.mjs CHANGED
@@ -1,14 +1,3 @@
1
- // src/formats/Format.tsx
2
- import { useContext, useEffect, useRef, useState } from "react";
3
- import {
4
- AdsContext,
5
- convertParamsToString,
6
- ErrorBoundary,
7
- useBid,
8
- useIframeUrl
9
- } from "@kontextso/sdk-react";
10
- import { Linking, Modal, View, useWindowDimensions, Keyboard } from "react-native";
11
-
12
1
  // ../sdk-common/dist/index.mjs
13
2
  function makeIframeMessage(type, opts) {
14
3
  const { data, code, component } = opts;
@@ -27,6 +16,17 @@ function handleIframeMessage(handler, opts) {
27
16
  };
28
17
  }
29
18
 
19
+ // src/formats/Format.tsx
20
+ import {
21
+ AdsContext,
22
+ convertParamsToString,
23
+ ErrorBoundary,
24
+ useBid,
25
+ useIframeUrl
26
+ } from "@kontextso/sdk-react";
27
+ import { useContext, useEffect, useRef, useState } from "react";
28
+ import { Keyboard, Linking, Modal, useWindowDimensions, View } from "react-native";
29
+
30
30
  // src/frame-webview.tsx
31
31
  import { forwardRef } from "react";
32
32
  import { WebView } from "react-native-webview";
@@ -76,11 +76,18 @@ var sendMessage = (webViewRef, type, code, data) => {
76
76
  }));
77
77
  `);
78
78
  };
79
+ var getCachedContent = (context, bidId) => {
80
+ if (!bidId) {
81
+ return null;
82
+ }
83
+ return context?.cachedContentRef?.current?.get(bidId) ?? null;
84
+ };
79
85
  var Format = ({ code, messageId, wrapper, onEvent, ...otherParams }) => {
80
86
  const context = useContext(AdsContext);
81
87
  const bid = useBid({ code, messageId });
82
88
  const [height, setHeight] = useState(0);
83
- const iframeUrl = useIframeUrl(context, bid, code, messageId, "sdk-react-native", otherParams.theme);
89
+ const cachedContent = getCachedContent(context, bid?.bidId);
90
+ const iframeUrl = useIframeUrl(context, bid, code, messageId, "sdk-react-native", otherParams.theme, cachedContent);
84
91
  const modalUrl = iframeUrl.replace("/api/frame/", "/api/modal/");
85
92
  const [showIframe, setShowIframe] = useState(false);
86
93
  const [iframeLoaded, setIframeLoaded] = useState(false);
@@ -182,6 +189,11 @@ var Format = ({ code, messageId, wrapper, onEvent, ...otherParams }) => {
182
189
  case "view-iframe":
183
190
  context?.onAdViewInternal(message.data);
184
191
  break;
192
+ case "ad-done-iframe":
193
+ if (bid?.bidId && message.data.cachedContent) {
194
+ context?.cachedContentRef?.current?.set(bid.bidId, message.data.cachedContent);
195
+ }
196
+ break;
185
197
  case "show-iframe":
186
198
  setShowIframe(true);
187
199
  break;
@@ -419,7 +431,7 @@ import { TurboModuleRegistry } from "react-native";
419
431
  var NativeRNKontext_default = TurboModuleRegistry.getEnforcing("RNKontext");
420
432
 
421
433
  // package.json
422
- var version = "3.0.1";
434
+ var version = "3.0.3";
423
435
 
424
436
  // src/context/AdsProvider.tsx
425
437
  import { jsx as jsx4 } from "react/jsx-runtime";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kontextso/sdk-react-native",
3
- "version": "3.0.1",
3
+ "version": "3.0.3",
4
4
  "description": "Kontext SDK for React Native",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -11,7 +11,7 @@
11
11
  "homepage": "https://github.com/kontextso",
12
12
  "scripts": {
13
13
  "dev:js": "tsup --watch",
14
- "dev": "npm-run-all dev:js",
14
+ "dev": "npm-run-all2 dev:js",
15
15
  "build:js": "tsup",
16
16
  "build": "npm run build:js && cross-env NODE_ENV=development npm run test:run",
17
17
  "test": "",
@@ -33,7 +33,7 @@
33
33
  "cross-env": "^7.0.3",
34
34
  "expo": "^53.0.18",
35
35
  "expo-av": "^15.1.7",
36
- "jsdom": "^25.0.1",
36
+ "jsdom": "^27.0.1",
37
37
  "react": "^18.3.1",
38
38
  "react-dom": "^18.3.1",
39
39
  "react-native": "^0.80.1",
@@ -51,7 +51,7 @@
51
51
  "react-native-webview": "^13.10.0"
52
52
  },
53
53
  "dependencies": {
54
- "@kontextso/sdk-react": "^3.0.1"
54
+ "@kontextso/sdk-react": "^3.0.3"
55
55
  },
56
56
  "files": [
57
57
  "dist/*",
@@ -1,21 +1,22 @@
1
- import { useContext, useEffect, useRef, useState } from 'react'
1
+ import {
2
+ handleIframeMessage,
3
+ type IframeMessage,
4
+ type IframeMessageEvent,
5
+ type IframeMessageType,
6
+ makeIframeMessage,
7
+ } from '@kontextso/sdk-common'
2
8
  import {
3
9
  AdsContext,
10
+ type ContextType,
4
11
  convertParamsToString,
5
12
  ErrorBoundary,
13
+ type FormatProps,
6
14
  useBid,
7
15
  useIframeUrl,
8
- type FormatProps,
9
16
  } from '@kontextso/sdk-react'
17
+ import { useContext, useEffect, useRef, useState } from 'react'
18
+ import { Keyboard, Linking, Modal, useWindowDimensions, View } from 'react-native'
10
19
  import type { WebView, WebViewMessageEvent } from 'react-native-webview'
11
- import { Linking, Modal, View, useWindowDimensions, Keyboard } from 'react-native'
12
- import {
13
- handleIframeMessage,
14
- type IframeMessageEvent,
15
- type IframeMessageType,
16
- makeIframeMessage,
17
- type IframeMessage,
18
- } from '@kontextso/sdk-common'
19
20
  import FrameWebView from '../frame-webview'
20
21
 
21
22
  const sendMessage = (
@@ -36,13 +37,22 @@ const sendMessage = (
36
37
  `)
37
38
  }
38
39
 
40
+ const getCachedContent = (context: ContextType, bidId?: string) => {
41
+ if (!bidId) {
42
+ return null
43
+ }
44
+ return context?.cachedContentRef?.current?.get(bidId) ?? null
45
+ }
46
+
39
47
  const Format = ({ code, messageId, wrapper, onEvent, ...otherParams }: FormatProps) => {
40
48
  const context = useContext(AdsContext)
41
49
 
42
50
  const bid = useBid({ code, messageId })
43
51
  const [height, setHeight] = useState<number>(0)
44
52
 
45
- const iframeUrl = useIframeUrl(context, bid, code, messageId, 'sdk-react-native', otherParams.theme)
53
+ const cachedContent = getCachedContent(context, bid?.bidId)
54
+
55
+ const iframeUrl = useIframeUrl(context, bid, code, messageId, 'sdk-react-native', otherParams.theme, cachedContent)
46
56
  const modalUrl = iframeUrl.replace('/api/frame/', '/api/modal/')
47
57
 
48
58
  const [showIframe, setShowIframe] = useState<boolean>(false)
@@ -63,7 +73,7 @@ const Format = ({ code, messageId, wrapper, onEvent, ...otherParams }: FormatPro
63
73
 
64
74
  const { height: windowHeight, width: windowWidth } = useWindowDimensions()
65
75
 
66
- const keyboardHeightRef = useRef(0);
76
+ const keyboardHeightRef = useRef(0)
67
77
 
68
78
  const isAdViewVisible = showIframe && iframeLoaded
69
79
 
@@ -165,6 +175,12 @@ const Format = ({ code, messageId, wrapper, onEvent, ...otherParams }: FormatPro
165
175
  context?.onAdViewInternal(message.data)
166
176
  break
167
177
 
178
+ case 'ad-done-iframe':
179
+ if (bid?.bidId && message.data.cachedContent) {
180
+ context?.cachedContentRef?.current?.set(bid.bidId, message.data.cachedContent)
181
+ }
182
+ break
183
+
168
184
  case 'show-iframe':
169
185
  setShowIframe(true)
170
186
  break
@@ -313,18 +329,18 @@ const Format = ({ code, messageId, wrapper, onEvent, ...otherParams }: FormatPro
313
329
 
314
330
  useEffect(() => {
315
331
  const showSubscription = Keyboard.addListener('keyboardDidShow', (e) => {
316
- keyboardHeightRef.current = e?.endCoordinates?.height ?? 0;
317
- });
332
+ keyboardHeightRef.current = e?.endCoordinates?.height ?? 0
333
+ })
318
334
  const hideSubscription = Keyboard.addListener('keyboardDidHide', () => {
319
- keyboardHeightRef.current = 0;
320
- });
335
+ keyboardHeightRef.current = 0
336
+ })
321
337
 
322
338
  return () => {
323
- showSubscription.remove();
324
- hideSubscription.remove();
325
- keyboardHeightRef.current = 0;
326
- };
327
- }, []);
339
+ showSubscription.remove()
340
+ hideSubscription.remove()
341
+ keyboardHeightRef.current = 0
342
+ }
343
+ }, [])
328
344
 
329
345
  if (!context || !bid || !iframeUrl) {
330
346
  return null