@kontextso/sdk-react-native 3.2.0-rc.1 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kontextso/sdk-react-native",
3
- "version": "3.2.0-rc.1",
3
+ "version": "3.2.0-rc.3",
4
4
  "description": "Kontext SDK for React Native",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -179,33 +179,64 @@ const Format = ({ code, messageId, wrapper, onEvent, ...otherParams }: FormatPro
179
179
  const openSkStoreProduct = async (appStoreId: string) => {
180
180
  try {
181
181
  if (!(await presentSKStoreProduct(appStoreId))) {
182
- return
182
+ return false
183
183
  }
184
184
  sendMessage(webViewRef, 'update-skstoreproduct-iframe', code, {
185
185
  open: true,
186
186
  })
187
+ return true
187
188
  } catch (e) {
188
189
  debug('error-open-skstoreproduct-iframe', {
189
190
  error: e,
190
191
  })
191
192
  console.error('error opening sk store product', e)
193
+ return false
192
194
  }
193
195
  }
194
196
 
195
197
  const closeSkStoreProduct = async () => {
196
198
  try {
197
199
  if (!(await dismissSKStoreProduct())) {
198
- return
200
+ return false
199
201
  }
200
202
  sendMessage(webViewRef, 'update-skstoreproduct-iframe', code, {
201
203
  open: false,
202
204
  })
205
+ return true
203
206
  } catch (e) {
204
207
  debug('error-close-skstoreproduct-iframe', {
205
208
  error: e,
206
209
  })
207
210
  console.error('error closing sk store product', e)
211
+ return false
212
+ }
213
+ }
214
+
215
+ const openUrl = async (message: IframeMessage<'click-iframe'>) => {
216
+ if (!message.data.url) {
217
+ return
218
+ }
219
+ try {
220
+ await Linking.openURL(`${context?.adServerUrl}${message.data.url}`)
221
+ } catch (e) {
222
+ console.error('error opening url', e)
223
+ }
224
+ }
225
+
226
+ const handleClick = async (message: IframeMessage<'click-iframe'>) => {
227
+ if (message.data.appStoreId) {
228
+ try {
229
+ if (!(await openSkStoreProduct(message.data.appStoreId))) {
230
+ await openUrl(message)
231
+ }
232
+ } catch (e) {
233
+ console.error('error opening sk store product', e)
234
+ await openUrl(message)
235
+ }
236
+ } else {
237
+ await openUrl(message)
208
238
  }
239
+ context?.onAdClickInternal(message.data)
209
240
  }
210
241
 
211
242
  debug('format-update-state')
@@ -242,14 +273,7 @@ const Format = ({ code, messageId, wrapper, onEvent, ...otherParams }: FormatPro
242
273
  break
243
274
 
244
275
  case 'click-iframe':
245
- if (message.data.appStoreId) {
246
- openSkStoreProduct(message.data.appStoreId)
247
- } else if (message.data.url) {
248
- Linking.openURL(`${context?.adServerUrl}${message.data.url}`).catch((err) =>
249
- console.error('error opening url', err)
250
- )
251
- }
252
- context?.onAdClickInternal(message.data)
276
+ handleClick(message)
253
277
  break
254
278
 
255
279
  case 'view-iframe':
@@ -372,14 +396,7 @@ const Format = ({ code, messageId, wrapper, onEvent, ...otherParams }: FormatPro
372
396
  break
373
397
 
374
398
  case 'click-iframe':
375
- if (message.data.appStoreId) {
376
- openSkStoreProduct(message.data.appStoreId)
377
- } else if (message.data.url) {
378
- Linking.openURL(`${context?.adServerUrl}${message.data.url}`).catch((err) =>
379
- console.error('error opening url', err)
380
- )
381
- }
382
- context?.onAdClickInternal(message.data)
399
+ handleClick(message)
383
400
  break
384
401
 
385
402
  case 'event-iframe':