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