@kontextso/sdk-react-native 3.1.0-rc.1 → 3.1.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.js +81 -20
- package/dist/index.mjs +69 -8
- package/package.json +1 -1
- package/src/formats/Format.tsx +6 -6
package/dist/index.js
CHANGED
|
@@ -57,7 +57,7 @@ function handleIframeMessage(handler, opts) {
|
|
|
57
57
|
// src/formats/Format.tsx
|
|
58
58
|
var import_sdk_react = require("@kontextso/sdk-react");
|
|
59
59
|
var import_react2 = require("react");
|
|
60
|
-
var
|
|
60
|
+
var import_react_native3 = require("react-native");
|
|
61
61
|
|
|
62
62
|
// src/frame-webview.tsx
|
|
63
63
|
var import_react = require("react");
|
|
@@ -98,6 +98,43 @@ var FrameWebView = (0, import_react.forwardRef)(
|
|
|
98
98
|
);
|
|
99
99
|
var frame_webview_default = FrameWebView;
|
|
100
100
|
|
|
101
|
+
// src/services/SkOverlay.ts
|
|
102
|
+
var import_react_native2 = require("react-native");
|
|
103
|
+
|
|
104
|
+
// src/NativeRNKontext.ts
|
|
105
|
+
var import_react_native = require("react-native");
|
|
106
|
+
var NativeRNKontext_default = import_react_native.TurboModuleRegistry.getEnforcing("RNKontext");
|
|
107
|
+
|
|
108
|
+
// src/services/SkOverlay.ts
|
|
109
|
+
var isValidAppStoreId = (id) => {
|
|
110
|
+
return typeof id === "string" && /^\d+$/.test(id);
|
|
111
|
+
};
|
|
112
|
+
var isValidPosition = (p) => {
|
|
113
|
+
return p === "bottom" || p === "bottomRaised";
|
|
114
|
+
};
|
|
115
|
+
async function presentSKOverlay(params) {
|
|
116
|
+
if (import_react_native2.Platform.OS !== "ios") {
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
let { appStoreId, position, dismissible } = params;
|
|
120
|
+
if (!isValidAppStoreId(appStoreId)) {
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
123
|
+
if (!isValidPosition(position)) {
|
|
124
|
+
position = "bottom";
|
|
125
|
+
}
|
|
126
|
+
if (typeof dismissible !== "boolean") {
|
|
127
|
+
dismissible = Boolean(dismissible);
|
|
128
|
+
}
|
|
129
|
+
return NativeRNKontext_default.presentSKOverlay(appStoreId, position, dismissible);
|
|
130
|
+
}
|
|
131
|
+
async function dismissSKOverlay() {
|
|
132
|
+
if (import_react_native2.Platform.OS !== "ios") {
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
return NativeRNKontext_default.dismissSKOverlay();
|
|
136
|
+
}
|
|
137
|
+
|
|
101
138
|
// src/formats/Format.tsx
|
|
102
139
|
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
103
140
|
var sendMessage = (webViewRef, type, code, data) => {
|
|
@@ -137,7 +174,7 @@ var Format = ({ code, messageId, wrapper, onEvent, ...otherParams }) => {
|
|
|
137
174
|
const messageStatusRef = (0, import_react2.useRef)("none" /* None */);
|
|
138
175
|
const modalInitTimeoutRef = (0, import_react2.useRef)(null);
|
|
139
176
|
const isModalInitRef = (0, import_react2.useRef)(false);
|
|
140
|
-
const { height: windowHeight, width: windowWidth } = (0,
|
|
177
|
+
const { height: windowHeight, width: windowWidth } = (0, import_react_native3.useWindowDimensions)();
|
|
141
178
|
const keyboardHeightRef = (0, import_react2.useRef)(0);
|
|
142
179
|
const isAdViewVisible = showIframe && iframeLoaded;
|
|
143
180
|
const reset = () => {
|
|
@@ -156,6 +193,7 @@ var Format = ({ code, messageId, wrapper, onEvent, ...otherParams }) => {
|
|
|
156
193
|
modalInitTimeoutRef.current = null;
|
|
157
194
|
}
|
|
158
195
|
isModalInitRef.current = false;
|
|
196
|
+
closeSkOverlay();
|
|
159
197
|
setModalOpen(false);
|
|
160
198
|
setModalLoaded(false);
|
|
161
199
|
setModalShown(false);
|
|
@@ -188,6 +226,27 @@ var Format = ({ code, messageId, wrapper, onEvent, ...otherParams }) => {
|
|
|
188
226
|
...data
|
|
189
227
|
});
|
|
190
228
|
};
|
|
229
|
+
const openSkOverlay = async (appStoreId, position, dismissible) => {
|
|
230
|
+
try {
|
|
231
|
+
await presentSKOverlay({ appStoreId, position, dismissible });
|
|
232
|
+
sendMessage(webViewRef, "update-skoverlay-iframe", code, {
|
|
233
|
+
open: true
|
|
234
|
+
});
|
|
235
|
+
} catch (e) {
|
|
236
|
+
console.error("error opening sk overlay", e);
|
|
237
|
+
reset();
|
|
238
|
+
}
|
|
239
|
+
};
|
|
240
|
+
const closeSkOverlay = async () => {
|
|
241
|
+
try {
|
|
242
|
+
await dismissSKOverlay();
|
|
243
|
+
sendMessage(webViewRef, "update-skoverlay-iframe", code, {
|
|
244
|
+
open: false
|
|
245
|
+
});
|
|
246
|
+
} catch (e) {
|
|
247
|
+
console.error("error dismissing sk overlay", e);
|
|
248
|
+
}
|
|
249
|
+
};
|
|
191
250
|
debug("format-update-state");
|
|
192
251
|
const onMessage = (event) => {
|
|
193
252
|
try {
|
|
@@ -217,7 +276,7 @@ var Format = ({ code, messageId, wrapper, onEvent, ...otherParams }) => {
|
|
|
217
276
|
break;
|
|
218
277
|
case "click-iframe":
|
|
219
278
|
if (message.data.url) {
|
|
220
|
-
|
|
279
|
+
import_react_native3.Linking.openURL(`${context?.adServerUrl}${message.data.url}`).catch(
|
|
221
280
|
(err) => console.error("error opening url", err)
|
|
222
281
|
);
|
|
223
282
|
}
|
|
@@ -254,6 +313,12 @@ var Format = ({ code, messageId, wrapper, onEvent, ...otherParams }) => {
|
|
|
254
313
|
context?.onAdEventInternal(message.data);
|
|
255
314
|
messageStatusRef.current = "message-received" /* MessageReceived */;
|
|
256
315
|
break;
|
|
316
|
+
case "open-skoverlay-iframe":
|
|
317
|
+
openSkOverlay(message.data.appStoreId, message.data.position, message.data.dismissible);
|
|
318
|
+
break;
|
|
319
|
+
case "close-skoverlay-iframe":
|
|
320
|
+
closeSkOverlay();
|
|
321
|
+
break;
|
|
257
322
|
}
|
|
258
323
|
},
|
|
259
324
|
{
|
|
@@ -296,7 +361,7 @@ var Format = ({ code, messageId, wrapper, onEvent, ...otherParams }) => {
|
|
|
296
361
|
break;
|
|
297
362
|
case "click-iframe":
|
|
298
363
|
if (message.data.url) {
|
|
299
|
-
|
|
364
|
+
import_react_native3.Linking.openURL(`${context?.adServerUrl}${message.data.url}`).catch(
|
|
300
365
|
(err) => console.error("error opening url", err)
|
|
301
366
|
);
|
|
302
367
|
}
|
|
@@ -380,10 +445,10 @@ var Format = ({ code, messageId, wrapper, onEvent, ...otherParams }) => {
|
|
|
380
445
|
return () => clearInterval(interval);
|
|
381
446
|
}, [isAdViewVisible]);
|
|
382
447
|
(0, import_react2.useEffect)(() => {
|
|
383
|
-
const showSubscription =
|
|
448
|
+
const showSubscription = import_react_native3.Keyboard.addListener("keyboardDidShow", (e) => {
|
|
384
449
|
keyboardHeightRef.current = e?.endCoordinates?.height ?? 0;
|
|
385
450
|
});
|
|
386
|
-
const hideSubscription =
|
|
451
|
+
const hideSubscription = import_react_native3.Keyboard.addListener("keyboardDidHide", () => {
|
|
387
452
|
keyboardHeightRef.current = 0;
|
|
388
453
|
});
|
|
389
454
|
return () => {
|
|
@@ -419,7 +484,7 @@ var Format = ({ code, messageId, wrapper, onEvent, ...otherParams }) => {
|
|
|
419
484
|
}
|
|
420
485
|
);
|
|
421
486
|
const interstitialContent = /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
422
|
-
|
|
487
|
+
import_react_native3.Modal,
|
|
423
488
|
{
|
|
424
489
|
visible: modalOpen,
|
|
425
490
|
transparent: true,
|
|
@@ -427,7 +492,7 @@ var Format = ({ code, messageId, wrapper, onEvent, ...otherParams }) => {
|
|
|
427
492
|
animationType: "slide",
|
|
428
493
|
statusBarTranslucent: true,
|
|
429
494
|
children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
430
|
-
|
|
495
|
+
import_react_native3.View,
|
|
431
496
|
{
|
|
432
497
|
style: {
|
|
433
498
|
flex: 1,
|
|
@@ -462,7 +527,7 @@ var Format = ({ code, messageId, wrapper, onEvent, ...otherParams }) => {
|
|
|
462
527
|
);
|
|
463
528
|
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
|
|
464
529
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
465
|
-
|
|
530
|
+
import_react_native3.View,
|
|
466
531
|
{
|
|
467
532
|
style: isAdViewVisible ? containerStyles : {
|
|
468
533
|
height: 0,
|
|
@@ -488,15 +553,11 @@ var InlineAd_default = InlineAd;
|
|
|
488
553
|
// src/context/AdsProvider.tsx
|
|
489
554
|
var import_sdk_react2 = require("@kontextso/sdk-react");
|
|
490
555
|
var import_netinfo = require("@react-native-community/netinfo");
|
|
491
|
-
var
|
|
556
|
+
var import_react_native4 = require("react-native");
|
|
492
557
|
var import_react_native_device_info = __toESM(require("react-native-device-info"));
|
|
493
558
|
|
|
494
559
|
// package.json
|
|
495
|
-
var version = "3.1.0-rc.
|
|
496
|
-
|
|
497
|
-
// src/NativeRNKontext.ts
|
|
498
|
-
var import_react_native2 = require("react-native");
|
|
499
|
-
var NativeRNKontext_default = import_react_native2.TurboModuleRegistry.getEnforcing("RNKontext");
|
|
560
|
+
var version = "3.1.0-rc.3";
|
|
500
561
|
|
|
501
562
|
// src/context/AdsProvider.tsx
|
|
502
563
|
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
@@ -512,7 +573,7 @@ var getDevice = async () => {
|
|
|
512
573
|
const powerState = await import_react_native_device_info.default.getPowerState();
|
|
513
574
|
const deviceType = import_react_native_device_info.default.getDeviceType();
|
|
514
575
|
const soundOn = await NativeRNKontext_default.isSoundOn();
|
|
515
|
-
const screen =
|
|
576
|
+
const screen = import_react_native4.Dimensions.get("screen");
|
|
516
577
|
const networkInfo = await (0, import_netinfo.fetch)();
|
|
517
578
|
const mapDeviceTypeToHardwareType = () => {
|
|
518
579
|
switch (deviceType) {
|
|
@@ -549,14 +610,14 @@ var getDevice = async () => {
|
|
|
549
610
|
detail: networkInfo.type === import_netinfo.NetInfoStateType.cellular && networkInfo.details.cellularGeneration || void 0
|
|
550
611
|
},
|
|
551
612
|
os: {
|
|
552
|
-
name:
|
|
613
|
+
name: import_react_native4.Platform.OS,
|
|
553
614
|
version: import_react_native_device_info.default.getSystemVersion(),
|
|
554
615
|
locale: Intl.DateTimeFormat().resolvedOptions().locale,
|
|
555
616
|
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone
|
|
556
617
|
},
|
|
557
618
|
screen: {
|
|
558
|
-
darkMode:
|
|
559
|
-
dpr:
|
|
619
|
+
darkMode: import_react_native4.Appearance.getColorScheme() === "dark",
|
|
620
|
+
dpr: import_react_native4.PixelRatio.get(),
|
|
560
621
|
height: screen.height,
|
|
561
622
|
width: screen.width,
|
|
562
623
|
orientation: screen.width > screen.height ? "landscape" : "portrait"
|
|
@@ -589,7 +650,7 @@ var getApp = async () => {
|
|
|
589
650
|
};
|
|
590
651
|
var getSdk = async () => ({
|
|
591
652
|
name: "sdk-react-native",
|
|
592
|
-
platform:
|
|
653
|
+
platform: import_react_native4.Platform.OS === "ios" ? "ios" : "android",
|
|
593
654
|
version
|
|
594
655
|
});
|
|
595
656
|
var AdsProvider = (props) => {
|
package/dist/index.mjs
CHANGED
|
@@ -67,6 +67,43 @@ var FrameWebView = forwardRef(
|
|
|
67
67
|
);
|
|
68
68
|
var frame_webview_default = FrameWebView;
|
|
69
69
|
|
|
70
|
+
// src/services/SkOverlay.ts
|
|
71
|
+
import { Platform } from "react-native";
|
|
72
|
+
|
|
73
|
+
// src/NativeRNKontext.ts
|
|
74
|
+
import { TurboModuleRegistry } from "react-native";
|
|
75
|
+
var NativeRNKontext_default = TurboModuleRegistry.getEnforcing("RNKontext");
|
|
76
|
+
|
|
77
|
+
// src/services/SkOverlay.ts
|
|
78
|
+
var isValidAppStoreId = (id) => {
|
|
79
|
+
return typeof id === "string" && /^\d+$/.test(id);
|
|
80
|
+
};
|
|
81
|
+
var isValidPosition = (p) => {
|
|
82
|
+
return p === "bottom" || p === "bottomRaised";
|
|
83
|
+
};
|
|
84
|
+
async function presentSKOverlay(params) {
|
|
85
|
+
if (Platform.OS !== "ios") {
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
let { appStoreId, position, dismissible } = params;
|
|
89
|
+
if (!isValidAppStoreId(appStoreId)) {
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
if (!isValidPosition(position)) {
|
|
93
|
+
position = "bottom";
|
|
94
|
+
}
|
|
95
|
+
if (typeof dismissible !== "boolean") {
|
|
96
|
+
dismissible = Boolean(dismissible);
|
|
97
|
+
}
|
|
98
|
+
return NativeRNKontext_default.presentSKOverlay(appStoreId, position, dismissible);
|
|
99
|
+
}
|
|
100
|
+
async function dismissSKOverlay() {
|
|
101
|
+
if (Platform.OS !== "ios") {
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
return NativeRNKontext_default.dismissSKOverlay();
|
|
105
|
+
}
|
|
106
|
+
|
|
70
107
|
// src/formats/Format.tsx
|
|
71
108
|
import { Fragment, jsx as jsx2, jsxs } from "react/jsx-runtime";
|
|
72
109
|
var sendMessage = (webViewRef, type, code, data) => {
|
|
@@ -125,6 +162,7 @@ var Format = ({ code, messageId, wrapper, onEvent, ...otherParams }) => {
|
|
|
125
162
|
modalInitTimeoutRef.current = null;
|
|
126
163
|
}
|
|
127
164
|
isModalInitRef.current = false;
|
|
165
|
+
closeSkOverlay();
|
|
128
166
|
setModalOpen(false);
|
|
129
167
|
setModalLoaded(false);
|
|
130
168
|
setModalShown(false);
|
|
@@ -157,6 +195,27 @@ var Format = ({ code, messageId, wrapper, onEvent, ...otherParams }) => {
|
|
|
157
195
|
...data
|
|
158
196
|
});
|
|
159
197
|
};
|
|
198
|
+
const openSkOverlay = async (appStoreId, position, dismissible) => {
|
|
199
|
+
try {
|
|
200
|
+
await presentSKOverlay({ appStoreId, position, dismissible });
|
|
201
|
+
sendMessage(webViewRef, "update-skoverlay-iframe", code, {
|
|
202
|
+
open: true
|
|
203
|
+
});
|
|
204
|
+
} catch (e) {
|
|
205
|
+
console.error("error opening sk overlay", e);
|
|
206
|
+
reset();
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
const closeSkOverlay = async () => {
|
|
210
|
+
try {
|
|
211
|
+
await dismissSKOverlay();
|
|
212
|
+
sendMessage(webViewRef, "update-skoverlay-iframe", code, {
|
|
213
|
+
open: false
|
|
214
|
+
});
|
|
215
|
+
} catch (e) {
|
|
216
|
+
console.error("error dismissing sk overlay", e);
|
|
217
|
+
}
|
|
218
|
+
};
|
|
160
219
|
debug("format-update-state");
|
|
161
220
|
const onMessage = (event) => {
|
|
162
221
|
try {
|
|
@@ -223,6 +282,12 @@ var Format = ({ code, messageId, wrapper, onEvent, ...otherParams }) => {
|
|
|
223
282
|
context?.onAdEventInternal(message.data);
|
|
224
283
|
messageStatusRef.current = "message-received" /* MessageReceived */;
|
|
225
284
|
break;
|
|
285
|
+
case "open-skoverlay-iframe":
|
|
286
|
+
openSkOverlay(message.data.appStoreId, message.data.position, message.data.dismissible);
|
|
287
|
+
break;
|
|
288
|
+
case "close-skoverlay-iframe":
|
|
289
|
+
closeSkOverlay();
|
|
290
|
+
break;
|
|
226
291
|
}
|
|
227
292
|
},
|
|
228
293
|
{
|
|
@@ -460,15 +525,11 @@ import {
|
|
|
460
525
|
log
|
|
461
526
|
} from "@kontextso/sdk-react";
|
|
462
527
|
import { fetch as fetchNetworkInfo, NetInfoStateType } from "@react-native-community/netinfo";
|
|
463
|
-
import { Appearance, Dimensions, PixelRatio, Platform } from "react-native";
|
|
528
|
+
import { Appearance, Dimensions, PixelRatio, Platform as Platform2 } from "react-native";
|
|
464
529
|
import DeviceInfo from "react-native-device-info";
|
|
465
530
|
|
|
466
531
|
// package.json
|
|
467
|
-
var version = "3.1.0-rc.
|
|
468
|
-
|
|
469
|
-
// src/NativeRNKontext.ts
|
|
470
|
-
import { TurboModuleRegistry } from "react-native";
|
|
471
|
-
var NativeRNKontext_default = TurboModuleRegistry.getEnforcing("RNKontext");
|
|
532
|
+
var version = "3.1.0-rc.3";
|
|
472
533
|
|
|
473
534
|
// src/context/AdsProvider.tsx
|
|
474
535
|
import { jsx as jsx4 } from "react/jsx-runtime";
|
|
@@ -521,7 +582,7 @@ var getDevice = async () => {
|
|
|
521
582
|
detail: networkInfo.type === NetInfoStateType.cellular && networkInfo.details.cellularGeneration || void 0
|
|
522
583
|
},
|
|
523
584
|
os: {
|
|
524
|
-
name:
|
|
585
|
+
name: Platform2.OS,
|
|
525
586
|
version: DeviceInfo.getSystemVersion(),
|
|
526
587
|
locale: Intl.DateTimeFormat().resolvedOptions().locale,
|
|
527
588
|
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone
|
|
@@ -561,7 +622,7 @@ var getApp = async () => {
|
|
|
561
622
|
};
|
|
562
623
|
var getSdk = async () => ({
|
|
563
624
|
name: "sdk-react-native",
|
|
564
|
-
platform:
|
|
625
|
+
platform: Platform2.OS === "ios" ? "ios" : "android",
|
|
565
626
|
version
|
|
566
627
|
});
|
|
567
628
|
var AdsProvider = (props) => {
|
package/package.json
CHANGED
package/src/formats/Format.tsx
CHANGED
|
@@ -18,7 +18,7 @@ import { useContext, useEffect, useRef, useState } from 'react'
|
|
|
18
18
|
import { Keyboard, Linking, Modal, useWindowDimensions, View } from 'react-native'
|
|
19
19
|
import type { WebView, WebViewMessageEvent } from 'react-native-webview'
|
|
20
20
|
import FrameWebView from '../frame-webview'
|
|
21
|
-
import
|
|
21
|
+
import { presentSKOverlay, dismissSKOverlay, type SKOverlayPosition } from '../services/SkOverlay'
|
|
22
22
|
|
|
23
23
|
const sendMessage = (
|
|
24
24
|
webViewRef: React.RefObject<WebView>,
|
|
@@ -91,7 +91,6 @@ const Format = ({ code, messageId, wrapper, onEvent, ...otherParams }: FormatPro
|
|
|
91
91
|
setContainerStyles({})
|
|
92
92
|
setIframeStyles({})
|
|
93
93
|
setIframeLoaded(false)
|
|
94
|
-
closeSkOverlay()
|
|
95
94
|
resetModal()
|
|
96
95
|
context?.resetAll()
|
|
97
96
|
context?.captureError(new Error('Processing iframe error'))
|
|
@@ -104,6 +103,7 @@ const Format = ({ code, messageId, wrapper, onEvent, ...otherParams }: FormatPro
|
|
|
104
103
|
}
|
|
105
104
|
|
|
106
105
|
isModalInitRef.current = false
|
|
106
|
+
closeSkOverlay()
|
|
107
107
|
setModalOpen(false)
|
|
108
108
|
setModalLoaded(false)
|
|
109
109
|
setModalShown(false)
|
|
@@ -139,9 +139,9 @@ const Format = ({ code, messageId, wrapper, onEvent, ...otherParams }: FormatPro
|
|
|
139
139
|
})
|
|
140
140
|
}
|
|
141
141
|
|
|
142
|
-
const openSkOverlay = async (appStoreId: string, position:
|
|
142
|
+
const openSkOverlay = async (appStoreId: string, position: SKOverlayPosition, dismissible: boolean) => {
|
|
143
143
|
try {
|
|
144
|
-
await
|
|
144
|
+
await presentSKOverlay({ appStoreId, position, dismissible })
|
|
145
145
|
sendMessage(webViewRef, 'update-skoverlay-iframe', code, {
|
|
146
146
|
open: true
|
|
147
147
|
})
|
|
@@ -153,7 +153,7 @@ const Format = ({ code, messageId, wrapper, onEvent, ...otherParams }: FormatPro
|
|
|
153
153
|
|
|
154
154
|
const closeSkOverlay = async () => {
|
|
155
155
|
try {
|
|
156
|
-
await
|
|
156
|
+
await dismissSKOverlay()
|
|
157
157
|
sendMessage(webViewRef, 'update-skoverlay-iframe', code, {
|
|
158
158
|
open: false
|
|
159
159
|
})
|
|
@@ -244,7 +244,7 @@ const Format = ({ code, messageId, wrapper, onEvent, ...otherParams }: FormatPro
|
|
|
244
244
|
break
|
|
245
245
|
|
|
246
246
|
case 'open-skoverlay-iframe':
|
|
247
|
-
openSkOverlay(message.data.appStoreId, message.data.position, message.data.dismissible)
|
|
247
|
+
openSkOverlay(message.data.appStoreId, message.data.position as SKOverlayPosition, message.data.dismissible)
|
|
248
248
|
break
|
|
249
249
|
|
|
250
250
|
case 'close-skoverlay-iframe':
|