@kontextso/sdk-react-native 3.1.0-rc.2 → 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 +52 -19
- package/dist/index.mjs +40 -7
- 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,10 +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
|
+
|
|
101
104
|
// src/NativeRNKontext.ts
|
|
102
105
|
var import_react_native = require("react-native");
|
|
103
106
|
var NativeRNKontext_default = import_react_native.TurboModuleRegistry.getEnforcing("RNKontext");
|
|
104
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
|
+
|
|
105
138
|
// src/formats/Format.tsx
|
|
106
139
|
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
107
140
|
var sendMessage = (webViewRef, type, code, data) => {
|
|
@@ -141,7 +174,7 @@ var Format = ({ code, messageId, wrapper, onEvent, ...otherParams }) => {
|
|
|
141
174
|
const messageStatusRef = (0, import_react2.useRef)("none" /* None */);
|
|
142
175
|
const modalInitTimeoutRef = (0, import_react2.useRef)(null);
|
|
143
176
|
const isModalInitRef = (0, import_react2.useRef)(false);
|
|
144
|
-
const { height: windowHeight, width: windowWidth } = (0,
|
|
177
|
+
const { height: windowHeight, width: windowWidth } = (0, import_react_native3.useWindowDimensions)();
|
|
145
178
|
const keyboardHeightRef = (0, import_react2.useRef)(0);
|
|
146
179
|
const isAdViewVisible = showIframe && iframeLoaded;
|
|
147
180
|
const reset = () => {
|
|
@@ -150,7 +183,6 @@ var Format = ({ code, messageId, wrapper, onEvent, ...otherParams }) => {
|
|
|
150
183
|
setContainerStyles({});
|
|
151
184
|
setIframeStyles({});
|
|
152
185
|
setIframeLoaded(false);
|
|
153
|
-
closeSkOverlay();
|
|
154
186
|
resetModal();
|
|
155
187
|
context?.resetAll();
|
|
156
188
|
context?.captureError(new Error("Processing iframe error"));
|
|
@@ -161,6 +193,7 @@ var Format = ({ code, messageId, wrapper, onEvent, ...otherParams }) => {
|
|
|
161
193
|
modalInitTimeoutRef.current = null;
|
|
162
194
|
}
|
|
163
195
|
isModalInitRef.current = false;
|
|
196
|
+
closeSkOverlay();
|
|
164
197
|
setModalOpen(false);
|
|
165
198
|
setModalLoaded(false);
|
|
166
199
|
setModalShown(false);
|
|
@@ -195,7 +228,7 @@ var Format = ({ code, messageId, wrapper, onEvent, ...otherParams }) => {
|
|
|
195
228
|
};
|
|
196
229
|
const openSkOverlay = async (appStoreId, position, dismissible) => {
|
|
197
230
|
try {
|
|
198
|
-
await
|
|
231
|
+
await presentSKOverlay({ appStoreId, position, dismissible });
|
|
199
232
|
sendMessage(webViewRef, "update-skoverlay-iframe", code, {
|
|
200
233
|
open: true
|
|
201
234
|
});
|
|
@@ -206,7 +239,7 @@ var Format = ({ code, messageId, wrapper, onEvent, ...otherParams }) => {
|
|
|
206
239
|
};
|
|
207
240
|
const closeSkOverlay = async () => {
|
|
208
241
|
try {
|
|
209
|
-
await
|
|
242
|
+
await dismissSKOverlay();
|
|
210
243
|
sendMessage(webViewRef, "update-skoverlay-iframe", code, {
|
|
211
244
|
open: false
|
|
212
245
|
});
|
|
@@ -243,7 +276,7 @@ var Format = ({ code, messageId, wrapper, onEvent, ...otherParams }) => {
|
|
|
243
276
|
break;
|
|
244
277
|
case "click-iframe":
|
|
245
278
|
if (message.data.url) {
|
|
246
|
-
|
|
279
|
+
import_react_native3.Linking.openURL(`${context?.adServerUrl}${message.data.url}`).catch(
|
|
247
280
|
(err) => console.error("error opening url", err)
|
|
248
281
|
);
|
|
249
282
|
}
|
|
@@ -328,7 +361,7 @@ var Format = ({ code, messageId, wrapper, onEvent, ...otherParams }) => {
|
|
|
328
361
|
break;
|
|
329
362
|
case "click-iframe":
|
|
330
363
|
if (message.data.url) {
|
|
331
|
-
|
|
364
|
+
import_react_native3.Linking.openURL(`${context?.adServerUrl}${message.data.url}`).catch(
|
|
332
365
|
(err) => console.error("error opening url", err)
|
|
333
366
|
);
|
|
334
367
|
}
|
|
@@ -412,10 +445,10 @@ var Format = ({ code, messageId, wrapper, onEvent, ...otherParams }) => {
|
|
|
412
445
|
return () => clearInterval(interval);
|
|
413
446
|
}, [isAdViewVisible]);
|
|
414
447
|
(0, import_react2.useEffect)(() => {
|
|
415
|
-
const showSubscription =
|
|
448
|
+
const showSubscription = import_react_native3.Keyboard.addListener("keyboardDidShow", (e) => {
|
|
416
449
|
keyboardHeightRef.current = e?.endCoordinates?.height ?? 0;
|
|
417
450
|
});
|
|
418
|
-
const hideSubscription =
|
|
451
|
+
const hideSubscription = import_react_native3.Keyboard.addListener("keyboardDidHide", () => {
|
|
419
452
|
keyboardHeightRef.current = 0;
|
|
420
453
|
});
|
|
421
454
|
return () => {
|
|
@@ -451,7 +484,7 @@ var Format = ({ code, messageId, wrapper, onEvent, ...otherParams }) => {
|
|
|
451
484
|
}
|
|
452
485
|
);
|
|
453
486
|
const interstitialContent = /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
454
|
-
|
|
487
|
+
import_react_native3.Modal,
|
|
455
488
|
{
|
|
456
489
|
visible: modalOpen,
|
|
457
490
|
transparent: true,
|
|
@@ -459,7 +492,7 @@ var Format = ({ code, messageId, wrapper, onEvent, ...otherParams }) => {
|
|
|
459
492
|
animationType: "slide",
|
|
460
493
|
statusBarTranslucent: true,
|
|
461
494
|
children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
462
|
-
|
|
495
|
+
import_react_native3.View,
|
|
463
496
|
{
|
|
464
497
|
style: {
|
|
465
498
|
flex: 1,
|
|
@@ -494,7 +527,7 @@ var Format = ({ code, messageId, wrapper, onEvent, ...otherParams }) => {
|
|
|
494
527
|
);
|
|
495
528
|
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
|
|
496
529
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
497
|
-
|
|
530
|
+
import_react_native3.View,
|
|
498
531
|
{
|
|
499
532
|
style: isAdViewVisible ? containerStyles : {
|
|
500
533
|
height: 0,
|
|
@@ -520,11 +553,11 @@ var InlineAd_default = InlineAd;
|
|
|
520
553
|
// src/context/AdsProvider.tsx
|
|
521
554
|
var import_sdk_react2 = require("@kontextso/sdk-react");
|
|
522
555
|
var import_netinfo = require("@react-native-community/netinfo");
|
|
523
|
-
var
|
|
556
|
+
var import_react_native4 = require("react-native");
|
|
524
557
|
var import_react_native_device_info = __toESM(require("react-native-device-info"));
|
|
525
558
|
|
|
526
559
|
// package.json
|
|
527
|
-
var version = "3.1.0-rc.
|
|
560
|
+
var version = "3.1.0-rc.3";
|
|
528
561
|
|
|
529
562
|
// src/context/AdsProvider.tsx
|
|
530
563
|
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
@@ -540,7 +573,7 @@ var getDevice = async () => {
|
|
|
540
573
|
const powerState = await import_react_native_device_info.default.getPowerState();
|
|
541
574
|
const deviceType = import_react_native_device_info.default.getDeviceType();
|
|
542
575
|
const soundOn = await NativeRNKontext_default.isSoundOn();
|
|
543
|
-
const screen =
|
|
576
|
+
const screen = import_react_native4.Dimensions.get("screen");
|
|
544
577
|
const networkInfo = await (0, import_netinfo.fetch)();
|
|
545
578
|
const mapDeviceTypeToHardwareType = () => {
|
|
546
579
|
switch (deviceType) {
|
|
@@ -577,14 +610,14 @@ var getDevice = async () => {
|
|
|
577
610
|
detail: networkInfo.type === import_netinfo.NetInfoStateType.cellular && networkInfo.details.cellularGeneration || void 0
|
|
578
611
|
},
|
|
579
612
|
os: {
|
|
580
|
-
name:
|
|
613
|
+
name: import_react_native4.Platform.OS,
|
|
581
614
|
version: import_react_native_device_info.default.getSystemVersion(),
|
|
582
615
|
locale: Intl.DateTimeFormat().resolvedOptions().locale,
|
|
583
616
|
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone
|
|
584
617
|
},
|
|
585
618
|
screen: {
|
|
586
|
-
darkMode:
|
|
587
|
-
dpr:
|
|
619
|
+
darkMode: import_react_native4.Appearance.getColorScheme() === "dark",
|
|
620
|
+
dpr: import_react_native4.PixelRatio.get(),
|
|
588
621
|
height: screen.height,
|
|
589
622
|
width: screen.width,
|
|
590
623
|
orientation: screen.width > screen.height ? "landscape" : "portrait"
|
|
@@ -617,7 +650,7 @@ var getApp = async () => {
|
|
|
617
650
|
};
|
|
618
651
|
var getSdk = async () => ({
|
|
619
652
|
name: "sdk-react-native",
|
|
620
|
-
platform:
|
|
653
|
+
platform: import_react_native4.Platform.OS === "ios" ? "ios" : "android",
|
|
621
654
|
version
|
|
622
655
|
});
|
|
623
656
|
var AdsProvider = (props) => {
|
package/dist/index.mjs
CHANGED
|
@@ -67,10 +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
|
+
|
|
70
73
|
// src/NativeRNKontext.ts
|
|
71
74
|
import { TurboModuleRegistry } from "react-native";
|
|
72
75
|
var NativeRNKontext_default = TurboModuleRegistry.getEnforcing("RNKontext");
|
|
73
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
|
+
|
|
74
107
|
// src/formats/Format.tsx
|
|
75
108
|
import { Fragment, jsx as jsx2, jsxs } from "react/jsx-runtime";
|
|
76
109
|
var sendMessage = (webViewRef, type, code, data) => {
|
|
@@ -119,7 +152,6 @@ var Format = ({ code, messageId, wrapper, onEvent, ...otherParams }) => {
|
|
|
119
152
|
setContainerStyles({});
|
|
120
153
|
setIframeStyles({});
|
|
121
154
|
setIframeLoaded(false);
|
|
122
|
-
closeSkOverlay();
|
|
123
155
|
resetModal();
|
|
124
156
|
context?.resetAll();
|
|
125
157
|
context?.captureError(new Error("Processing iframe error"));
|
|
@@ -130,6 +162,7 @@ var Format = ({ code, messageId, wrapper, onEvent, ...otherParams }) => {
|
|
|
130
162
|
modalInitTimeoutRef.current = null;
|
|
131
163
|
}
|
|
132
164
|
isModalInitRef.current = false;
|
|
165
|
+
closeSkOverlay();
|
|
133
166
|
setModalOpen(false);
|
|
134
167
|
setModalLoaded(false);
|
|
135
168
|
setModalShown(false);
|
|
@@ -164,7 +197,7 @@ var Format = ({ code, messageId, wrapper, onEvent, ...otherParams }) => {
|
|
|
164
197
|
};
|
|
165
198
|
const openSkOverlay = async (appStoreId, position, dismissible) => {
|
|
166
199
|
try {
|
|
167
|
-
await
|
|
200
|
+
await presentSKOverlay({ appStoreId, position, dismissible });
|
|
168
201
|
sendMessage(webViewRef, "update-skoverlay-iframe", code, {
|
|
169
202
|
open: true
|
|
170
203
|
});
|
|
@@ -175,7 +208,7 @@ var Format = ({ code, messageId, wrapper, onEvent, ...otherParams }) => {
|
|
|
175
208
|
};
|
|
176
209
|
const closeSkOverlay = async () => {
|
|
177
210
|
try {
|
|
178
|
-
await
|
|
211
|
+
await dismissSKOverlay();
|
|
179
212
|
sendMessage(webViewRef, "update-skoverlay-iframe", code, {
|
|
180
213
|
open: false
|
|
181
214
|
});
|
|
@@ -492,11 +525,11 @@ import {
|
|
|
492
525
|
log
|
|
493
526
|
} from "@kontextso/sdk-react";
|
|
494
527
|
import { fetch as fetchNetworkInfo, NetInfoStateType } from "@react-native-community/netinfo";
|
|
495
|
-
import { Appearance, Dimensions, PixelRatio, Platform } from "react-native";
|
|
528
|
+
import { Appearance, Dimensions, PixelRatio, Platform as Platform2 } from "react-native";
|
|
496
529
|
import DeviceInfo from "react-native-device-info";
|
|
497
530
|
|
|
498
531
|
// package.json
|
|
499
|
-
var version = "3.1.0-rc.
|
|
532
|
+
var version = "3.1.0-rc.3";
|
|
500
533
|
|
|
501
534
|
// src/context/AdsProvider.tsx
|
|
502
535
|
import { jsx as jsx4 } from "react/jsx-runtime";
|
|
@@ -549,7 +582,7 @@ var getDevice = async () => {
|
|
|
549
582
|
detail: networkInfo.type === NetInfoStateType.cellular && networkInfo.details.cellularGeneration || void 0
|
|
550
583
|
},
|
|
551
584
|
os: {
|
|
552
|
-
name:
|
|
585
|
+
name: Platform2.OS,
|
|
553
586
|
version: DeviceInfo.getSystemVersion(),
|
|
554
587
|
locale: Intl.DateTimeFormat().resolvedOptions().locale,
|
|
555
588
|
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone
|
|
@@ -589,7 +622,7 @@ var getApp = async () => {
|
|
|
589
622
|
};
|
|
590
623
|
var getSdk = async () => ({
|
|
591
624
|
name: "sdk-react-native",
|
|
592
|
-
platform:
|
|
625
|
+
platform: Platform2.OS === "ios" ? "ios" : "android",
|
|
593
626
|
version
|
|
594
627
|
});
|
|
595
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':
|