@kontextso/sdk-react-native 2.4.1 → 2.5.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/README.md +1 -83
- package/dist/index.js +18 -3
- package/dist/index.mjs +19 -4
- package/package.json +2 -2
- package/src/formats/Format.tsx +20 -2
package/README.md
CHANGED
|
@@ -2,86 +2,4 @@
|
|
|
2
2
|
|
|
3
3
|
A lightweight React Native SDK for integrating Kontext's AI-powered ads into your iOS and Android apps.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
## Quick Setup
|
|
8
|
-
|
|
9
|
-
### Prerequisites
|
|
10
|
-
|
|
11
|
-
To get started, you will need to set up a publisher account to get a [`publisherToken` and `code`](https://docs.kontext.so/publishers#getting-started-is-easy).
|
|
12
|
-
|
|
13
|
-
### 1. Installation
|
|
14
|
-
|
|
15
|
-
```bash
|
|
16
|
-
# Install the SDK
|
|
17
|
-
npm install @kontextso/sdk-react-native
|
|
18
|
-
|
|
19
|
-
# Install required dependencies
|
|
20
|
-
npm install react-native-device-info
|
|
21
|
-
npm install react-native-webview
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
### 2. Initialize AdsProvider
|
|
25
|
-
|
|
26
|
-
Set up the ad provider early in your component tree:
|
|
27
|
-
|
|
28
|
-
```tsx
|
|
29
|
-
import React, { useState } from 'react';
|
|
30
|
-
import { AdsProvider } from '@kontextso/sdk-react-native';
|
|
31
|
-
|
|
32
|
-
interface Message {
|
|
33
|
-
id: string;
|
|
34
|
-
role: 'user' | 'assistant';
|
|
35
|
-
content: string;
|
|
36
|
-
createdAt: Date;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function App() {
|
|
40
|
-
const [messages, setMessages] = useState<Message[]>([]);
|
|
41
|
-
|
|
42
|
-
return (
|
|
43
|
-
<AdsProvider
|
|
44
|
-
publisherToken="<your-publisher-token>"
|
|
45
|
-
messages={messages}
|
|
46
|
-
userId="<unique-user-id>"
|
|
47
|
-
conversationId="<conversation-id>"
|
|
48
|
-
enabledPlacementCodes={["<placement-code>"]}
|
|
49
|
-
character={{
|
|
50
|
-
name: "<name>",
|
|
51
|
-
avatarUrl: "<url>",
|
|
52
|
-
isNsfw: <boolean>,
|
|
53
|
-
id: "<character-id>",
|
|
54
|
-
greeting: "<greeting text>",
|
|
55
|
-
persona: "<persona description>",
|
|
56
|
-
tags: ["tag1", "tag2"],
|
|
57
|
-
}}
|
|
58
|
-
>
|
|
59
|
-
{/* Rest of your app components */}
|
|
60
|
-
</AdsProvider>
|
|
61
|
-
);
|
|
62
|
-
}
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
### 3. Display Your First Ad
|
|
66
|
-
|
|
67
|
-
Insert ads inline within your UI, tied to messages:
|
|
68
|
-
|
|
69
|
-
```tsx
|
|
70
|
-
function MessageList({ messages }: { messages: Message[] }) {
|
|
71
|
-
return (
|
|
72
|
-
<View>
|
|
73
|
-
{messages.map((m) => (
|
|
74
|
-
<View key={m.id}>
|
|
75
|
-
{/* Your message component */}
|
|
76
|
-
<InlineAd code="<placement-code>" messageId={m.id} />
|
|
77
|
-
</View>
|
|
78
|
-
))}
|
|
79
|
-
</View>
|
|
80
|
-
);
|
|
81
|
-
}
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
## Additional Resources
|
|
85
|
-
|
|
86
|
-
* Explore a working [Demo Project featuring SDK integration](https://github.com/kontextso/sdk-react-native-demo).
|
|
87
|
-
* Full documentation: [Kontext React Native SDK](https://docs.kontext.so/sdk/react-native).
|
|
5
|
+
📚 Full documentation: [Kontext React Native SDK](https://docs.kontext.so/sdk/react-native).
|
package/dist/index.js
CHANGED
|
@@ -126,6 +126,7 @@ var Format = ({ code, messageId, wrapper, onEvent, ...otherParams }) => {
|
|
|
126
126
|
const modalInitTimeoutRef = (0, import_react2.useRef)(null);
|
|
127
127
|
const isModalInitRef = (0, import_react2.useRef)(false);
|
|
128
128
|
const { height: windowHeight, width: windowWidth } = (0, import_react_native.useWindowDimensions)();
|
|
129
|
+
const keyboardHeightRef = (0, import_react2.useRef)(0);
|
|
129
130
|
const isAdViewVisible = showIframe && iframeLoaded;
|
|
130
131
|
const reset = () => {
|
|
131
132
|
setHeight(0);
|
|
@@ -322,7 +323,8 @@ var Format = ({ code, messageId, wrapper, onEvent, ...otherParams }) => {
|
|
|
322
323
|
containerWidth,
|
|
323
324
|
containerHeight,
|
|
324
325
|
containerX,
|
|
325
|
-
containerY
|
|
326
|
+
containerY,
|
|
327
|
+
keyboardHeight: keyboardHeightRef.current
|
|
326
328
|
});
|
|
327
329
|
});
|
|
328
330
|
};
|
|
@@ -333,7 +335,20 @@ var Format = ({ code, messageId, wrapper, onEvent, ...otherParams }) => {
|
|
|
333
335
|
}, 250);
|
|
334
336
|
return () => clearInterval(interval);
|
|
335
337
|
}, [isAdViewVisible]);
|
|
336
|
-
|
|
338
|
+
(0, import_react2.useEffect)(() => {
|
|
339
|
+
const showSubscription = import_react_native.Keyboard.addListener("keyboardDidShow", (e) => {
|
|
340
|
+
keyboardHeightRef.current = e?.endCoordinates?.height ?? 0;
|
|
341
|
+
});
|
|
342
|
+
const hideSubscription = import_react_native.Keyboard.addListener("keyboardDidHide", () => {
|
|
343
|
+
keyboardHeightRef.current = 0;
|
|
344
|
+
});
|
|
345
|
+
return () => {
|
|
346
|
+
showSubscription.remove();
|
|
347
|
+
hideSubscription.remove();
|
|
348
|
+
keyboardHeightRef.current = 0;
|
|
349
|
+
};
|
|
350
|
+
}, []);
|
|
351
|
+
if (!context || !bid || !iframeUrl) {
|
|
337
352
|
return null;
|
|
338
353
|
}
|
|
339
354
|
const inlineContent = /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
@@ -435,7 +450,7 @@ var import_react_native2 = require("react-native");
|
|
|
435
450
|
var NativeRNKontext_default = import_react_native2.TurboModuleRegistry.getEnforcing("RNKontext");
|
|
436
451
|
|
|
437
452
|
// package.json
|
|
438
|
-
var version = "2.
|
|
453
|
+
var version = "2.5.0";
|
|
439
454
|
|
|
440
455
|
// src/context/AdsProvider.tsx
|
|
441
456
|
var import_jsx_runtime4 = require("react/jsx-runtime");
|
package/dist/index.mjs
CHANGED
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
useBid,
|
|
8
8
|
useIframeUrl
|
|
9
9
|
} from "@kontextso/sdk-react";
|
|
10
|
-
import { Linking, Modal, View, useWindowDimensions } from "react-native";
|
|
10
|
+
import { Linking, Modal, View, useWindowDimensions, Keyboard } from "react-native";
|
|
11
11
|
|
|
12
12
|
// ../sdk-common/dist/index.mjs
|
|
13
13
|
function makeIframeMessage(type, opts) {
|
|
@@ -95,6 +95,7 @@ var Format = ({ code, messageId, wrapper, onEvent, ...otherParams }) => {
|
|
|
95
95
|
const modalInitTimeoutRef = useRef(null);
|
|
96
96
|
const isModalInitRef = useRef(false);
|
|
97
97
|
const { height: windowHeight, width: windowWidth } = useWindowDimensions();
|
|
98
|
+
const keyboardHeightRef = useRef(0);
|
|
98
99
|
const isAdViewVisible = showIframe && iframeLoaded;
|
|
99
100
|
const reset = () => {
|
|
100
101
|
setHeight(0);
|
|
@@ -291,7 +292,8 @@ var Format = ({ code, messageId, wrapper, onEvent, ...otherParams }) => {
|
|
|
291
292
|
containerWidth,
|
|
292
293
|
containerHeight,
|
|
293
294
|
containerX,
|
|
294
|
-
containerY
|
|
295
|
+
containerY,
|
|
296
|
+
keyboardHeight: keyboardHeightRef.current
|
|
295
297
|
});
|
|
296
298
|
});
|
|
297
299
|
};
|
|
@@ -302,7 +304,20 @@ var Format = ({ code, messageId, wrapper, onEvent, ...otherParams }) => {
|
|
|
302
304
|
}, 250);
|
|
303
305
|
return () => clearInterval(interval);
|
|
304
306
|
}, [isAdViewVisible]);
|
|
305
|
-
|
|
307
|
+
useEffect(() => {
|
|
308
|
+
const showSubscription = Keyboard.addListener("keyboardDidShow", (e) => {
|
|
309
|
+
keyboardHeightRef.current = e?.endCoordinates?.height ?? 0;
|
|
310
|
+
});
|
|
311
|
+
const hideSubscription = Keyboard.addListener("keyboardDidHide", () => {
|
|
312
|
+
keyboardHeightRef.current = 0;
|
|
313
|
+
});
|
|
314
|
+
return () => {
|
|
315
|
+
showSubscription.remove();
|
|
316
|
+
hideSubscription.remove();
|
|
317
|
+
keyboardHeightRef.current = 0;
|
|
318
|
+
};
|
|
319
|
+
}, []);
|
|
320
|
+
if (!context || !bid || !iframeUrl) {
|
|
306
321
|
return null;
|
|
307
322
|
}
|
|
308
323
|
const inlineContent = /* @__PURE__ */ jsx2(
|
|
@@ -404,7 +419,7 @@ import { TurboModuleRegistry } from "react-native";
|
|
|
404
419
|
var NativeRNKontext_default = TurboModuleRegistry.getEnforcing("RNKontext");
|
|
405
420
|
|
|
406
421
|
// package.json
|
|
407
|
-
var version = "2.
|
|
422
|
+
var version = "2.5.0";
|
|
408
423
|
|
|
409
424
|
// src/context/AdsProvider.tsx
|
|
410
425
|
import { jsx as jsx4 } from "react/jsx-runtime";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kontextso/sdk-react-native",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.5.1",
|
|
4
4
|
"description": "Kontext SDK for React Native",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"react-native-webview": "^13.10.0"
|
|
56
56
|
},
|
|
57
57
|
"dependencies": {
|
|
58
|
-
"@kontextso/sdk-react": "^2.1
|
|
58
|
+
"@kontextso/sdk-react": "^2.2.1"
|
|
59
59
|
},
|
|
60
60
|
"files": [
|
|
61
61
|
"dist/*",
|
package/src/formats/Format.tsx
CHANGED
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
type FormatProps,
|
|
9
9
|
} from '@kontextso/sdk-react'
|
|
10
10
|
import type { WebView, WebViewMessageEvent } from 'react-native-webview'
|
|
11
|
-
import { Linking, Modal, View, useWindowDimensions } from 'react-native'
|
|
11
|
+
import { Linking, Modal, View, useWindowDimensions, Keyboard } from 'react-native'
|
|
12
12
|
import {
|
|
13
13
|
handleIframeMessage,
|
|
14
14
|
type IframeMessageEvent,
|
|
@@ -63,6 +63,8 @@ const Format = ({ code, messageId, wrapper, onEvent, ...otherParams }: FormatPro
|
|
|
63
63
|
|
|
64
64
|
const { height: windowHeight, width: windowWidth } = useWindowDimensions()
|
|
65
65
|
|
|
66
|
+
const keyboardHeightRef = useRef(0);
|
|
67
|
+
|
|
66
68
|
const isAdViewVisible = showIframe && iframeLoaded
|
|
67
69
|
|
|
68
70
|
const reset = () => {
|
|
@@ -294,6 +296,7 @@ const Format = ({ code, messageId, wrapper, onEvent, ...otherParams }: FormatPro
|
|
|
294
296
|
containerHeight,
|
|
295
297
|
containerX,
|
|
296
298
|
containerY,
|
|
299
|
+
keyboardHeight: keyboardHeightRef.current,
|
|
297
300
|
})
|
|
298
301
|
})
|
|
299
302
|
}
|
|
@@ -308,7 +311,22 @@ const Format = ({ code, messageId, wrapper, onEvent, ...otherParams }: FormatPro
|
|
|
308
311
|
return () => clearInterval(interval)
|
|
309
312
|
}, [isAdViewVisible])
|
|
310
313
|
|
|
311
|
-
|
|
314
|
+
useEffect(() => {
|
|
315
|
+
const showSubscription = Keyboard.addListener('keyboardDidShow', (e) => {
|
|
316
|
+
keyboardHeightRef.current = e?.endCoordinates?.height ?? 0;
|
|
317
|
+
});
|
|
318
|
+
const hideSubscription = Keyboard.addListener('keyboardDidHide', () => {
|
|
319
|
+
keyboardHeightRef.current = 0;
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
return () => {
|
|
323
|
+
showSubscription.remove();
|
|
324
|
+
hideSubscription.remove();
|
|
325
|
+
keyboardHeightRef.current = 0;
|
|
326
|
+
};
|
|
327
|
+
}, []);
|
|
328
|
+
|
|
329
|
+
if (!context || !bid || !iframeUrl) {
|
|
312
330
|
return null
|
|
313
331
|
}
|
|
314
332
|
|