@kontextso/sdk-react-native 3.1.0-rc.2 → 3.1.0-rc.4
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 +77 -21
- package/dist/index.mjs +65 -9
- package/package.json +2 -2
- package/src/NativeRNKontext.ts +1 -1
- package/src/__tests__/util.test.ts +1 -1
- package/src/formats/Format.tsx +40 -15
- package/src/services/SkOverlay.ts +8 -8
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,22 +228,31 @@ var Format = ({ code, messageId, wrapper, onEvent, ...otherParams }) => {
|
|
|
195
228
|
};
|
|
196
229
|
const openSkOverlay = async (appStoreId, position, dismissible) => {
|
|
197
230
|
try {
|
|
198
|
-
await
|
|
231
|
+
if (!await presentSKOverlay({ appStoreId, position, dismissible })) {
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
199
234
|
sendMessage(webViewRef, "update-skoverlay-iframe", code, {
|
|
200
235
|
open: true
|
|
201
236
|
});
|
|
202
237
|
} catch (e) {
|
|
238
|
+
debug("error-open-skoverlay-iframe", {
|
|
239
|
+
error: e
|
|
240
|
+
});
|
|
203
241
|
console.error("error opening sk overlay", e);
|
|
204
|
-
reset();
|
|
205
242
|
}
|
|
206
243
|
};
|
|
207
244
|
const closeSkOverlay = async () => {
|
|
208
245
|
try {
|
|
209
|
-
await
|
|
246
|
+
if (!await dismissSKOverlay()) {
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
210
249
|
sendMessage(webViewRef, "update-skoverlay-iframe", code, {
|
|
211
250
|
open: false
|
|
212
251
|
});
|
|
213
252
|
} catch (e) {
|
|
253
|
+
debug("error-dismiss-skoverlay-iframe", {
|
|
254
|
+
error: e
|
|
255
|
+
});
|
|
214
256
|
console.error("error dismissing sk overlay", e);
|
|
215
257
|
}
|
|
216
258
|
};
|
|
@@ -243,7 +285,7 @@ var Format = ({ code, messageId, wrapper, onEvent, ...otherParams }) => {
|
|
|
243
285
|
break;
|
|
244
286
|
case "click-iframe":
|
|
245
287
|
if (message.data.url) {
|
|
246
|
-
|
|
288
|
+
import_react_native3.Linking.openURL(`${context?.adServerUrl}${message.data.url}`).catch(
|
|
247
289
|
(err) => console.error("error opening url", err)
|
|
248
290
|
);
|
|
249
291
|
}
|
|
@@ -281,7 +323,11 @@ var Format = ({ code, messageId, wrapper, onEvent, ...otherParams }) => {
|
|
|
281
323
|
messageStatusRef.current = "message-received" /* MessageReceived */;
|
|
282
324
|
break;
|
|
283
325
|
case "open-skoverlay-iframe":
|
|
284
|
-
openSkOverlay(
|
|
326
|
+
openSkOverlay(
|
|
327
|
+
message.data.appStoreId,
|
|
328
|
+
message.data.position,
|
|
329
|
+
message.data.dismissible
|
|
330
|
+
);
|
|
285
331
|
break;
|
|
286
332
|
case "close-skoverlay-iframe":
|
|
287
333
|
closeSkOverlay();
|
|
@@ -326,9 +372,19 @@ var Format = ({ code, messageId, wrapper, onEvent, ...otherParams }) => {
|
|
|
326
372
|
resetModal();
|
|
327
373
|
context?.captureError(new Error("Processing modal iframe error"));
|
|
328
374
|
break;
|
|
375
|
+
case "open-skoverlay-iframe":
|
|
376
|
+
openSkOverlay(
|
|
377
|
+
message.data.appStoreId,
|
|
378
|
+
message.data.position,
|
|
379
|
+
message.data.dismissible
|
|
380
|
+
);
|
|
381
|
+
break;
|
|
382
|
+
case "close-skoverlay-iframe":
|
|
383
|
+
closeSkOverlay();
|
|
384
|
+
break;
|
|
329
385
|
case "click-iframe":
|
|
330
386
|
if (message.data.url) {
|
|
331
|
-
|
|
387
|
+
import_react_native3.Linking.openURL(`${context?.adServerUrl}${message.data.url}`).catch(
|
|
332
388
|
(err) => console.error("error opening url", err)
|
|
333
389
|
);
|
|
334
390
|
}
|
|
@@ -412,10 +468,10 @@ var Format = ({ code, messageId, wrapper, onEvent, ...otherParams }) => {
|
|
|
412
468
|
return () => clearInterval(interval);
|
|
413
469
|
}, [isAdViewVisible]);
|
|
414
470
|
(0, import_react2.useEffect)(() => {
|
|
415
|
-
const showSubscription =
|
|
471
|
+
const showSubscription = import_react_native3.Keyboard.addListener("keyboardDidShow", (e) => {
|
|
416
472
|
keyboardHeightRef.current = e?.endCoordinates?.height ?? 0;
|
|
417
473
|
});
|
|
418
|
-
const hideSubscription =
|
|
474
|
+
const hideSubscription = import_react_native3.Keyboard.addListener("keyboardDidHide", () => {
|
|
419
475
|
keyboardHeightRef.current = 0;
|
|
420
476
|
});
|
|
421
477
|
return () => {
|
|
@@ -451,7 +507,7 @@ var Format = ({ code, messageId, wrapper, onEvent, ...otherParams }) => {
|
|
|
451
507
|
}
|
|
452
508
|
);
|
|
453
509
|
const interstitialContent = /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
454
|
-
|
|
510
|
+
import_react_native3.Modal,
|
|
455
511
|
{
|
|
456
512
|
visible: modalOpen,
|
|
457
513
|
transparent: true,
|
|
@@ -459,7 +515,7 @@ var Format = ({ code, messageId, wrapper, onEvent, ...otherParams }) => {
|
|
|
459
515
|
animationType: "slide",
|
|
460
516
|
statusBarTranslucent: true,
|
|
461
517
|
children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
462
|
-
|
|
518
|
+
import_react_native3.View,
|
|
463
519
|
{
|
|
464
520
|
style: {
|
|
465
521
|
flex: 1,
|
|
@@ -494,7 +550,7 @@ var Format = ({ code, messageId, wrapper, onEvent, ...otherParams }) => {
|
|
|
494
550
|
);
|
|
495
551
|
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
|
|
496
552
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
497
|
-
|
|
553
|
+
import_react_native3.View,
|
|
498
554
|
{
|
|
499
555
|
style: isAdViewVisible ? containerStyles : {
|
|
500
556
|
height: 0,
|
|
@@ -520,11 +576,11 @@ var InlineAd_default = InlineAd;
|
|
|
520
576
|
// src/context/AdsProvider.tsx
|
|
521
577
|
var import_sdk_react2 = require("@kontextso/sdk-react");
|
|
522
578
|
var import_netinfo = require("@react-native-community/netinfo");
|
|
523
|
-
var
|
|
579
|
+
var import_react_native4 = require("react-native");
|
|
524
580
|
var import_react_native_device_info = __toESM(require("react-native-device-info"));
|
|
525
581
|
|
|
526
582
|
// package.json
|
|
527
|
-
var version = "3.1.0-rc.
|
|
583
|
+
var version = "3.1.0-rc.4";
|
|
528
584
|
|
|
529
585
|
// src/context/AdsProvider.tsx
|
|
530
586
|
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
@@ -540,7 +596,7 @@ var getDevice = async () => {
|
|
|
540
596
|
const powerState = await import_react_native_device_info.default.getPowerState();
|
|
541
597
|
const deviceType = import_react_native_device_info.default.getDeviceType();
|
|
542
598
|
const soundOn = await NativeRNKontext_default.isSoundOn();
|
|
543
|
-
const screen =
|
|
599
|
+
const screen = import_react_native4.Dimensions.get("screen");
|
|
544
600
|
const networkInfo = await (0, import_netinfo.fetch)();
|
|
545
601
|
const mapDeviceTypeToHardwareType = () => {
|
|
546
602
|
switch (deviceType) {
|
|
@@ -577,14 +633,14 @@ var getDevice = async () => {
|
|
|
577
633
|
detail: networkInfo.type === import_netinfo.NetInfoStateType.cellular && networkInfo.details.cellularGeneration || void 0
|
|
578
634
|
},
|
|
579
635
|
os: {
|
|
580
|
-
name:
|
|
636
|
+
name: import_react_native4.Platform.OS,
|
|
581
637
|
version: import_react_native_device_info.default.getSystemVersion(),
|
|
582
638
|
locale: Intl.DateTimeFormat().resolvedOptions().locale,
|
|
583
639
|
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone
|
|
584
640
|
},
|
|
585
641
|
screen: {
|
|
586
|
-
darkMode:
|
|
587
|
-
dpr:
|
|
642
|
+
darkMode: import_react_native4.Appearance.getColorScheme() === "dark",
|
|
643
|
+
dpr: import_react_native4.PixelRatio.get(),
|
|
588
644
|
height: screen.height,
|
|
589
645
|
width: screen.width,
|
|
590
646
|
orientation: screen.width > screen.height ? "landscape" : "portrait"
|
|
@@ -617,7 +673,7 @@ var getApp = async () => {
|
|
|
617
673
|
};
|
|
618
674
|
var getSdk = async () => ({
|
|
619
675
|
name: "sdk-react-native",
|
|
620
|
-
platform:
|
|
676
|
+
platform: import_react_native4.Platform.OS === "ios" ? "ios" : "android",
|
|
621
677
|
version
|
|
622
678
|
});
|
|
623
679
|
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,22 +197,31 @@ var Format = ({ code, messageId, wrapper, onEvent, ...otherParams }) => {
|
|
|
164
197
|
};
|
|
165
198
|
const openSkOverlay = async (appStoreId, position, dismissible) => {
|
|
166
199
|
try {
|
|
167
|
-
await
|
|
200
|
+
if (!await presentSKOverlay({ appStoreId, position, dismissible })) {
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
168
203
|
sendMessage(webViewRef, "update-skoverlay-iframe", code, {
|
|
169
204
|
open: true
|
|
170
205
|
});
|
|
171
206
|
} catch (e) {
|
|
207
|
+
debug("error-open-skoverlay-iframe", {
|
|
208
|
+
error: e
|
|
209
|
+
});
|
|
172
210
|
console.error("error opening sk overlay", e);
|
|
173
|
-
reset();
|
|
174
211
|
}
|
|
175
212
|
};
|
|
176
213
|
const closeSkOverlay = async () => {
|
|
177
214
|
try {
|
|
178
|
-
await
|
|
215
|
+
if (!await dismissSKOverlay()) {
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
179
218
|
sendMessage(webViewRef, "update-skoverlay-iframe", code, {
|
|
180
219
|
open: false
|
|
181
220
|
});
|
|
182
221
|
} catch (e) {
|
|
222
|
+
debug("error-dismiss-skoverlay-iframe", {
|
|
223
|
+
error: e
|
|
224
|
+
});
|
|
183
225
|
console.error("error dismissing sk overlay", e);
|
|
184
226
|
}
|
|
185
227
|
};
|
|
@@ -250,7 +292,11 @@ var Format = ({ code, messageId, wrapper, onEvent, ...otherParams }) => {
|
|
|
250
292
|
messageStatusRef.current = "message-received" /* MessageReceived */;
|
|
251
293
|
break;
|
|
252
294
|
case "open-skoverlay-iframe":
|
|
253
|
-
openSkOverlay(
|
|
295
|
+
openSkOverlay(
|
|
296
|
+
message.data.appStoreId,
|
|
297
|
+
message.data.position,
|
|
298
|
+
message.data.dismissible
|
|
299
|
+
);
|
|
254
300
|
break;
|
|
255
301
|
case "close-skoverlay-iframe":
|
|
256
302
|
closeSkOverlay();
|
|
@@ -295,6 +341,16 @@ var Format = ({ code, messageId, wrapper, onEvent, ...otherParams }) => {
|
|
|
295
341
|
resetModal();
|
|
296
342
|
context?.captureError(new Error("Processing modal iframe error"));
|
|
297
343
|
break;
|
|
344
|
+
case "open-skoverlay-iframe":
|
|
345
|
+
openSkOverlay(
|
|
346
|
+
message.data.appStoreId,
|
|
347
|
+
message.data.position,
|
|
348
|
+
message.data.dismissible
|
|
349
|
+
);
|
|
350
|
+
break;
|
|
351
|
+
case "close-skoverlay-iframe":
|
|
352
|
+
closeSkOverlay();
|
|
353
|
+
break;
|
|
298
354
|
case "click-iframe":
|
|
299
355
|
if (message.data.url) {
|
|
300
356
|
Linking.openURL(`${context?.adServerUrl}${message.data.url}`).catch(
|
|
@@ -492,11 +548,11 @@ import {
|
|
|
492
548
|
log
|
|
493
549
|
} from "@kontextso/sdk-react";
|
|
494
550
|
import { fetch as fetchNetworkInfo, NetInfoStateType } from "@react-native-community/netinfo";
|
|
495
|
-
import { Appearance, Dimensions, PixelRatio, Platform } from "react-native";
|
|
551
|
+
import { Appearance, Dimensions, PixelRatio, Platform as Platform2 } from "react-native";
|
|
496
552
|
import DeviceInfo from "react-native-device-info";
|
|
497
553
|
|
|
498
554
|
// package.json
|
|
499
|
-
var version = "3.1.0-rc.
|
|
555
|
+
var version = "3.1.0-rc.4";
|
|
500
556
|
|
|
501
557
|
// src/context/AdsProvider.tsx
|
|
502
558
|
import { jsx as jsx4 } from "react/jsx-runtime";
|
|
@@ -549,7 +605,7 @@ var getDevice = async () => {
|
|
|
549
605
|
detail: networkInfo.type === NetInfoStateType.cellular && networkInfo.details.cellularGeneration || void 0
|
|
550
606
|
},
|
|
551
607
|
os: {
|
|
552
|
-
name:
|
|
608
|
+
name: Platform2.OS,
|
|
553
609
|
version: DeviceInfo.getSystemVersion(),
|
|
554
610
|
locale: Intl.DateTimeFormat().resolvedOptions().locale,
|
|
555
611
|
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone
|
|
@@ -589,7 +645,7 @@ var getApp = async () => {
|
|
|
589
645
|
};
|
|
590
646
|
var getSdk = async () => ({
|
|
591
647
|
name: "sdk-react-native",
|
|
592
|
-
platform:
|
|
648
|
+
platform: Platform2.OS === "ios" ? "ios" : "android",
|
|
593
649
|
version
|
|
594
650
|
});
|
|
595
651
|
var AdsProvider = (props) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kontextso/sdk-react-native",
|
|
3
|
-
"version": "3.1.0-rc.
|
|
3
|
+
"version": "3.1.0-rc.4",
|
|
4
4
|
"description": "Kontext SDK for React Native",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"format": "biome format --write ."
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
|
-
"@kontextso/sdk-common": "^1.0.
|
|
23
|
+
"@kontextso/sdk-common": "^1.0.3",
|
|
24
24
|
"@kontextso/typescript-config": "*",
|
|
25
25
|
"@react-native-community/netinfo": "11.3.1",
|
|
26
26
|
"@testing-library/dom": "^10.4.0",
|
package/src/NativeRNKontext.ts
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,25 +139,34 @@ 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
|
+
if (!(await presentSKOverlay({ appStoreId, position, dismissible }))) {
|
|
145
|
+
return
|
|
146
|
+
}
|
|
145
147
|
sendMessage(webViewRef, 'update-skoverlay-iframe', code, {
|
|
146
|
-
open: true
|
|
148
|
+
open: true,
|
|
147
149
|
})
|
|
148
150
|
} catch (e) {
|
|
151
|
+
debug('error-open-skoverlay-iframe', {
|
|
152
|
+
error: e,
|
|
153
|
+
})
|
|
149
154
|
console.error('error opening sk overlay', e)
|
|
150
|
-
reset()
|
|
151
155
|
}
|
|
152
156
|
}
|
|
153
157
|
|
|
154
158
|
const closeSkOverlay = async () => {
|
|
155
159
|
try {
|
|
156
|
-
await
|
|
160
|
+
if (!(await dismissSKOverlay())) {
|
|
161
|
+
return
|
|
162
|
+
}
|
|
157
163
|
sendMessage(webViewRef, 'update-skoverlay-iframe', code, {
|
|
158
|
-
open: false
|
|
164
|
+
open: false,
|
|
159
165
|
})
|
|
160
166
|
} catch (e) {
|
|
167
|
+
debug('error-dismiss-skoverlay-iframe', {
|
|
168
|
+
error: e,
|
|
169
|
+
})
|
|
161
170
|
console.error('error dismissing sk overlay', e)
|
|
162
171
|
}
|
|
163
172
|
}
|
|
@@ -244,7 +253,11 @@ const Format = ({ code, messageId, wrapper, onEvent, ...otherParams }: FormatPro
|
|
|
244
253
|
break
|
|
245
254
|
|
|
246
255
|
case 'open-skoverlay-iframe':
|
|
247
|
-
openSkOverlay(
|
|
256
|
+
openSkOverlay(
|
|
257
|
+
message.data.appStoreId,
|
|
258
|
+
message.data.position as SKOverlayPosition,
|
|
259
|
+
message.data.dismissible
|
|
260
|
+
)
|
|
248
261
|
break
|
|
249
262
|
|
|
250
263
|
case 'close-skoverlay-iframe':
|
|
@@ -299,6 +312,18 @@ const Format = ({ code, messageId, wrapper, onEvent, ...otherParams }: FormatPro
|
|
|
299
312
|
context?.captureError(new Error('Processing modal iframe error'))
|
|
300
313
|
break
|
|
301
314
|
|
|
315
|
+
case 'open-skoverlay-iframe':
|
|
316
|
+
openSkOverlay(
|
|
317
|
+
message.data.appStoreId,
|
|
318
|
+
message.data.position as SKOverlayPosition,
|
|
319
|
+
message.data.dismissible
|
|
320
|
+
)
|
|
321
|
+
break
|
|
322
|
+
|
|
323
|
+
case 'close-skoverlay-iframe':
|
|
324
|
+
closeSkOverlay()
|
|
325
|
+
break
|
|
326
|
+
|
|
302
327
|
case 'click-iframe':
|
|
303
328
|
if (message.data.url) {
|
|
304
329
|
Linking.openURL(`${context?.adServerUrl}${message.data.url}`).catch((err) =>
|
|
@@ -330,12 +355,12 @@ const Format = ({ code, messageId, wrapper, onEvent, ...otherParams }: FormatPro
|
|
|
330
355
|
}
|
|
331
356
|
|
|
332
357
|
/*
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
358
|
+
* Fix for Android issue in Saylo.
|
|
359
|
+
* When the iframe is loaded, the onLoad event is sometimes called two or more times.
|
|
360
|
+
* When these events fire too quickly, the init-iframe response from the server gets discarded.
|
|
361
|
+
* As a result, our SDK doesn’t send the update-iframe event back to the server, and the stream never starts.
|
|
362
|
+
* This fix will send the update-iframe event even if the init-iframe isn’t received.
|
|
363
|
+
*/
|
|
339
364
|
useEffect(() => {
|
|
340
365
|
const interval = setInterval(() => {
|
|
341
366
|
if (messageStatusRef.current === MessageStatus.None) {
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import { Platform } from 'react-native'
|
|
2
|
-
import NativeRNKontext from '../NativeRNKontext'
|
|
2
|
+
import NativeRNKontext from '../NativeRNKontext'
|
|
3
3
|
|
|
4
|
-
export type SKOverlayPosition = 'bottom' | 'bottomRaised'
|
|
4
|
+
export type SKOverlayPosition = 'bottom' | 'bottomRaised'
|
|
5
5
|
|
|
6
6
|
const isValidAppStoreId = (id: unknown): id is string => {
|
|
7
|
-
return typeof id ===
|
|
7
|
+
return typeof id === 'string' && /^\d+$/.test(id)
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
const isValidPosition = (p: unknown): p is SKOverlayPosition => {
|
|
11
|
-
return p ===
|
|
11
|
+
return p === 'bottom' || p === 'bottomRaised'
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
export async function presentSKOverlay(params: {
|
|
15
|
-
appStoreId: string
|
|
16
|
-
position: SKOverlayPosition
|
|
17
|
-
dismissible: boolean
|
|
15
|
+
appStoreId: string
|
|
16
|
+
position: SKOverlayPosition
|
|
17
|
+
dismissible: boolean
|
|
18
18
|
}) {
|
|
19
19
|
if (Platform.OS !== 'ios') {
|
|
20
20
|
return false
|
|
@@ -39,4 +39,4 @@ export async function dismissSKOverlay() {
|
|
|
39
39
|
return false
|
|
40
40
|
}
|
|
41
41
|
return NativeRNKontext.dismissSKOverlay()
|
|
42
|
-
}
|
|
42
|
+
}
|