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