@kontextso/sdk-react-native 3.2.0-rc.0 → 3.2.0-rc.2
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 +109 -27
- package/dist/index.mjs +99 -17
- package/package.json +2 -2
- package/src/formats/Format.tsx +87 -13
- package/src/services/SkStoreProduct.ts +1 -1
- package/src/services/utils.ts +1 -2
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_native4 = require("react-native");
|
|
61
61
|
|
|
62
62
|
// src/frame-webview.tsx
|
|
63
63
|
var import_react = require("react");
|
|
@@ -105,10 +105,12 @@ var import_react_native2 = require("react-native");
|
|
|
105
105
|
var import_react_native = require("react-native");
|
|
106
106
|
var NativeRNKontext_default = import_react_native.TurboModuleRegistry.getEnforcing("RNKontext");
|
|
107
107
|
|
|
108
|
-
// src/services/
|
|
108
|
+
// src/services/utils.ts
|
|
109
109
|
var isValidAppStoreId = (id) => {
|
|
110
110
|
return typeof id === "string" && /^\d+$/.test(id);
|
|
111
111
|
};
|
|
112
|
+
|
|
113
|
+
// src/services/SkOverlay.ts
|
|
112
114
|
var isValidPosition = (p) => {
|
|
113
115
|
return p === "bottom" || p === "bottomRaised";
|
|
114
116
|
};
|
|
@@ -135,6 +137,24 @@ async function dismissSKOverlay() {
|
|
|
135
137
|
return NativeRNKontext_default.dismissSKOverlay();
|
|
136
138
|
}
|
|
137
139
|
|
|
140
|
+
// src/services/SkStoreProduct.ts
|
|
141
|
+
var import_react_native3 = require("react-native");
|
|
142
|
+
async function presentSKStoreProduct(appStoreId) {
|
|
143
|
+
if (import_react_native3.Platform.OS !== "ios") {
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
if (!isValidAppStoreId(appStoreId)) {
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
return NativeRNKontext_default.presentSKStoreProduct(appStoreId);
|
|
150
|
+
}
|
|
151
|
+
async function dismissSKStoreProduct() {
|
|
152
|
+
if (import_react_native3.Platform.OS !== "ios") {
|
|
153
|
+
return false;
|
|
154
|
+
}
|
|
155
|
+
return NativeRNKontext_default.dismissSKStoreProduct();
|
|
156
|
+
}
|
|
157
|
+
|
|
138
158
|
// src/formats/Format.tsx
|
|
139
159
|
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
140
160
|
var sendMessage = (webViewRef, type, code, data) => {
|
|
@@ -174,7 +194,7 @@ var Format = ({ code, messageId, wrapper, onEvent, ...otherParams }) => {
|
|
|
174
194
|
const messageStatusRef = (0, import_react2.useRef)("none" /* None */);
|
|
175
195
|
const modalInitTimeoutRef = (0, import_react2.useRef)(null);
|
|
176
196
|
const isModalInitRef = (0, import_react2.useRef)(false);
|
|
177
|
-
const { height: windowHeight, width: windowWidth } = (0,
|
|
197
|
+
const { height: windowHeight, width: windowWidth } = (0, import_react_native4.useWindowDimensions)();
|
|
178
198
|
const keyboardHeightRef = (0, import_react2.useRef)(0);
|
|
179
199
|
const isAdViewVisible = showIframe && iframeLoaded;
|
|
180
200
|
const reset = () => {
|
|
@@ -194,6 +214,7 @@ var Format = ({ code, messageId, wrapper, onEvent, ...otherParams }) => {
|
|
|
194
214
|
}
|
|
195
215
|
isModalInitRef.current = false;
|
|
196
216
|
closeSkOverlay();
|
|
217
|
+
closeSkStoreProduct();
|
|
197
218
|
setModalOpen(false);
|
|
198
219
|
setModalLoaded(false);
|
|
199
220
|
setModalShown(false);
|
|
@@ -256,6 +277,65 @@ var Format = ({ code, messageId, wrapper, onEvent, ...otherParams }) => {
|
|
|
256
277
|
console.error("error dismissing sk overlay", e);
|
|
257
278
|
}
|
|
258
279
|
};
|
|
280
|
+
const openSkStoreProduct = async (appStoreId) => {
|
|
281
|
+
try {
|
|
282
|
+
if (!await presentSKStoreProduct(appStoreId)) {
|
|
283
|
+
return false;
|
|
284
|
+
}
|
|
285
|
+
sendMessage(webViewRef, "update-skstoreproduct-iframe", code, {
|
|
286
|
+
open: true
|
|
287
|
+
});
|
|
288
|
+
return true;
|
|
289
|
+
} catch (e) {
|
|
290
|
+
debug("error-open-skstoreproduct-iframe", {
|
|
291
|
+
error: e
|
|
292
|
+
});
|
|
293
|
+
console.error("error opening sk store product", e);
|
|
294
|
+
return false;
|
|
295
|
+
}
|
|
296
|
+
};
|
|
297
|
+
const closeSkStoreProduct = async () => {
|
|
298
|
+
try {
|
|
299
|
+
if (!await dismissSKStoreProduct()) {
|
|
300
|
+
return false;
|
|
301
|
+
}
|
|
302
|
+
sendMessage(webViewRef, "update-skstoreproduct-iframe", code, {
|
|
303
|
+
open: false
|
|
304
|
+
});
|
|
305
|
+
return true;
|
|
306
|
+
} catch (e) {
|
|
307
|
+
debug("error-close-skstoreproduct-iframe", {
|
|
308
|
+
error: e
|
|
309
|
+
});
|
|
310
|
+
console.error("error closing sk store product", e);
|
|
311
|
+
return false;
|
|
312
|
+
}
|
|
313
|
+
};
|
|
314
|
+
const openUrl = async (message) => {
|
|
315
|
+
if (!message.data.url) {
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
try {
|
|
319
|
+
await import_react_native4.Linking.openURL(`${context?.adServerUrl}${message.data.url}`);
|
|
320
|
+
} catch (e) {
|
|
321
|
+
console.error("error opening url", e);
|
|
322
|
+
}
|
|
323
|
+
};
|
|
324
|
+
const handleClick = async (message) => {
|
|
325
|
+
if (message.data.appStoreId) {
|
|
326
|
+
try {
|
|
327
|
+
if (!await openSkStoreProduct(message.data.appStoreId)) {
|
|
328
|
+
await openUrl(message);
|
|
329
|
+
}
|
|
330
|
+
} catch (e) {
|
|
331
|
+
console.error("error opening sk store product", e);
|
|
332
|
+
await openUrl(message);
|
|
333
|
+
}
|
|
334
|
+
} else {
|
|
335
|
+
await openUrl(message);
|
|
336
|
+
}
|
|
337
|
+
context?.onAdClickInternal(message.data);
|
|
338
|
+
};
|
|
259
339
|
debug("format-update-state");
|
|
260
340
|
const onMessage = (event) => {
|
|
261
341
|
try {
|
|
@@ -284,12 +364,7 @@ var Format = ({ code, messageId, wrapper, onEvent, ...otherParams }) => {
|
|
|
284
364
|
setHeight(message.data.height);
|
|
285
365
|
break;
|
|
286
366
|
case "click-iframe":
|
|
287
|
-
|
|
288
|
-
import_react_native3.Linking.openURL(`${context?.adServerUrl}${message.data.url}`).catch(
|
|
289
|
-
(err) => console.error("error opening url", err)
|
|
290
|
-
);
|
|
291
|
-
}
|
|
292
|
-
context?.onAdClickInternal(message.data);
|
|
367
|
+
handleClick(message);
|
|
293
368
|
break;
|
|
294
369
|
case "view-iframe":
|
|
295
370
|
context?.onAdViewInternal(message.data);
|
|
@@ -332,6 +407,12 @@ var Format = ({ code, messageId, wrapper, onEvent, ...otherParams }) => {
|
|
|
332
407
|
case "close-skoverlay-iframe":
|
|
333
408
|
closeSkOverlay();
|
|
334
409
|
break;
|
|
410
|
+
case "open-skstoreproduct-iframe":
|
|
411
|
+
openSkStoreProduct(message.data.appStoreId);
|
|
412
|
+
break;
|
|
413
|
+
case "close-skstoreproduct-iframe":
|
|
414
|
+
closeSkStoreProduct();
|
|
415
|
+
break;
|
|
335
416
|
}
|
|
336
417
|
},
|
|
337
418
|
{
|
|
@@ -383,17 +464,18 @@ var Format = ({ code, messageId, wrapper, onEvent, ...otherParams }) => {
|
|
|
383
464
|
closeSkOverlay();
|
|
384
465
|
break;
|
|
385
466
|
case "click-iframe":
|
|
386
|
-
|
|
387
|
-
import_react_native3.Linking.openURL(`${context?.adServerUrl}${message.data.url}`).catch(
|
|
388
|
-
(err) => console.error("error opening url", err)
|
|
389
|
-
);
|
|
390
|
-
}
|
|
391
|
-
context?.onAdClickInternal(message.data);
|
|
467
|
+
handleClick(message);
|
|
392
468
|
break;
|
|
393
469
|
case "event-iframe":
|
|
394
470
|
onEvent?.(message.data);
|
|
395
471
|
context?.onAdEventInternal(message.data);
|
|
396
472
|
break;
|
|
473
|
+
case "open-skstoreproduct-iframe":
|
|
474
|
+
openSkStoreProduct(message.data.appStoreId);
|
|
475
|
+
break;
|
|
476
|
+
case "close-skstoreproduct-iframe":
|
|
477
|
+
closeSkStoreProduct();
|
|
478
|
+
break;
|
|
397
479
|
}
|
|
398
480
|
},
|
|
399
481
|
{
|
|
@@ -468,10 +550,10 @@ var Format = ({ code, messageId, wrapper, onEvent, ...otherParams }) => {
|
|
|
468
550
|
return () => clearInterval(interval);
|
|
469
551
|
}, [isAdViewVisible]);
|
|
470
552
|
(0, import_react2.useEffect)(() => {
|
|
471
|
-
const showSubscription =
|
|
553
|
+
const showSubscription = import_react_native4.Keyboard.addListener("keyboardDidShow", (e) => {
|
|
472
554
|
keyboardHeightRef.current = e?.endCoordinates?.height ?? 0;
|
|
473
555
|
});
|
|
474
|
-
const hideSubscription =
|
|
556
|
+
const hideSubscription = import_react_native4.Keyboard.addListener("keyboardDidHide", () => {
|
|
475
557
|
keyboardHeightRef.current = 0;
|
|
476
558
|
});
|
|
477
559
|
return () => {
|
|
@@ -507,7 +589,7 @@ var Format = ({ code, messageId, wrapper, onEvent, ...otherParams }) => {
|
|
|
507
589
|
}
|
|
508
590
|
);
|
|
509
591
|
const interstitialContent = /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
510
|
-
|
|
592
|
+
import_react_native4.Modal,
|
|
511
593
|
{
|
|
512
594
|
visible: modalOpen,
|
|
513
595
|
transparent: true,
|
|
@@ -515,7 +597,7 @@ var Format = ({ code, messageId, wrapper, onEvent, ...otherParams }) => {
|
|
|
515
597
|
animationType: "slide",
|
|
516
598
|
statusBarTranslucent: true,
|
|
517
599
|
children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
518
|
-
|
|
600
|
+
import_react_native4.View,
|
|
519
601
|
{
|
|
520
602
|
style: {
|
|
521
603
|
flex: 1,
|
|
@@ -550,7 +632,7 @@ var Format = ({ code, messageId, wrapper, onEvent, ...otherParams }) => {
|
|
|
550
632
|
);
|
|
551
633
|
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
|
|
552
634
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
553
|
-
|
|
635
|
+
import_react_native4.View,
|
|
554
636
|
{
|
|
555
637
|
style: isAdViewVisible ? containerStyles : {
|
|
556
638
|
height: 0,
|
|
@@ -576,11 +658,11 @@ var InlineAd_default = InlineAd;
|
|
|
576
658
|
// src/context/AdsProvider.tsx
|
|
577
659
|
var import_sdk_react2 = require("@kontextso/sdk-react");
|
|
578
660
|
var import_netinfo = require("@react-native-community/netinfo");
|
|
579
|
-
var
|
|
661
|
+
var import_react_native5 = require("react-native");
|
|
580
662
|
var import_react_native_device_info = __toESM(require("react-native-device-info"));
|
|
581
663
|
|
|
582
664
|
// package.json
|
|
583
|
-
var version = "3.
|
|
665
|
+
var version = "3.2.0-rc.1";
|
|
584
666
|
|
|
585
667
|
// src/context/AdsProvider.tsx
|
|
586
668
|
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
@@ -596,7 +678,7 @@ var getDevice = async () => {
|
|
|
596
678
|
const powerState = await import_react_native_device_info.default.getPowerState();
|
|
597
679
|
const deviceType = import_react_native_device_info.default.getDeviceType();
|
|
598
680
|
const soundOn = await NativeRNKontext_default.isSoundOn();
|
|
599
|
-
const screen =
|
|
681
|
+
const screen = import_react_native5.Dimensions.get("screen");
|
|
600
682
|
const networkInfo = await (0, import_netinfo.fetch)();
|
|
601
683
|
const mapDeviceTypeToHardwareType = () => {
|
|
602
684
|
switch (deviceType) {
|
|
@@ -633,14 +715,14 @@ var getDevice = async () => {
|
|
|
633
715
|
detail: networkInfo.type === import_netinfo.NetInfoStateType.cellular && networkInfo.details.cellularGeneration || void 0
|
|
634
716
|
},
|
|
635
717
|
os: {
|
|
636
|
-
name:
|
|
718
|
+
name: import_react_native5.Platform.OS,
|
|
637
719
|
version: import_react_native_device_info.default.getSystemVersion(),
|
|
638
720
|
locale: Intl.DateTimeFormat().resolvedOptions().locale,
|
|
639
721
|
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone
|
|
640
722
|
},
|
|
641
723
|
screen: {
|
|
642
|
-
darkMode:
|
|
643
|
-
dpr:
|
|
724
|
+
darkMode: import_react_native5.Appearance.getColorScheme() === "dark",
|
|
725
|
+
dpr: import_react_native5.PixelRatio.get(),
|
|
644
726
|
height: screen.height,
|
|
645
727
|
width: screen.width,
|
|
646
728
|
orientation: screen.width > screen.height ? "landscape" : "portrait"
|
|
@@ -673,7 +755,7 @@ var getApp = async () => {
|
|
|
673
755
|
};
|
|
674
756
|
var getSdk = async () => ({
|
|
675
757
|
name: "sdk-react-native",
|
|
676
|
-
platform:
|
|
758
|
+
platform: import_react_native5.Platform.OS === "ios" ? "ios" : "android",
|
|
677
759
|
version
|
|
678
760
|
});
|
|
679
761
|
var AdsProvider = (props) => {
|
package/dist/index.mjs
CHANGED
|
@@ -74,10 +74,12 @@ import { Platform } from "react-native";
|
|
|
74
74
|
import { TurboModuleRegistry } from "react-native";
|
|
75
75
|
var NativeRNKontext_default = TurboModuleRegistry.getEnforcing("RNKontext");
|
|
76
76
|
|
|
77
|
-
// src/services/
|
|
77
|
+
// src/services/utils.ts
|
|
78
78
|
var isValidAppStoreId = (id) => {
|
|
79
79
|
return typeof id === "string" && /^\d+$/.test(id);
|
|
80
80
|
};
|
|
81
|
+
|
|
82
|
+
// src/services/SkOverlay.ts
|
|
81
83
|
var isValidPosition = (p) => {
|
|
82
84
|
return p === "bottom" || p === "bottomRaised";
|
|
83
85
|
};
|
|
@@ -104,6 +106,24 @@ async function dismissSKOverlay() {
|
|
|
104
106
|
return NativeRNKontext_default.dismissSKOverlay();
|
|
105
107
|
}
|
|
106
108
|
|
|
109
|
+
// src/services/SkStoreProduct.ts
|
|
110
|
+
import { Platform as Platform2 } from "react-native";
|
|
111
|
+
async function presentSKStoreProduct(appStoreId) {
|
|
112
|
+
if (Platform2.OS !== "ios") {
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
if (!isValidAppStoreId(appStoreId)) {
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
return NativeRNKontext_default.presentSKStoreProduct(appStoreId);
|
|
119
|
+
}
|
|
120
|
+
async function dismissSKStoreProduct() {
|
|
121
|
+
if (Platform2.OS !== "ios") {
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
return NativeRNKontext_default.dismissSKStoreProduct();
|
|
125
|
+
}
|
|
126
|
+
|
|
107
127
|
// src/formats/Format.tsx
|
|
108
128
|
import { Fragment, jsx as jsx2, jsxs } from "react/jsx-runtime";
|
|
109
129
|
var sendMessage = (webViewRef, type, code, data) => {
|
|
@@ -163,6 +183,7 @@ var Format = ({ code, messageId, wrapper, onEvent, ...otherParams }) => {
|
|
|
163
183
|
}
|
|
164
184
|
isModalInitRef.current = false;
|
|
165
185
|
closeSkOverlay();
|
|
186
|
+
closeSkStoreProduct();
|
|
166
187
|
setModalOpen(false);
|
|
167
188
|
setModalLoaded(false);
|
|
168
189
|
setModalShown(false);
|
|
@@ -225,6 +246,65 @@ var Format = ({ code, messageId, wrapper, onEvent, ...otherParams }) => {
|
|
|
225
246
|
console.error("error dismissing sk overlay", e);
|
|
226
247
|
}
|
|
227
248
|
};
|
|
249
|
+
const openSkStoreProduct = async (appStoreId) => {
|
|
250
|
+
try {
|
|
251
|
+
if (!await presentSKStoreProduct(appStoreId)) {
|
|
252
|
+
return false;
|
|
253
|
+
}
|
|
254
|
+
sendMessage(webViewRef, "update-skstoreproduct-iframe", code, {
|
|
255
|
+
open: true
|
|
256
|
+
});
|
|
257
|
+
return true;
|
|
258
|
+
} catch (e) {
|
|
259
|
+
debug("error-open-skstoreproduct-iframe", {
|
|
260
|
+
error: e
|
|
261
|
+
});
|
|
262
|
+
console.error("error opening sk store product", e);
|
|
263
|
+
return false;
|
|
264
|
+
}
|
|
265
|
+
};
|
|
266
|
+
const closeSkStoreProduct = async () => {
|
|
267
|
+
try {
|
|
268
|
+
if (!await dismissSKStoreProduct()) {
|
|
269
|
+
return false;
|
|
270
|
+
}
|
|
271
|
+
sendMessage(webViewRef, "update-skstoreproduct-iframe", code, {
|
|
272
|
+
open: false
|
|
273
|
+
});
|
|
274
|
+
return true;
|
|
275
|
+
} catch (e) {
|
|
276
|
+
debug("error-close-skstoreproduct-iframe", {
|
|
277
|
+
error: e
|
|
278
|
+
});
|
|
279
|
+
console.error("error closing sk store product", e);
|
|
280
|
+
return false;
|
|
281
|
+
}
|
|
282
|
+
};
|
|
283
|
+
const openUrl = async (message) => {
|
|
284
|
+
if (!message.data.url) {
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
try {
|
|
288
|
+
await Linking.openURL(`${context?.adServerUrl}${message.data.url}`);
|
|
289
|
+
} catch (e) {
|
|
290
|
+
console.error("error opening url", e);
|
|
291
|
+
}
|
|
292
|
+
};
|
|
293
|
+
const handleClick = async (message) => {
|
|
294
|
+
if (message.data.appStoreId) {
|
|
295
|
+
try {
|
|
296
|
+
if (!await openSkStoreProduct(message.data.appStoreId)) {
|
|
297
|
+
await openUrl(message);
|
|
298
|
+
}
|
|
299
|
+
} catch (e) {
|
|
300
|
+
console.error("error opening sk store product", e);
|
|
301
|
+
await openUrl(message);
|
|
302
|
+
}
|
|
303
|
+
} else {
|
|
304
|
+
await openUrl(message);
|
|
305
|
+
}
|
|
306
|
+
context?.onAdClickInternal(message.data);
|
|
307
|
+
};
|
|
228
308
|
debug("format-update-state");
|
|
229
309
|
const onMessage = (event) => {
|
|
230
310
|
try {
|
|
@@ -253,12 +333,7 @@ var Format = ({ code, messageId, wrapper, onEvent, ...otherParams }) => {
|
|
|
253
333
|
setHeight(message.data.height);
|
|
254
334
|
break;
|
|
255
335
|
case "click-iframe":
|
|
256
|
-
|
|
257
|
-
Linking.openURL(`${context?.adServerUrl}${message.data.url}`).catch(
|
|
258
|
-
(err) => console.error("error opening url", err)
|
|
259
|
-
);
|
|
260
|
-
}
|
|
261
|
-
context?.onAdClickInternal(message.data);
|
|
336
|
+
handleClick(message);
|
|
262
337
|
break;
|
|
263
338
|
case "view-iframe":
|
|
264
339
|
context?.onAdViewInternal(message.data);
|
|
@@ -301,6 +376,12 @@ var Format = ({ code, messageId, wrapper, onEvent, ...otherParams }) => {
|
|
|
301
376
|
case "close-skoverlay-iframe":
|
|
302
377
|
closeSkOverlay();
|
|
303
378
|
break;
|
|
379
|
+
case "open-skstoreproduct-iframe":
|
|
380
|
+
openSkStoreProduct(message.data.appStoreId);
|
|
381
|
+
break;
|
|
382
|
+
case "close-skstoreproduct-iframe":
|
|
383
|
+
closeSkStoreProduct();
|
|
384
|
+
break;
|
|
304
385
|
}
|
|
305
386
|
},
|
|
306
387
|
{
|
|
@@ -352,17 +433,18 @@ var Format = ({ code, messageId, wrapper, onEvent, ...otherParams }) => {
|
|
|
352
433
|
closeSkOverlay();
|
|
353
434
|
break;
|
|
354
435
|
case "click-iframe":
|
|
355
|
-
|
|
356
|
-
Linking.openURL(`${context?.adServerUrl}${message.data.url}`).catch(
|
|
357
|
-
(err) => console.error("error opening url", err)
|
|
358
|
-
);
|
|
359
|
-
}
|
|
360
|
-
context?.onAdClickInternal(message.data);
|
|
436
|
+
handleClick(message);
|
|
361
437
|
break;
|
|
362
438
|
case "event-iframe":
|
|
363
439
|
onEvent?.(message.data);
|
|
364
440
|
context?.onAdEventInternal(message.data);
|
|
365
441
|
break;
|
|
442
|
+
case "open-skstoreproduct-iframe":
|
|
443
|
+
openSkStoreProduct(message.data.appStoreId);
|
|
444
|
+
break;
|
|
445
|
+
case "close-skstoreproduct-iframe":
|
|
446
|
+
closeSkStoreProduct();
|
|
447
|
+
break;
|
|
366
448
|
}
|
|
367
449
|
},
|
|
368
450
|
{
|
|
@@ -548,11 +630,11 @@ import {
|
|
|
548
630
|
log
|
|
549
631
|
} from "@kontextso/sdk-react";
|
|
550
632
|
import { fetch as fetchNetworkInfo, NetInfoStateType } from "@react-native-community/netinfo";
|
|
551
|
-
import { Appearance, Dimensions, PixelRatio, Platform as
|
|
633
|
+
import { Appearance, Dimensions, PixelRatio, Platform as Platform3 } from "react-native";
|
|
552
634
|
import DeviceInfo from "react-native-device-info";
|
|
553
635
|
|
|
554
636
|
// package.json
|
|
555
|
-
var version = "3.
|
|
637
|
+
var version = "3.2.0-rc.1";
|
|
556
638
|
|
|
557
639
|
// src/context/AdsProvider.tsx
|
|
558
640
|
import { jsx as jsx4 } from "react/jsx-runtime";
|
|
@@ -605,7 +687,7 @@ var getDevice = async () => {
|
|
|
605
687
|
detail: networkInfo.type === NetInfoStateType.cellular && networkInfo.details.cellularGeneration || void 0
|
|
606
688
|
},
|
|
607
689
|
os: {
|
|
608
|
-
name:
|
|
690
|
+
name: Platform3.OS,
|
|
609
691
|
version: DeviceInfo.getSystemVersion(),
|
|
610
692
|
locale: Intl.DateTimeFormat().resolvedOptions().locale,
|
|
611
693
|
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone
|
|
@@ -645,7 +727,7 @@ var getApp = async () => {
|
|
|
645
727
|
};
|
|
646
728
|
var getSdk = async () => ({
|
|
647
729
|
name: "sdk-react-native",
|
|
648
|
-
platform:
|
|
730
|
+
platform: Platform3.OS === "ios" ? "ios" : "android",
|
|
649
731
|
version
|
|
650
732
|
});
|
|
651
733
|
var AdsProvider = (props) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kontextso/sdk-react-native",
|
|
3
|
-
"version": "3.2.0-rc.
|
|
3
|
+
"version": "3.2.0-rc.2",
|
|
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.4",
|
|
24
24
|
"@kontextso/typescript-config": "*",
|
|
25
25
|
"@react-native-community/netinfo": "11.3.1",
|
|
26
26
|
"@testing-library/dom": "^10.4.0",
|
package/src/formats/Format.tsx
CHANGED
|
@@ -19,10 +19,14 @@ import { Keyboard, Linking, Modal, useWindowDimensions, View } from 'react-nativ
|
|
|
19
19
|
import type { WebView, WebViewMessageEvent } from 'react-native-webview'
|
|
20
20
|
import FrameWebView from '../frame-webview'
|
|
21
21
|
import { presentSKOverlay, dismissSKOverlay, type SKOverlayPosition } from '../services/SkOverlay'
|
|
22
|
+
import { presentSKStoreProduct, dismissSKStoreProduct } from '../services/SkStoreProduct'
|
|
22
23
|
|
|
23
24
|
const sendMessage = (
|
|
24
25
|
webViewRef: React.RefObject<WebView>,
|
|
25
|
-
type: Extract<
|
|
26
|
+
type: Extract<
|
|
27
|
+
IframeMessageType,
|
|
28
|
+
'update-iframe' | 'update-dimensions-iframe' | 'update-skoverlay-iframe' | 'update-skstoreproduct-iframe'
|
|
29
|
+
>,
|
|
26
30
|
code: string,
|
|
27
31
|
data: any
|
|
28
32
|
) => {
|
|
@@ -104,6 +108,7 @@ const Format = ({ code, messageId, wrapper, onEvent, ...otherParams }: FormatPro
|
|
|
104
108
|
|
|
105
109
|
isModalInitRef.current = false
|
|
106
110
|
closeSkOverlay()
|
|
111
|
+
closeSkStoreProduct()
|
|
107
112
|
setModalOpen(false)
|
|
108
113
|
setModalLoaded(false)
|
|
109
114
|
setModalShown(false)
|
|
@@ -171,6 +176,69 @@ const Format = ({ code, messageId, wrapper, onEvent, ...otherParams }: FormatPro
|
|
|
171
176
|
}
|
|
172
177
|
}
|
|
173
178
|
|
|
179
|
+
const openSkStoreProduct = async (appStoreId: string) => {
|
|
180
|
+
try {
|
|
181
|
+
if (!(await presentSKStoreProduct(appStoreId))) {
|
|
182
|
+
return false
|
|
183
|
+
}
|
|
184
|
+
sendMessage(webViewRef, 'update-skstoreproduct-iframe', code, {
|
|
185
|
+
open: true,
|
|
186
|
+
})
|
|
187
|
+
return true
|
|
188
|
+
} catch (e) {
|
|
189
|
+
debug('error-open-skstoreproduct-iframe', {
|
|
190
|
+
error: e,
|
|
191
|
+
})
|
|
192
|
+
console.error('error opening sk store product', e)
|
|
193
|
+
return false
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
const closeSkStoreProduct = async () => {
|
|
198
|
+
try {
|
|
199
|
+
if (!(await dismissSKStoreProduct())) {
|
|
200
|
+
return false
|
|
201
|
+
}
|
|
202
|
+
sendMessage(webViewRef, 'update-skstoreproduct-iframe', code, {
|
|
203
|
+
open: false,
|
|
204
|
+
})
|
|
205
|
+
return true
|
|
206
|
+
} catch (e) {
|
|
207
|
+
debug('error-close-skstoreproduct-iframe', {
|
|
208
|
+
error: e,
|
|
209
|
+
})
|
|
210
|
+
console.error('error closing sk store product', e)
|
|
211
|
+
return false
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
const openUrl = async (message: IframeMessage<'click-iframe'>) => {
|
|
216
|
+
if (!message.data.url) {
|
|
217
|
+
return
|
|
218
|
+
}
|
|
219
|
+
try {
|
|
220
|
+
await Linking.openURL(`${context?.adServerUrl}${message.data.url}`)
|
|
221
|
+
} catch (e) {
|
|
222
|
+
console.error('error opening url', e)
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
const handleClick = async(message: IframeMessage<'click-iframe'>) => {
|
|
227
|
+
if (message.data.appStoreId) {
|
|
228
|
+
try {
|
|
229
|
+
if (!(await openSkStoreProduct(message.data.appStoreId))) {
|
|
230
|
+
await openUrl(message)
|
|
231
|
+
}
|
|
232
|
+
} catch (e) {
|
|
233
|
+
console.error('error opening sk store product', e)
|
|
234
|
+
await openUrl(message)
|
|
235
|
+
}
|
|
236
|
+
} else {
|
|
237
|
+
await openUrl(message)
|
|
238
|
+
}
|
|
239
|
+
context?.onAdClickInternal(message.data)
|
|
240
|
+
}
|
|
241
|
+
|
|
174
242
|
debug('format-update-state')
|
|
175
243
|
|
|
176
244
|
const onMessage = (event: WebViewMessageEvent) => {
|
|
@@ -205,12 +273,7 @@ const Format = ({ code, messageId, wrapper, onEvent, ...otherParams }: FormatPro
|
|
|
205
273
|
break
|
|
206
274
|
|
|
207
275
|
case 'click-iframe':
|
|
208
|
-
|
|
209
|
-
Linking.openURL(`${context?.adServerUrl}${message.data.url}`).catch((err) =>
|
|
210
|
-
console.error('error opening url', err)
|
|
211
|
-
)
|
|
212
|
-
}
|
|
213
|
-
context?.onAdClickInternal(message.data)
|
|
276
|
+
handleClick(message)
|
|
214
277
|
break
|
|
215
278
|
|
|
216
279
|
case 'view-iframe':
|
|
@@ -263,6 +326,14 @@ const Format = ({ code, messageId, wrapper, onEvent, ...otherParams }: FormatPro
|
|
|
263
326
|
case 'close-skoverlay-iframe':
|
|
264
327
|
closeSkOverlay()
|
|
265
328
|
break
|
|
329
|
+
|
|
330
|
+
case 'open-skstoreproduct-iframe':
|
|
331
|
+
openSkStoreProduct(message.data.appStoreId)
|
|
332
|
+
break
|
|
333
|
+
|
|
334
|
+
case 'close-skstoreproduct-iframe':
|
|
335
|
+
closeSkStoreProduct()
|
|
336
|
+
break
|
|
266
337
|
}
|
|
267
338
|
},
|
|
268
339
|
{
|
|
@@ -325,18 +396,21 @@ const Format = ({ code, messageId, wrapper, onEvent, ...otherParams }: FormatPro
|
|
|
325
396
|
break
|
|
326
397
|
|
|
327
398
|
case 'click-iframe':
|
|
328
|
-
|
|
329
|
-
Linking.openURL(`${context?.adServerUrl}${message.data.url}`).catch((err) =>
|
|
330
|
-
console.error('error opening url', err)
|
|
331
|
-
)
|
|
332
|
-
}
|
|
333
|
-
context?.onAdClickInternal(message.data)
|
|
399
|
+
handleClick(message)
|
|
334
400
|
break
|
|
335
401
|
|
|
336
402
|
case 'event-iframe':
|
|
337
403
|
onEvent?.(message.data)
|
|
338
404
|
context?.onAdEventInternal(message.data)
|
|
339
405
|
break
|
|
406
|
+
|
|
407
|
+
case 'open-skstoreproduct-iframe':
|
|
408
|
+
openSkStoreProduct(message.data.appStoreId)
|
|
409
|
+
break
|
|
410
|
+
|
|
411
|
+
case 'close-skstoreproduct-iframe':
|
|
412
|
+
closeSkStoreProduct()
|
|
413
|
+
break
|
|
340
414
|
}
|
|
341
415
|
},
|
|
342
416
|
{
|
package/src/services/utils.ts
CHANGED