@kontextso/sdk-react-native 3.1.0-rc.0 → 3.1.0-rc.1

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.1.0-rc.0",
3
+ "version": "3.1.0-rc.1",
4
4
  "description": "Kontext SDK for React Native",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -20,7 +20,7 @@
20
20
  "format": "biome format --write ."
21
21
  },
22
22
  "devDependencies": {
23
- "@kontextso/sdk-common": "^1.0.0",
23
+ "@kontextso/sdk-common": "^1.0.2",
24
24
  "@kontextso/typescript-config": "*",
25
25
  "@react-native-community/netinfo": "11.3.1",
26
26
  "@testing-library/dom": "^10.4.0",
@@ -18,10 +18,11 @@ import { useContext, useEffect, useRef, useState } from 'react'
18
18
  import { Keyboard, Linking, Modal, useWindowDimensions, View } from 'react-native'
19
19
  import type { WebView, WebViewMessageEvent } from 'react-native-webview'
20
20
  import FrameWebView from '../frame-webview'
21
+ import NativeRNKontext from '../NativeRNKontext'
21
22
 
22
23
  const sendMessage = (
23
24
  webViewRef: React.RefObject<WebView>,
24
- type: Extract<IframeMessageType, 'update-iframe' | 'update-dimensions-iframe'>,
25
+ type: Extract<IframeMessageType, 'update-iframe' | 'update-dimensions-iframe' | 'update-skoverlay-iframe'>,
25
26
  code: string,
26
27
  data: any
27
28
  ) => {
@@ -90,6 +91,7 @@ const Format = ({ code, messageId, wrapper, onEvent, ...otherParams }: FormatPro
90
91
  setContainerStyles({})
91
92
  setIframeStyles({})
92
93
  setIframeLoaded(false)
94
+ closeSkOverlay()
93
95
  resetModal()
94
96
  context?.resetAll()
95
97
  context?.captureError(new Error('Processing iframe error'))
@@ -137,6 +139,29 @@ const Format = ({ code, messageId, wrapper, onEvent, ...otherParams }: FormatPro
137
139
  })
138
140
  }
139
141
 
142
+ const openSkOverlay = async (appStoreId: string, position: string, dismissible: boolean) => {
143
+ try {
144
+ await NativeRNKontext.presentSKOverlay(appStoreId, position, dismissible)
145
+ sendMessage(webViewRef, 'update-skoverlay-iframe', code, {
146
+ open: true
147
+ })
148
+ } catch (e) {
149
+ console.error('error opening sk overlay', e)
150
+ reset()
151
+ }
152
+ }
153
+
154
+ const closeSkOverlay = async () => {
155
+ try {
156
+ await NativeRNKontext.dismissSKOverlay()
157
+ sendMessage(webViewRef, 'update-skoverlay-iframe', code, {
158
+ open: false
159
+ })
160
+ } catch (e) {
161
+ console.error('error dismissing sk overlay', e)
162
+ }
163
+ }
164
+
140
165
  debug('format-update-state')
141
166
 
142
167
  const onMessage = (event: WebViewMessageEvent) => {
@@ -217,6 +242,14 @@ const Format = ({ code, messageId, wrapper, onEvent, ...otherParams }: FormatPro
217
242
  context?.onAdEventInternal(message.data)
218
243
  messageStatusRef.current = MessageStatus.MessageReceived
219
244
  break
245
+
246
+ case 'open-skoverlay-iframe':
247
+ openSkOverlay(message.data.appStoreId, message.data.position, message.data.dismissible)
248
+ break
249
+
250
+ case 'close-skoverlay-iframe':
251
+ closeSkOverlay()
252
+ break
220
253
  }
221
254
  },
222
255
  {
@@ -3,15 +3,34 @@ import NativeRNKontext from '../NativeRNKontext';
3
3
 
4
4
  export type SKOverlayPosition = 'bottom' | 'bottomRaised';
5
5
 
6
+ const isValidAppStoreId = (id: unknown): id is string => {
7
+ return typeof id === "string" && /^\d+$/.test(id);
8
+ }
9
+
10
+ const isValidPosition = (p: unknown): p is SKOverlayPosition => {
11
+ return p === "bottom" || p === "bottomRaised";
12
+ }
13
+
6
14
  export async function presentSKOverlay(params: {
7
15
  appStoreId: string;
8
- position?: SKOverlayPosition;
9
- dismissible?: boolean;
16
+ position: SKOverlayPosition;
17
+ dismissible: boolean;
10
18
  }) {
11
19
  if (Platform.OS !== 'ios') {
12
20
  return false
13
21
  }
14
- const { appStoreId, position = 'bottom', dismissible = true } = params
22
+ let { appStoreId, position, dismissible } = params
23
+
24
+ if (!isValidAppStoreId(appStoreId)) {
25
+ return false
26
+ }
27
+ if (!isValidPosition(position)) {
28
+ position = 'bottom'
29
+ }
30
+ if (typeof dismissible !== 'boolean') {
31
+ dismissible = Boolean(dismissible)
32
+ }
33
+
15
34
  return NativeRNKontext.presentSKOverlay(appStoreId, position, dismissible)
16
35
  }
17
36