@kontextso/sdk-react-native 3.3.0-rc.6 → 3.3.1-rc.0
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/android/src/main/java/so/kontext/react/RNKontextModuleImpl.kt +12 -9
- package/dist/index.d.mts +5 -5
- package/dist/index.d.ts +5 -5
- package/dist/index.js +557 -536
- package/dist/index.mjs +533 -472
- package/package.json +3 -3
- package/src/NativeRNKontext.ts +1 -1
- package/src/formats/Format.tsx +18 -10
- package/src/frame-webview.tsx +26 -5
package/dist/index.js
CHANGED
|
@@ -1,231 +1,241 @@
|
|
|
1
|
-
|
|
2
|
-
var __create = Object.create
|
|
3
|
-
var __defProp = Object.defineProperty
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
8
|
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
}
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
11
12
|
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
14
|
for (let key of __getOwnPropNames(from))
|
|
14
15
|
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, {
|
|
16
|
-
get: () => from[key],
|
|
17
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable,
|
|
18
|
-
})
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
19
17
|
}
|
|
20
|
-
return to
|
|
21
|
-
}
|
|
22
|
-
var __toESM = (mod, isNodeMode, target) => (
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
)
|
|
32
|
-
)
|
|
33
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, '__esModule', { value: true }), mod)
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
34
29
|
|
|
35
30
|
// src/index.ts
|
|
36
|
-
var index_exports = {}
|
|
31
|
+
var index_exports = {};
|
|
37
32
|
__export(index_exports, {
|
|
38
33
|
AdsProvider: () => AdsProvider,
|
|
39
|
-
InlineAd: () => InlineAd_default
|
|
40
|
-
})
|
|
41
|
-
module.exports = __toCommonJS(index_exports)
|
|
34
|
+
InlineAd: () => InlineAd_default
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(index_exports);
|
|
42
37
|
|
|
43
38
|
// ../sdk-common/dist/index.mjs
|
|
44
39
|
function makeIframeMessage(type, opts) {
|
|
45
|
-
const { data, code, component } = opts
|
|
46
|
-
const message = { type, data: { ...
|
|
47
|
-
return message
|
|
40
|
+
const { data, code, component } = opts;
|
|
41
|
+
const message = { type, data: { ...data || {}, code, component } };
|
|
42
|
+
return message;
|
|
48
43
|
}
|
|
49
44
|
function handleIframeMessage(handler, opts) {
|
|
50
|
-
const { origin, code, component } = opts
|
|
45
|
+
const { origin, code, component } = opts;
|
|
51
46
|
return (event) => {
|
|
52
|
-
var _a, _b
|
|
53
|
-
if (origin && event.origin !== origin) return
|
|
54
|
-
const eventCode = (_a = event.data.data) == null ? void 0 : _a.code
|
|
55
|
-
if (eventCode && code && eventCode !== code) return
|
|
56
|
-
const eventComponent = (_b = event.data.data) == null ? void 0 : _b.component
|
|
57
|
-
if (eventComponent && component && eventComponent !== component) return
|
|
58
|
-
handler(event.data)
|
|
59
|
-
}
|
|
47
|
+
var _a, _b;
|
|
48
|
+
if (origin && event.origin !== origin) return;
|
|
49
|
+
const eventCode = (_a = event.data.data) == null ? void 0 : _a.code;
|
|
50
|
+
if (eventCode && code && eventCode !== code) return;
|
|
51
|
+
const eventComponent = (_b = event.data.data) == null ? void 0 : _b.component;
|
|
52
|
+
if (eventComponent && component && eventComponent !== component) return;
|
|
53
|
+
handler(event.data);
|
|
54
|
+
};
|
|
60
55
|
}
|
|
61
56
|
|
|
62
57
|
// src/formats/Format.tsx
|
|
63
|
-
var import_sdk_react = require(
|
|
64
|
-
var import_react2 = require(
|
|
65
|
-
var
|
|
58
|
+
var import_sdk_react = require("@kontextso/sdk-react");
|
|
59
|
+
var import_react2 = require("react");
|
|
60
|
+
var import_react_native5 = require("react-native");
|
|
66
61
|
|
|
67
62
|
// src/frame-webview.tsx
|
|
68
|
-
var import_react = require(
|
|
69
|
-
var
|
|
70
|
-
var
|
|
71
|
-
var
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
63
|
+
var import_react = require("react");
|
|
64
|
+
var import_react_native = require("react-native");
|
|
65
|
+
var import_react_native_webview = require("react-native-webview");
|
|
66
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
67
|
+
var FrameWebView = (0, import_react.forwardRef)(
|
|
68
|
+
({ iframeUrl, onMessage, style, onError, onLoad }, forwardedRef) => {
|
|
69
|
+
const isLoadedRef = (0, import_react.useRef)(false);
|
|
70
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
71
|
+
import_react_native_webview.WebView,
|
|
72
|
+
{
|
|
73
|
+
ref: forwardedRef,
|
|
74
|
+
source: {
|
|
75
|
+
uri: iframeUrl
|
|
76
|
+
},
|
|
77
|
+
onMessage,
|
|
78
|
+
style,
|
|
79
|
+
allowsInlineMediaPlayback: true,
|
|
80
|
+
mediaPlaybackRequiresUserAction: false,
|
|
81
|
+
javaScriptEnabled: true,
|
|
82
|
+
domStorageEnabled: true,
|
|
83
|
+
allowsFullscreenVideo: false,
|
|
84
|
+
originWhitelist: ["*"],
|
|
85
|
+
sharedCookiesEnabled: true,
|
|
86
|
+
thirdPartyCookiesEnabled: true,
|
|
87
|
+
injectedJavaScript: `
|
|
88
88
|
window.addEventListener("message", function(event) {
|
|
89
89
|
if (window.ReactNativeWebView && event.data) {
|
|
90
90
|
// ReactNativeWebView.postMessage only supports string data
|
|
91
91
|
window.ReactNativeWebView.postMessage(JSON.stringify(event.data));
|
|
92
92
|
}
|
|
93
93
|
}, false);
|
|
94
|
+
|
|
94
95
|
`,
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
96
|
+
onError: (event) => onError(
|
|
97
|
+
new Error(`${event.nativeEvent.title}: ${event.nativeEvent.description} [${event.nativeEvent.url}]`),
|
|
98
|
+
true
|
|
99
|
+
),
|
|
100
|
+
onLoad: () => {
|
|
101
|
+
isLoadedRef.current = true;
|
|
102
|
+
onLoad();
|
|
103
|
+
},
|
|
104
|
+
onShouldStartLoadWithRequest: (request) => {
|
|
105
|
+
if (!isLoadedRef.current || request.url.match(/^about:/) || request.url.startsWith(iframeUrl)) {
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
108
|
+
import_react_native.Linking.openURL(request.url).catch((err) => {
|
|
109
|
+
onError(new Error(`Failed to open URL: ${request.url} [${err.message}]`));
|
|
110
|
+
});
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
);
|
|
117
|
+
var frame_webview_default = FrameWebView;
|
|
100
118
|
|
|
101
119
|
// src/services/SkOverlay.ts
|
|
102
|
-
var
|
|
120
|
+
var import_react_native3 = require("react-native");
|
|
103
121
|
|
|
104
122
|
// src/NativeRNKontext.ts
|
|
105
|
-
var
|
|
106
|
-
var NativeRNKontext_default =
|
|
123
|
+
var import_react_native2 = require("react-native");
|
|
124
|
+
var NativeRNKontext_default = import_react_native2.TurboModuleRegistry.getEnforcing("RNKontext");
|
|
107
125
|
|
|
108
126
|
// src/services/utils.ts
|
|
109
127
|
var isValidAppStoreId = (id) => {
|
|
110
|
-
return typeof id ===
|
|
111
|
-
}
|
|
128
|
+
return typeof id === "string" && /^\d+$/.test(id);
|
|
129
|
+
};
|
|
112
130
|
|
|
113
131
|
// src/services/SkOverlay.ts
|
|
114
132
|
var isValidPosition = (p) => {
|
|
115
|
-
return p ===
|
|
116
|
-
}
|
|
133
|
+
return p === "bottom" || p === "bottomRaised";
|
|
134
|
+
};
|
|
117
135
|
async function presentSKOverlay(params) {
|
|
118
|
-
if (
|
|
119
|
-
return false
|
|
136
|
+
if (import_react_native3.Platform.OS !== "ios") {
|
|
137
|
+
return false;
|
|
120
138
|
}
|
|
121
|
-
let { appStoreId, position, dismissible } = params
|
|
139
|
+
let { appStoreId, position, dismissible } = params;
|
|
122
140
|
if (!isValidAppStoreId(appStoreId)) {
|
|
123
|
-
return false
|
|
141
|
+
return false;
|
|
124
142
|
}
|
|
125
143
|
if (!isValidPosition(position)) {
|
|
126
|
-
position =
|
|
144
|
+
position = "bottom";
|
|
127
145
|
}
|
|
128
|
-
if (typeof dismissible !==
|
|
129
|
-
dismissible = Boolean(dismissible)
|
|
146
|
+
if (typeof dismissible !== "boolean") {
|
|
147
|
+
dismissible = Boolean(dismissible);
|
|
130
148
|
}
|
|
131
|
-
return NativeRNKontext_default.presentSKOverlay(appStoreId, position, dismissible)
|
|
149
|
+
return NativeRNKontext_default.presentSKOverlay(appStoreId, position, dismissible);
|
|
132
150
|
}
|
|
133
151
|
async function dismissSKOverlay() {
|
|
134
|
-
if (
|
|
135
|
-
return false
|
|
152
|
+
if (import_react_native3.Platform.OS !== "ios") {
|
|
153
|
+
return false;
|
|
136
154
|
}
|
|
137
|
-
return NativeRNKontext_default.dismissSKOverlay()
|
|
155
|
+
return NativeRNKontext_default.dismissSKOverlay();
|
|
138
156
|
}
|
|
139
157
|
|
|
140
158
|
// src/services/SkStoreProduct.ts
|
|
141
|
-
var
|
|
159
|
+
var import_react_native4 = require("react-native");
|
|
142
160
|
async function presentSKStoreProduct(appStoreId) {
|
|
143
|
-
if (
|
|
144
|
-
return false
|
|
161
|
+
if (import_react_native4.Platform.OS !== "ios") {
|
|
162
|
+
return false;
|
|
145
163
|
}
|
|
146
164
|
if (!isValidAppStoreId(appStoreId)) {
|
|
147
|
-
return false
|
|
165
|
+
return false;
|
|
148
166
|
}
|
|
149
|
-
return NativeRNKontext_default.presentSKStoreProduct(appStoreId)
|
|
167
|
+
return NativeRNKontext_default.presentSKStoreProduct(appStoreId);
|
|
150
168
|
}
|
|
151
169
|
async function dismissSKStoreProduct() {
|
|
152
|
-
if (
|
|
153
|
-
return false
|
|
170
|
+
if (import_react_native4.Platform.OS !== "ios") {
|
|
171
|
+
return false;
|
|
154
172
|
}
|
|
155
|
-
return NativeRNKontext_default.dismissSKStoreProduct()
|
|
173
|
+
return NativeRNKontext_default.dismissSKStoreProduct();
|
|
156
174
|
}
|
|
157
175
|
|
|
158
176
|
// src/formats/Format.tsx
|
|
159
|
-
var import_jsx_runtime2 = require(
|
|
177
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
160
178
|
var sendMessage = (webViewRef, type, code, data) => {
|
|
161
179
|
const message = makeIframeMessage(type, {
|
|
162
180
|
data,
|
|
163
|
-
code
|
|
164
|
-
})
|
|
181
|
+
code
|
|
182
|
+
});
|
|
165
183
|
webViewRef.current?.injectJavaScript(`
|
|
166
184
|
window.dispatchEvent(new MessageEvent('message', {
|
|
167
185
|
data: ${JSON.stringify(message)}
|
|
168
186
|
}));
|
|
169
|
-
`)
|
|
170
|
-
}
|
|
187
|
+
`);
|
|
188
|
+
};
|
|
171
189
|
var getCachedContent = (context, bidId) => {
|
|
172
190
|
if (!bidId) {
|
|
173
|
-
return null
|
|
191
|
+
return null;
|
|
174
192
|
}
|
|
175
|
-
return context?.cachedContentRef?.current?.get(bidId) ?? null
|
|
176
|
-
}
|
|
193
|
+
return context?.cachedContentRef?.current?.get(bidId) ?? null;
|
|
194
|
+
};
|
|
177
195
|
var Format = ({ code, messageId, wrapper, onEvent, ...otherParams }) => {
|
|
178
|
-
const context = (0, import_react2.useContext)(import_sdk_react.AdsContext)
|
|
179
|
-
const bid = (0, import_sdk_react.useBid)({ code, messageId })
|
|
180
|
-
const [height, setHeight] = (0, import_react2.useState)(0)
|
|
181
|
-
const cachedContent = getCachedContent(context, bid?.bidId)
|
|
182
|
-
const iframeUrl = (0, import_sdk_react.useIframeUrl)(
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
)
|
|
190
|
-
const
|
|
191
|
-
const
|
|
192
|
-
const
|
|
193
|
-
const
|
|
194
|
-
const
|
|
195
|
-
const
|
|
196
|
-
const
|
|
197
|
-
const
|
|
198
|
-
const
|
|
199
|
-
const
|
|
200
|
-
const modalWebViewRef = (0, import_react2.useRef)(null)
|
|
201
|
-
const messageStatusRef = (0, import_react2.useRef)('none' /* None */)
|
|
202
|
-
const modalInitTimeoutRef = (0, import_react2.useRef)(null)
|
|
203
|
-
const isModalInitRef = (0, import_react2.useRef)(false)
|
|
204
|
-
const { height: windowHeight, width: windowWidth } = (0, import_react_native4.useWindowDimensions)()
|
|
205
|
-
const keyboardHeightRef = (0, import_react2.useRef)(0)
|
|
206
|
-
const isAdViewVisible = showIframe && iframeLoaded
|
|
196
|
+
const context = (0, import_react2.useContext)(import_sdk_react.AdsContext);
|
|
197
|
+
const bid = (0, import_sdk_react.useBid)({ code, messageId });
|
|
198
|
+
const [height, setHeight] = (0, import_react2.useState)(0);
|
|
199
|
+
const cachedContent = getCachedContent(context, bid?.bidId);
|
|
200
|
+
const iframeUrl = (0, import_sdk_react.useIframeUrl)(bid, code, messageId, "sdk-react-native", otherParams.theme, cachedContent);
|
|
201
|
+
const modalUrl = iframeUrl.replace("/api/frame/", "/api/modal/");
|
|
202
|
+
const [showIframe, setShowIframe] = (0, import_react2.useState)(false);
|
|
203
|
+
const [iframeLoaded, setIframeLoaded] = (0, import_react2.useState)(false);
|
|
204
|
+
const [modalOpen, setModalOpen] = (0, import_react2.useState)(false);
|
|
205
|
+
const [modalShown, setModalShown] = (0, import_react2.useState)(false);
|
|
206
|
+
const [modalLoaded, setModalLoaded] = (0, import_react2.useState)(false);
|
|
207
|
+
const [containerStyles, setContainerStyles] = (0, import_react2.useState)({});
|
|
208
|
+
const [iframeStyles, setIframeStyles] = (0, import_react2.useState)({});
|
|
209
|
+
const containerRef = (0, import_react2.useRef)(null);
|
|
210
|
+
const webViewRef = (0, import_react2.useRef)(null);
|
|
211
|
+
const modalWebViewRef = (0, import_react2.useRef)(null);
|
|
212
|
+
const messageStatusRef = (0, import_react2.useRef)("none" /* None */);
|
|
213
|
+
const modalInitTimeoutRef = (0, import_react2.useRef)(null);
|
|
214
|
+
const isModalInitRef = (0, import_react2.useRef)(false);
|
|
215
|
+
const { height: windowHeight, width: windowWidth } = (0, import_react_native5.useWindowDimensions)();
|
|
216
|
+
const keyboardHeightRef = (0, import_react2.useRef)(0);
|
|
217
|
+
const isAdViewVisible = showIframe && iframeLoaded;
|
|
207
218
|
const reset = () => {
|
|
208
|
-
setHeight(0)
|
|
209
|
-
setShowIframe(false)
|
|
210
|
-
setContainerStyles({})
|
|
211
|
-
setIframeStyles({})
|
|
212
|
-
setIframeLoaded(false)
|
|
213
|
-
resetModal()
|
|
214
|
-
context?.resetAll()
|
|
215
|
-
|
|
216
|
-
}
|
|
219
|
+
setHeight(0);
|
|
220
|
+
setShowIframe(false);
|
|
221
|
+
setContainerStyles({});
|
|
222
|
+
setIframeStyles({});
|
|
223
|
+
setIframeLoaded(false);
|
|
224
|
+
resetModal();
|
|
225
|
+
context?.resetAll();
|
|
226
|
+
};
|
|
217
227
|
const resetModal = () => {
|
|
218
228
|
if (modalInitTimeoutRef.current) {
|
|
219
|
-
clearTimeout(modalInitTimeoutRef.current)
|
|
220
|
-
modalInitTimeoutRef.current = null
|
|
229
|
+
clearTimeout(modalInitTimeoutRef.current);
|
|
230
|
+
modalInitTimeoutRef.current = null;
|
|
221
231
|
}
|
|
222
|
-
isModalInitRef.current = false
|
|
223
|
-
closeSkOverlay()
|
|
224
|
-
closeSkStoreProduct()
|
|
225
|
-
setModalOpen(false)
|
|
226
|
-
setModalLoaded(false)
|
|
227
|
-
setModalShown(false)
|
|
228
|
-
}
|
|
232
|
+
isModalInitRef.current = false;
|
|
233
|
+
closeSkOverlay();
|
|
234
|
+
closeSkStoreProduct();
|
|
235
|
+
setModalOpen(false);
|
|
236
|
+
setModalLoaded(false);
|
|
237
|
+
setModalShown(false);
|
|
238
|
+
};
|
|
229
239
|
const debug = (name, data = {}) => {
|
|
230
240
|
context?.onDebugEventInternal?.(name, {
|
|
231
241
|
code,
|
|
@@ -238,9 +248,9 @@ var Format = ({ code, messageId, wrapper, onEvent, ...otherParams }) => {
|
|
|
238
248
|
height,
|
|
239
249
|
containerStyles,
|
|
240
250
|
iframeStyles,
|
|
241
|
-
...data
|
|
242
|
-
})
|
|
243
|
-
}
|
|
251
|
+
...data
|
|
252
|
+
});
|
|
253
|
+
};
|
|
244
254
|
const debugModal = (name, data = {}) => {
|
|
245
255
|
context?.onDebugEventInternal?.(name, {
|
|
246
256
|
code,
|
|
@@ -251,542 +261,553 @@ var Format = ({ code, messageId, wrapper, onEvent, ...otherParams }) => {
|
|
|
251
261
|
modalOpen,
|
|
252
262
|
modalShown,
|
|
253
263
|
modalLoaded,
|
|
254
|
-
...data
|
|
255
|
-
})
|
|
256
|
-
}
|
|
264
|
+
...data
|
|
265
|
+
});
|
|
266
|
+
};
|
|
257
267
|
const openSkOverlay = async (appStoreId, position, dismissible) => {
|
|
258
268
|
try {
|
|
259
|
-
if (!
|
|
260
|
-
return
|
|
269
|
+
if (!await presentSKOverlay({ appStoreId, position, dismissible })) {
|
|
270
|
+
return;
|
|
261
271
|
}
|
|
262
|
-
sendMessage(webViewRef,
|
|
263
|
-
open: true
|
|
264
|
-
})
|
|
272
|
+
sendMessage(webViewRef, "update-skoverlay-iframe", code, {
|
|
273
|
+
open: true
|
|
274
|
+
});
|
|
265
275
|
} catch (e) {
|
|
266
|
-
debug(
|
|
267
|
-
error: e
|
|
268
|
-
})
|
|
269
|
-
console.error(
|
|
276
|
+
debug("error-open-skoverlay-iframe", {
|
|
277
|
+
error: e
|
|
278
|
+
});
|
|
279
|
+
console.error("error opening sk overlay", e);
|
|
270
280
|
}
|
|
271
|
-
}
|
|
281
|
+
};
|
|
272
282
|
const closeSkOverlay = async () => {
|
|
273
283
|
try {
|
|
274
|
-
if (!
|
|
275
|
-
return
|
|
284
|
+
if (!await dismissSKOverlay()) {
|
|
285
|
+
return;
|
|
276
286
|
}
|
|
277
|
-
sendMessage(webViewRef,
|
|
278
|
-
open: false
|
|
279
|
-
})
|
|
287
|
+
sendMessage(webViewRef, "update-skoverlay-iframe", code, {
|
|
288
|
+
open: false
|
|
289
|
+
});
|
|
280
290
|
} catch (e) {
|
|
281
|
-
debug(
|
|
282
|
-
error: e
|
|
283
|
-
})
|
|
284
|
-
console.error(
|
|
291
|
+
debug("error-dismiss-skoverlay-iframe", {
|
|
292
|
+
error: e
|
|
293
|
+
});
|
|
294
|
+
console.error("error dismissing sk overlay", e);
|
|
285
295
|
}
|
|
286
|
-
}
|
|
296
|
+
};
|
|
287
297
|
const openSkStoreProduct = async (appStoreId) => {
|
|
288
298
|
try {
|
|
289
|
-
if (!
|
|
290
|
-
return false
|
|
299
|
+
if (!await presentSKStoreProduct(appStoreId)) {
|
|
300
|
+
return false;
|
|
291
301
|
}
|
|
292
|
-
sendMessage(webViewRef,
|
|
293
|
-
open: true
|
|
294
|
-
})
|
|
295
|
-
return true
|
|
302
|
+
sendMessage(webViewRef, "update-skstoreproduct-iframe", code, {
|
|
303
|
+
open: true
|
|
304
|
+
});
|
|
305
|
+
return true;
|
|
296
306
|
} catch (e) {
|
|
297
|
-
debug(
|
|
298
|
-
error: e
|
|
299
|
-
})
|
|
300
|
-
console.error(
|
|
301
|
-
return false
|
|
307
|
+
debug("error-open-skstoreproduct-iframe", {
|
|
308
|
+
error: e
|
|
309
|
+
});
|
|
310
|
+
console.error("error opening sk store product", e);
|
|
311
|
+
return false;
|
|
302
312
|
}
|
|
303
|
-
}
|
|
313
|
+
};
|
|
304
314
|
const closeSkStoreProduct = async () => {
|
|
305
315
|
try {
|
|
306
|
-
if (!
|
|
307
|
-
return false
|
|
316
|
+
if (!await dismissSKStoreProduct()) {
|
|
317
|
+
return false;
|
|
308
318
|
}
|
|
309
|
-
sendMessage(webViewRef,
|
|
310
|
-
open: false
|
|
311
|
-
})
|
|
312
|
-
return true
|
|
319
|
+
sendMessage(webViewRef, "update-skstoreproduct-iframe", code, {
|
|
320
|
+
open: false
|
|
321
|
+
});
|
|
322
|
+
return true;
|
|
313
323
|
} catch (e) {
|
|
314
|
-
debug(
|
|
315
|
-
error: e
|
|
316
|
-
})
|
|
317
|
-
console.error(
|
|
318
|
-
return false
|
|
324
|
+
debug("error-close-skstoreproduct-iframe", {
|
|
325
|
+
error: e
|
|
326
|
+
});
|
|
327
|
+
console.error("error closing sk store product", e);
|
|
328
|
+
return false;
|
|
319
329
|
}
|
|
320
|
-
}
|
|
330
|
+
};
|
|
321
331
|
const openUrl = async (message) => {
|
|
322
332
|
if (!message.data.url) {
|
|
323
|
-
return
|
|
333
|
+
return;
|
|
324
334
|
}
|
|
325
335
|
try {
|
|
326
|
-
await
|
|
336
|
+
await import_react_native5.Linking.openURL(`${context?.adServerUrl}${message.data.url}`);
|
|
327
337
|
} catch (e) {
|
|
328
|
-
console.error(
|
|
338
|
+
console.error("error opening url", e);
|
|
329
339
|
}
|
|
330
|
-
}
|
|
340
|
+
};
|
|
331
341
|
const handleClick = async (message) => {
|
|
332
342
|
if (message.data.appStoreId) {
|
|
333
343
|
try {
|
|
334
|
-
if (!
|
|
335
|
-
await openUrl(message)
|
|
344
|
+
if (!await openSkStoreProduct(message.data.appStoreId)) {
|
|
345
|
+
await openUrl(message);
|
|
336
346
|
}
|
|
337
347
|
} catch (e) {
|
|
338
|
-
console.error(
|
|
339
|
-
await openUrl(message)
|
|
348
|
+
console.error("error opening sk store product", e);
|
|
349
|
+
await openUrl(message);
|
|
340
350
|
}
|
|
341
351
|
} else {
|
|
342
|
-
await openUrl(message)
|
|
352
|
+
await openUrl(message);
|
|
343
353
|
}
|
|
344
|
-
context?.onAdClickInternal(message.data)
|
|
345
|
-
}
|
|
346
|
-
debug(
|
|
354
|
+
context?.onAdClickInternal(message.data);
|
|
355
|
+
};
|
|
356
|
+
debug("format-update-state");
|
|
347
357
|
const onMessage = (event) => {
|
|
348
358
|
try {
|
|
349
|
-
const data = JSON.parse(event.nativeEvent.data)
|
|
350
|
-
debug(
|
|
351
|
-
message: data
|
|
352
|
-
})
|
|
359
|
+
const data = JSON.parse(event.nativeEvent.data);
|
|
360
|
+
debug("iframe-message", {
|
|
361
|
+
message: data
|
|
362
|
+
});
|
|
353
363
|
const messageHandler = handleIframeMessage(
|
|
354
364
|
(message) => {
|
|
355
365
|
switch (message.type) {
|
|
356
|
-
case
|
|
357
|
-
setIframeLoaded(true)
|
|
358
|
-
debug(
|
|
359
|
-
messageStatusRef.current =
|
|
360
|
-
sendMessage(webViewRef,
|
|
366
|
+
case "init-iframe":
|
|
367
|
+
setIframeLoaded(true);
|
|
368
|
+
debug("iframe-post-message");
|
|
369
|
+
messageStatusRef.current = "message-received" /* MessageReceived */;
|
|
370
|
+
sendMessage(webViewRef, "update-iframe", code, {
|
|
361
371
|
messages: context?.messages,
|
|
362
|
-
sdk:
|
|
372
|
+
sdk: "sdk-react-native",
|
|
363
373
|
otherParams,
|
|
364
|
-
messageId
|
|
365
|
-
})
|
|
366
|
-
break
|
|
367
|
-
case
|
|
368
|
-
reset()
|
|
369
|
-
break
|
|
370
|
-
case
|
|
371
|
-
setHeight(message.data.height)
|
|
372
|
-
break
|
|
373
|
-
case
|
|
374
|
-
handleClick(message)
|
|
375
|
-
break
|
|
376
|
-
case
|
|
377
|
-
context?.onAdViewInternal(message.data)
|
|
378
|
-
break
|
|
379
|
-
case
|
|
374
|
+
messageId
|
|
375
|
+
});
|
|
376
|
+
break;
|
|
377
|
+
case "error-iframe":
|
|
378
|
+
reset();
|
|
379
|
+
break;
|
|
380
|
+
case "resize-iframe":
|
|
381
|
+
setHeight(message.data.height);
|
|
382
|
+
break;
|
|
383
|
+
case "click-iframe":
|
|
384
|
+
handleClick(message);
|
|
385
|
+
break;
|
|
386
|
+
case "view-iframe":
|
|
387
|
+
context?.onAdViewInternal(message.data);
|
|
388
|
+
break;
|
|
389
|
+
case "ad-done-iframe":
|
|
380
390
|
if (bid?.bidId && message.data.cachedContent) {
|
|
381
|
-
context?.cachedContentRef?.current?.set(bid.bidId, message.data.cachedContent)
|
|
391
|
+
context?.cachedContentRef?.current?.set(bid.bidId, message.data.cachedContent);
|
|
382
392
|
}
|
|
383
|
-
break
|
|
384
|
-
case
|
|
385
|
-
setShowIframe(true)
|
|
386
|
-
break
|
|
387
|
-
case
|
|
388
|
-
setShowIframe(false)
|
|
389
|
-
break
|
|
390
|
-
case
|
|
391
|
-
setContainerStyles(message.data.containerStyles)
|
|
392
|
-
setIframeStyles(message.data.iframeStyles)
|
|
393
|
-
break
|
|
394
|
-
case
|
|
395
|
-
setModalOpen(true)
|
|
393
|
+
break;
|
|
394
|
+
case "show-iframe":
|
|
395
|
+
setShowIframe(true);
|
|
396
|
+
break;
|
|
397
|
+
case "hide-iframe":
|
|
398
|
+
setShowIframe(false);
|
|
399
|
+
break;
|
|
400
|
+
case "set-styles-iframe":
|
|
401
|
+
setContainerStyles(message.data.containerStyles);
|
|
402
|
+
setIframeStyles(message.data.iframeStyles);
|
|
403
|
+
break;
|
|
404
|
+
case "open-component-iframe":
|
|
405
|
+
setModalOpen(true);
|
|
396
406
|
modalInitTimeoutRef.current = setTimeout(() => {
|
|
397
407
|
if (!isModalInitRef.current) {
|
|
398
|
-
resetModal()
|
|
408
|
+
resetModal();
|
|
399
409
|
}
|
|
400
|
-
}, message.data.timeout ?? 5e3)
|
|
401
|
-
break
|
|
402
|
-
case
|
|
403
|
-
onEvent?.(message.data)
|
|
404
|
-
context?.onAdEventInternal(message.data)
|
|
405
|
-
messageStatusRef.current =
|
|
406
|
-
break
|
|
407
|
-
case
|
|
408
|
-
openSkOverlay(
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
410
|
+
}, message.data.timeout ?? 5e3);
|
|
411
|
+
break;
|
|
412
|
+
case "event-iframe":
|
|
413
|
+
onEvent?.(message.data);
|
|
414
|
+
context?.onAdEventInternal(message.data);
|
|
415
|
+
messageStatusRef.current = "message-received" /* MessageReceived */;
|
|
416
|
+
break;
|
|
417
|
+
case "open-skoverlay-iframe":
|
|
418
|
+
openSkOverlay(
|
|
419
|
+
message.data.appStoreId,
|
|
420
|
+
message.data.position,
|
|
421
|
+
message.data.dismissible
|
|
422
|
+
);
|
|
423
|
+
break;
|
|
424
|
+
case "close-skoverlay-iframe":
|
|
425
|
+
closeSkOverlay();
|
|
426
|
+
break;
|
|
427
|
+
case "open-skstoreproduct-iframe":
|
|
428
|
+
openSkStoreProduct(message.data.appStoreId);
|
|
429
|
+
break;
|
|
430
|
+
case "close-skstoreproduct-iframe":
|
|
431
|
+
closeSkStoreProduct();
|
|
432
|
+
break;
|
|
419
433
|
}
|
|
420
434
|
},
|
|
421
435
|
{
|
|
422
|
-
code
|
|
436
|
+
code
|
|
423
437
|
}
|
|
424
|
-
)
|
|
425
|
-
messageHandler({ data })
|
|
438
|
+
);
|
|
439
|
+
messageHandler({ data });
|
|
426
440
|
} catch (e) {
|
|
427
|
-
debug(
|
|
428
|
-
error: e
|
|
429
|
-
})
|
|
430
|
-
console.error(
|
|
431
|
-
reset()
|
|
441
|
+
debug("iframe-message-error", {
|
|
442
|
+
error: e
|
|
443
|
+
});
|
|
444
|
+
console.error("error parsing message from webview", e);
|
|
445
|
+
reset();
|
|
432
446
|
}
|
|
433
|
-
}
|
|
447
|
+
};
|
|
434
448
|
const onModalMessage = (event) => {
|
|
435
449
|
try {
|
|
436
|
-
const data = JSON.parse(event.nativeEvent.data)
|
|
437
|
-
debugModal(
|
|
438
|
-
message: data
|
|
439
|
-
})
|
|
450
|
+
const data = JSON.parse(event.nativeEvent.data);
|
|
451
|
+
debugModal("modal-iframe-message", {
|
|
452
|
+
message: data
|
|
453
|
+
});
|
|
440
454
|
const messageHandler = handleIframeMessage(
|
|
441
455
|
(message) => {
|
|
442
456
|
switch (message.type) {
|
|
443
|
-
case
|
|
444
|
-
resetModal()
|
|
445
|
-
break
|
|
446
|
-
case
|
|
447
|
-
isModalInitRef.current = true
|
|
457
|
+
case "close-component-iframe":
|
|
458
|
+
resetModal();
|
|
459
|
+
break;
|
|
460
|
+
case "init-component-iframe":
|
|
461
|
+
isModalInitRef.current = true;
|
|
448
462
|
if (modalInitTimeoutRef.current) {
|
|
449
|
-
clearTimeout(modalInitTimeoutRef.current)
|
|
450
|
-
modalInitTimeoutRef.current = null
|
|
463
|
+
clearTimeout(modalInitTimeoutRef.current);
|
|
464
|
+
modalInitTimeoutRef.current = null;
|
|
451
465
|
}
|
|
452
|
-
setModalShown(true)
|
|
453
|
-
break
|
|
454
|
-
case
|
|
455
|
-
case
|
|
456
|
-
resetModal()
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
break
|
|
465
|
-
case
|
|
466
|
-
|
|
467
|
-
break
|
|
468
|
-
case
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
break
|
|
475
|
-
case
|
|
476
|
-
|
|
477
|
-
break
|
|
466
|
+
setModalShown(true);
|
|
467
|
+
break;
|
|
468
|
+
case "error-component-iframe":
|
|
469
|
+
case "error-iframe":
|
|
470
|
+
resetModal();
|
|
471
|
+
break;
|
|
472
|
+
case "open-skoverlay-iframe":
|
|
473
|
+
openSkOverlay(
|
|
474
|
+
message.data.appStoreId,
|
|
475
|
+
message.data.position,
|
|
476
|
+
message.data.dismissible
|
|
477
|
+
);
|
|
478
|
+
break;
|
|
479
|
+
case "close-skoverlay-iframe":
|
|
480
|
+
closeSkOverlay();
|
|
481
|
+
break;
|
|
482
|
+
case "click-iframe":
|
|
483
|
+
handleClick(message);
|
|
484
|
+
break;
|
|
485
|
+
case "event-iframe":
|
|
486
|
+
onEvent?.(message.data);
|
|
487
|
+
context?.onAdEventInternal(message.data);
|
|
488
|
+
break;
|
|
489
|
+
case "open-skstoreproduct-iframe":
|
|
490
|
+
openSkStoreProduct(message.data.appStoreId);
|
|
491
|
+
break;
|
|
492
|
+
case "close-skstoreproduct-iframe":
|
|
493
|
+
closeSkStoreProduct();
|
|
494
|
+
break;
|
|
478
495
|
}
|
|
479
496
|
},
|
|
480
497
|
{
|
|
481
498
|
code,
|
|
482
|
-
component:
|
|
499
|
+
component: "modal"
|
|
483
500
|
}
|
|
484
|
-
)
|
|
485
|
-
messageHandler({ data })
|
|
501
|
+
);
|
|
502
|
+
messageHandler({ data });
|
|
486
503
|
} catch (e) {
|
|
487
|
-
debugModal(
|
|
488
|
-
error: e
|
|
489
|
-
})
|
|
490
|
-
console.error(
|
|
491
|
-
resetModal()
|
|
504
|
+
debugModal("modal-iframe-message-error", {
|
|
505
|
+
error: e
|
|
506
|
+
});
|
|
507
|
+
console.error("error parsing message from webview", e);
|
|
508
|
+
resetModal();
|
|
492
509
|
}
|
|
493
|
-
}
|
|
494
|
-
|
|
510
|
+
};
|
|
511
|
+
(0, import_react2.useEffect)(() => {
|
|
495
512
|
const interval = setInterval(() => {
|
|
496
|
-
if (messageStatusRef.current ===
|
|
497
|
-
return
|
|
513
|
+
if (messageStatusRef.current === "none" /* None */) {
|
|
514
|
+
return;
|
|
498
515
|
}
|
|
499
|
-
if (messageStatusRef.current ===
|
|
500
|
-
clearInterval(interval)
|
|
501
|
-
return
|
|
516
|
+
if (messageStatusRef.current === "message-received" /* MessageReceived */) {
|
|
517
|
+
clearInterval(interval);
|
|
518
|
+
return;
|
|
502
519
|
}
|
|
503
|
-
debug(
|
|
504
|
-
setIframeLoaded(true)
|
|
505
|
-
sendMessage(webViewRef,
|
|
520
|
+
debug("iframe-post-message-use-effect");
|
|
521
|
+
setIframeLoaded(true);
|
|
522
|
+
sendMessage(webViewRef, "update-iframe", code, {
|
|
506
523
|
messages: context?.messages,
|
|
507
|
-
sdk:
|
|
524
|
+
sdk: "sdk-react-native",
|
|
508
525
|
otherParams: {
|
|
509
526
|
...otherParams,
|
|
510
|
-
_useEffect: true
|
|
527
|
+
_useEffect: true
|
|
511
528
|
},
|
|
512
|
-
messageId
|
|
513
|
-
})
|
|
514
|
-
}, 500)
|
|
529
|
+
messageId
|
|
530
|
+
});
|
|
531
|
+
}, 500);
|
|
515
532
|
return () => {
|
|
516
|
-
clearInterval(interval)
|
|
517
|
-
}
|
|
518
|
-
}, [])
|
|
519
|
-
const paramsString = (0, import_sdk_react.convertParamsToString)(otherParams)
|
|
520
|
-
|
|
533
|
+
clearInterval(interval);
|
|
534
|
+
};
|
|
535
|
+
}, []);
|
|
536
|
+
const paramsString = (0, import_sdk_react.convertParamsToString)(otherParams);
|
|
537
|
+
(0, import_react2.useEffect)(() => {
|
|
521
538
|
if (!iframeLoaded || !context?.adServerUrl || !bid || !webViewRef.current) {
|
|
522
|
-
return
|
|
539
|
+
return;
|
|
523
540
|
}
|
|
524
|
-
debug(
|
|
525
|
-
sendMessage(webViewRef,
|
|
541
|
+
debug("iframe-post-message");
|
|
542
|
+
sendMessage(webViewRef, "update-iframe", code, {
|
|
526
543
|
data: { otherParams },
|
|
527
|
-
code
|
|
528
|
-
})
|
|
529
|
-
}, [paramsString, iframeLoaded, context?.adServerUrl, bid, code])
|
|
544
|
+
code
|
|
545
|
+
});
|
|
546
|
+
}, [paramsString, iframeLoaded, context?.adServerUrl, bid, code]);
|
|
530
547
|
const checkIfInViewport = () => {
|
|
531
|
-
if (!containerRef.current) return
|
|
548
|
+
if (!containerRef.current) return;
|
|
532
549
|
containerRef.current.measureInWindow((containerX, containerY, containerWidth, containerHeight) => {
|
|
533
|
-
sendMessage(webViewRef,
|
|
550
|
+
sendMessage(webViewRef, "update-dimensions-iframe", code, {
|
|
534
551
|
windowWidth,
|
|
535
552
|
windowHeight,
|
|
536
553
|
containerWidth,
|
|
537
554
|
containerHeight,
|
|
538
555
|
containerX,
|
|
539
556
|
containerY,
|
|
540
|
-
keyboardHeight: keyboardHeightRef.current
|
|
541
|
-
})
|
|
542
|
-
})
|
|
543
|
-
}
|
|
544
|
-
|
|
545
|
-
if (!isAdViewVisible) return
|
|
557
|
+
keyboardHeight: keyboardHeightRef.current
|
|
558
|
+
});
|
|
559
|
+
});
|
|
560
|
+
};
|
|
561
|
+
(0, import_react2.useEffect)(() => {
|
|
562
|
+
if (!isAdViewVisible) return;
|
|
546
563
|
const interval = setInterval(() => {
|
|
547
|
-
checkIfInViewport()
|
|
548
|
-
}, 250)
|
|
549
|
-
return () => clearInterval(interval)
|
|
550
|
-
}, [isAdViewVisible])
|
|
551
|
-
|
|
552
|
-
const showSubscription =
|
|
553
|
-
keyboardHeightRef.current = e?.endCoordinates?.height ?? 0
|
|
554
|
-
})
|
|
555
|
-
const hideSubscription =
|
|
556
|
-
keyboardHeightRef.current = 0
|
|
557
|
-
})
|
|
564
|
+
checkIfInViewport();
|
|
565
|
+
}, 250);
|
|
566
|
+
return () => clearInterval(interval);
|
|
567
|
+
}, [isAdViewVisible]);
|
|
568
|
+
(0, import_react2.useEffect)(() => {
|
|
569
|
+
const showSubscription = import_react_native5.Keyboard.addListener("keyboardDidShow", (e) => {
|
|
570
|
+
keyboardHeightRef.current = e?.endCoordinates?.height ?? 0;
|
|
571
|
+
});
|
|
572
|
+
const hideSubscription = import_react_native5.Keyboard.addListener("keyboardDidHide", () => {
|
|
573
|
+
keyboardHeightRef.current = 0;
|
|
574
|
+
});
|
|
558
575
|
return () => {
|
|
559
|
-
showSubscription.remove()
|
|
560
|
-
hideSubscription.remove()
|
|
561
|
-
keyboardHeightRef.current = 0
|
|
562
|
-
}
|
|
563
|
-
}, [])
|
|
576
|
+
showSubscription.remove();
|
|
577
|
+
hideSubscription.remove();
|
|
578
|
+
keyboardHeightRef.current = 0;
|
|
579
|
+
};
|
|
580
|
+
}, []);
|
|
564
581
|
if (!context || !bid || !iframeUrl) {
|
|
565
|
-
return null
|
|
582
|
+
return null;
|
|
566
583
|
}
|
|
567
|
-
const inlineContent = /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
width: '100%',
|
|
574
|
-
backgroundColor: 'transparent',
|
|
575
|
-
borderWidth: 0,
|
|
576
|
-
...iframeStyles,
|
|
577
|
-
},
|
|
578
|
-
onError: () => {
|
|
579
|
-
debug('iframe-error')
|
|
580
|
-
reset()
|
|
581
|
-
},
|
|
582
|
-
onLoad: () => {
|
|
583
|
-
debug('iframe-load')
|
|
584
|
-
messageStatusRef.current = 'initialized' /* Initialized */
|
|
585
|
-
},
|
|
586
|
-
})
|
|
587
|
-
const interstitialContent = /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native4.Modal, {
|
|
588
|
-
visible: modalOpen,
|
|
589
|
-
transparent: true,
|
|
590
|
-
onRequestClose: resetModal,
|
|
591
|
-
animationType: 'slide',
|
|
592
|
-
statusBarTranslucent: true,
|
|
593
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native4.View, {
|
|
584
|
+
const inlineContent = /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
585
|
+
frame_webview_default,
|
|
586
|
+
{
|
|
587
|
+
ref: webViewRef,
|
|
588
|
+
iframeUrl,
|
|
589
|
+
onMessage,
|
|
594
590
|
style: {
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
591
|
+
height,
|
|
592
|
+
width: "100%",
|
|
593
|
+
backgroundColor: "transparent",
|
|
594
|
+
borderWidth: 0,
|
|
595
|
+
...iframeStyles
|
|
598
596
|
},
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
597
|
+
onError: (error, shouldReset) => {
|
|
598
|
+
debug("iframe-error", {
|
|
599
|
+
error: error.toString()
|
|
600
|
+
});
|
|
601
|
+
context?.captureError(error);
|
|
602
|
+
if (shouldReset) {
|
|
603
|
+
reset();
|
|
604
|
+
}
|
|
605
|
+
},
|
|
606
|
+
onLoad: () => {
|
|
607
|
+
debug("iframe-load");
|
|
608
|
+
messageStatusRef.current = "initialized" /* Initialized */;
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
);
|
|
612
|
+
const interstitialContent = /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
613
|
+
import_react_native5.Modal,
|
|
614
|
+
{
|
|
615
|
+
visible: modalOpen,
|
|
616
|
+
transparent: true,
|
|
617
|
+
onRequestClose: resetModal,
|
|
618
|
+
animationType: "slide",
|
|
619
|
+
statusBarTranslucent: true,
|
|
620
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
621
|
+
import_react_native5.View,
|
|
622
|
+
{
|
|
623
|
+
style: {
|
|
624
|
+
flex: 1,
|
|
625
|
+
// Don't show the modal until the modal page is loaded and sends 'init-component-iframe' message back to SDK
|
|
626
|
+
...modalShown ? { opacity: 1, pointerEvents: "auto" } : { opacity: 0, pointerEvents: "none" }
|
|
627
|
+
},
|
|
628
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
629
|
+
frame_webview_default,
|
|
630
|
+
{
|
|
631
|
+
ref: modalWebViewRef,
|
|
632
|
+
iframeUrl: modalUrl,
|
|
633
|
+
onMessage: onModalMessage,
|
|
634
|
+
style: {
|
|
635
|
+
backgroundColor: "transparent",
|
|
636
|
+
height: "100%",
|
|
637
|
+
width: "100%",
|
|
638
|
+
borderWidth: 0
|
|
639
|
+
},
|
|
640
|
+
onError: (error, shouldReset) => {
|
|
641
|
+
debug("modal-error", {
|
|
642
|
+
error: error.toString()
|
|
643
|
+
});
|
|
644
|
+
context?.captureError(error);
|
|
645
|
+
if (shouldReset) {
|
|
646
|
+
resetModal();
|
|
647
|
+
}
|
|
648
|
+
},
|
|
649
|
+
onLoad: () => {
|
|
650
|
+
debug("modal-load");
|
|
651
|
+
setModalLoaded(true);
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
)
|
|
655
|
+
}
|
|
656
|
+
)
|
|
657
|
+
}
|
|
658
|
+
);
|
|
659
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
|
|
660
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
661
|
+
import_react_native5.View,
|
|
662
|
+
{
|
|
663
|
+
style: isAdViewVisible ? containerStyles : {
|
|
664
|
+
height: 0,
|
|
665
|
+
overflow: "hidden"
|
|
616
666
|
},
|
|
617
|
-
}),
|
|
618
|
-
}),
|
|
619
|
-
})
|
|
620
|
-
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, {
|
|
621
|
-
children: [
|
|
622
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native4.View, {
|
|
623
|
-
style: isAdViewVisible
|
|
624
|
-
? containerStyles
|
|
625
|
-
: {
|
|
626
|
-
height: 0,
|
|
627
|
-
overflow: 'hidden',
|
|
628
|
-
},
|
|
629
667
|
ref: containerRef,
|
|
630
|
-
children: wrapper ? wrapper(inlineContent) : inlineContent
|
|
631
|
-
}
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
})
|
|
635
|
-
}
|
|
636
|
-
var FormatWithErrorBoundary = (props) =>
|
|
637
|
-
|
|
638
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Format, { ...props }),
|
|
639
|
-
})
|
|
640
|
-
var Format_default = FormatWithErrorBoundary
|
|
668
|
+
children: wrapper ? wrapper(inlineContent) : inlineContent
|
|
669
|
+
}
|
|
670
|
+
),
|
|
671
|
+
interstitialContent
|
|
672
|
+
] });
|
|
673
|
+
};
|
|
674
|
+
var FormatWithErrorBoundary = (props) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_sdk_react.ErrorBoundary, { children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Format, { ...props }) });
|
|
675
|
+
var Format_default = FormatWithErrorBoundary;
|
|
641
676
|
|
|
642
677
|
// src/formats/InlineAd.tsx
|
|
643
|
-
var import_jsx_runtime3 = require(
|
|
678
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
644
679
|
var InlineAd = ({ code, messageId, wrapper, ...props }) => {
|
|
645
|
-
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Format_default, { code, messageId, wrapper, ...props })
|
|
646
|
-
}
|
|
647
|
-
var InlineAd_default = InlineAd
|
|
680
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Format_default, { code, messageId, wrapper, ...props });
|
|
681
|
+
};
|
|
682
|
+
var InlineAd_default = InlineAd;
|
|
648
683
|
|
|
649
684
|
// src/context/AdsProvider.tsx
|
|
650
|
-
var import_sdk_react2 = require(
|
|
651
|
-
var import_netinfo = require(
|
|
652
|
-
var
|
|
653
|
-
var import_react_native_device_info = __toESM(require(
|
|
685
|
+
var import_sdk_react2 = require("@kontextso/sdk-react");
|
|
686
|
+
var import_netinfo = require("@react-native-community/netinfo");
|
|
687
|
+
var import_react_native6 = require("react-native");
|
|
688
|
+
var import_react_native_device_info = __toESM(require("react-native-device-info"));
|
|
654
689
|
|
|
655
690
|
// package.json
|
|
656
|
-
var version =
|
|
691
|
+
var version = "3.3.1-rc.0";
|
|
657
692
|
|
|
658
693
|
// src/context/AdsProvider.tsx
|
|
659
|
-
var import_jsx_runtime4 = require(
|
|
694
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
660
695
|
ErrorUtils.setGlobalHandler((error, isFatal) => {
|
|
661
696
|
if (!isFatal) {
|
|
662
|
-
import_sdk_react2.log.warn(error)
|
|
697
|
+
import_sdk_react2.log.warn(error);
|
|
663
698
|
} else {
|
|
664
|
-
import_sdk_react2.log.error(error)
|
|
699
|
+
import_sdk_react2.log.error(error);
|
|
665
700
|
}
|
|
666
|
-
})
|
|
701
|
+
});
|
|
667
702
|
var batteryLevelToPercent = (level) => {
|
|
668
|
-
if (typeof level !==
|
|
669
|
-
if (level < 0) return void 0
|
|
670
|
-
return Math.max(0, Math.min(100, Math.round(level * 100)))
|
|
671
|
-
}
|
|
703
|
+
if (typeof level !== "number" || !isFinite(level)) return void 0;
|
|
704
|
+
if (level < 0) return void 0;
|
|
705
|
+
return Math.max(0, Math.min(100, Math.round(level * 100)));
|
|
706
|
+
};
|
|
672
707
|
var getDevice = async () => {
|
|
673
708
|
try {
|
|
674
|
-
const powerState = await import_react_native_device_info.default.getPowerState()
|
|
675
|
-
const deviceType = import_react_native_device_info.default.getDeviceType()
|
|
676
|
-
const soundOn = await NativeRNKontext_default.isSoundOn()
|
|
677
|
-
const screen =
|
|
678
|
-
const networkInfo = await (0, import_netinfo.fetch)()
|
|
709
|
+
const powerState = await import_react_native_device_info.default.getPowerState();
|
|
710
|
+
const deviceType = import_react_native_device_info.default.getDeviceType();
|
|
711
|
+
const soundOn = await NativeRNKontext_default.isSoundOn();
|
|
712
|
+
const screen = import_react_native6.Dimensions.get("screen");
|
|
713
|
+
const networkInfo = await (0, import_netinfo.fetch)();
|
|
679
714
|
const mapDeviceTypeToHardwareType = () => {
|
|
680
715
|
switch (deviceType) {
|
|
681
|
-
case
|
|
682
|
-
return
|
|
683
|
-
case
|
|
684
|
-
return
|
|
685
|
-
case
|
|
686
|
-
return
|
|
687
|
-
case
|
|
688
|
-
return
|
|
716
|
+
case "Handset":
|
|
717
|
+
return "handset";
|
|
718
|
+
case "Tablet":
|
|
719
|
+
return "tablet";
|
|
720
|
+
case "Tv":
|
|
721
|
+
return "tv";
|
|
722
|
+
case "Desktop":
|
|
723
|
+
return "desktop";
|
|
689
724
|
default:
|
|
690
|
-
return
|
|
725
|
+
return "other";
|
|
691
726
|
}
|
|
692
|
-
}
|
|
727
|
+
};
|
|
693
728
|
return {
|
|
694
729
|
hardware: {
|
|
695
730
|
brand: import_react_native_device_info.default.getBrand(),
|
|
696
731
|
model: import_react_native_device_info.default.getDeviceId(),
|
|
697
|
-
type: mapDeviceTypeToHardwareType()
|
|
732
|
+
type: mapDeviceTypeToHardwareType()
|
|
698
733
|
// bootTime: Not available without native module
|
|
699
734
|
// sdCardAvailable: Not available without native module
|
|
700
735
|
},
|
|
701
736
|
audio: {
|
|
702
|
-
muted: soundOn
|
|
737
|
+
muted: soundOn
|
|
703
738
|
// volume: Requires react-native-volume-manager
|
|
704
739
|
// outputPluggedIn: Not available without native module
|
|
705
740
|
// outputType: Not available without native module
|
|
706
741
|
},
|
|
707
742
|
network: {
|
|
708
|
-
carrier:
|
|
709
|
-
(networkInfo.type === import_netinfo.NetInfoStateType.cellular && networkInfo.details.carrier) || void 0,
|
|
743
|
+
carrier: networkInfo.type === import_netinfo.NetInfoStateType.cellular && networkInfo.details.carrier || void 0,
|
|
710
744
|
userAgent: await import_react_native_device_info.default.getUserAgent(),
|
|
711
|
-
type: [
|
|
712
|
-
|
|
713
|
-
import_netinfo.NetInfoStateType.cellular,
|
|
714
|
-
import_netinfo.NetInfoStateType.ethernet,
|
|
715
|
-
].includes(networkInfo.type)
|
|
716
|
-
? networkInfo.type
|
|
717
|
-
: import_netinfo.NetInfoStateType.other,
|
|
718
|
-
detail:
|
|
719
|
-
(networkInfo.type === import_netinfo.NetInfoStateType.cellular && networkInfo.details.cellularGeneration) ||
|
|
720
|
-
void 0,
|
|
745
|
+
type: [import_netinfo.NetInfoStateType.wifi, import_netinfo.NetInfoStateType.cellular, import_netinfo.NetInfoStateType.ethernet].includes(networkInfo.type) ? networkInfo.type : import_netinfo.NetInfoStateType.other,
|
|
746
|
+
detail: networkInfo.type === import_netinfo.NetInfoStateType.cellular && networkInfo.details.cellularGeneration || void 0
|
|
721
747
|
},
|
|
722
748
|
os: {
|
|
723
|
-
name:
|
|
749
|
+
name: import_react_native6.Platform.OS,
|
|
724
750
|
version: import_react_native_device_info.default.getSystemVersion(),
|
|
725
751
|
locale: Intl.DateTimeFormat().resolvedOptions().locale,
|
|
726
|
-
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone
|
|
752
|
+
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone
|
|
727
753
|
},
|
|
728
754
|
screen: {
|
|
729
|
-
darkMode:
|
|
730
|
-
dpr:
|
|
755
|
+
darkMode: import_react_native6.Appearance.getColorScheme() === "dark",
|
|
756
|
+
dpr: import_react_native6.PixelRatio.get(),
|
|
731
757
|
height: screen.height,
|
|
732
758
|
width: screen.width,
|
|
733
|
-
orientation: screen.width > screen.height ?
|
|
759
|
+
orientation: screen.width > screen.height ? "landscape" : "portrait"
|
|
734
760
|
},
|
|
735
761
|
power: {
|
|
736
762
|
batteryLevel: batteryLevelToPercent(powerState.batteryLevel),
|
|
737
763
|
batteryState: powerState.batteryState,
|
|
738
|
-
lowPowerMode: powerState.lowPowerMode
|
|
739
|
-
}
|
|
740
|
-
}
|
|
764
|
+
lowPowerMode: powerState.lowPowerMode
|
|
765
|
+
}
|
|
766
|
+
};
|
|
741
767
|
} catch (error) {
|
|
742
|
-
console.error(error)
|
|
743
|
-
return {}
|
|
768
|
+
console.error(error);
|
|
769
|
+
return {};
|
|
744
770
|
}
|
|
745
|
-
}
|
|
771
|
+
};
|
|
746
772
|
var getApp = async () => {
|
|
747
773
|
try {
|
|
748
774
|
return {
|
|
749
775
|
bundleId: import_react_native_device_info.default.getBundleId(),
|
|
750
776
|
firstInstallTime: await import_react_native_device_info.default.getFirstInstallTime(),
|
|
751
777
|
lastUpdateTime: await import_react_native_device_info.default.getLastUpdateTime(),
|
|
752
|
-
version: import_react_native_device_info.default.getVersion()
|
|
778
|
+
version: import_react_native_device_info.default.getVersion()
|
|
753
779
|
// Not supported in react-native-device-info v10
|
|
754
780
|
// startTime: await DeviceInfo.getStartupTime(),
|
|
755
|
-
}
|
|
781
|
+
};
|
|
756
782
|
} catch (error) {
|
|
757
|
-
console.error(error)
|
|
758
|
-
return {}
|
|
783
|
+
console.error(error);
|
|
784
|
+
return {};
|
|
759
785
|
}
|
|
760
|
-
}
|
|
786
|
+
};
|
|
761
787
|
var getSdk = async () => ({
|
|
762
|
-
name:
|
|
763
|
-
platform:
|
|
764
|
-
version
|
|
765
|
-
})
|
|
788
|
+
name: "sdk-react-native",
|
|
789
|
+
platform: import_react_native6.Platform.OS === "ios" ? "ios" : "android",
|
|
790
|
+
version
|
|
791
|
+
});
|
|
766
792
|
var getTcf = async () => {
|
|
767
793
|
try {
|
|
768
|
-
const tcfData = await NativeRNKontext_default.getTcfData()
|
|
794
|
+
const tcfData = await NativeRNKontext_default.getTcfData();
|
|
795
|
+
const gdpr = tcfData.gdprApplies === 0 || tcfData.gdprApplies === 1 ? tcfData.gdprApplies : void 0;
|
|
796
|
+
const gdprConsent = typeof tcfData.tcString === "string" && tcfData.tcString.length > 0 ? tcfData.tcString : void 0;
|
|
769
797
|
return {
|
|
770
|
-
gdpr:
|
|
771
|
-
gdprConsent:
|
|
772
|
-
}
|
|
798
|
+
...gdpr !== void 0 ? { gdpr } : {},
|
|
799
|
+
...gdprConsent !== void 0 ? { gdprConsent } : {}
|
|
800
|
+
};
|
|
773
801
|
} catch (error) {
|
|
774
|
-
console.error(error)
|
|
775
|
-
return {}
|
|
802
|
+
console.error(error);
|
|
803
|
+
return {};
|
|
776
804
|
}
|
|
777
|
-
}
|
|
805
|
+
};
|
|
778
806
|
var AdsProvider = (props) => {
|
|
779
|
-
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_sdk_react2.AdsProviderInternal, {
|
|
780
|
-
|
|
781
|
-
getDevice,
|
|
782
|
-
getSdk,
|
|
783
|
-
getApp,
|
|
784
|
-
getTcf,
|
|
785
|
-
})
|
|
786
|
-
}
|
|
807
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_sdk_react2.AdsProviderInternal, { ...props, getDevice, getSdk, getApp, getTcf });
|
|
808
|
+
};
|
|
787
809
|
// Annotate the CommonJS export names for ESM import in node:
|
|
788
|
-
0 &&
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
})
|
|
810
|
+
0 && (module.exports = {
|
|
811
|
+
AdsProvider,
|
|
812
|
+
InlineAd
|
|
813
|
+
});
|