react-native-demo-library-by-rinkal 1.2.7 → 1.3.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/ARCHITECTURE_DIAGRAMS.md +473 -0
- package/COMMUNICATION_DOCS.md +336 -0
- package/CONTAINER_APP_SETUP.md +360 -0
- package/CommunicationExample.tsx +247 -0
- package/ContainerCommunication.ts +91 -0
- package/IMPLEMENTATION_SUMMARY.md +385 -0
- package/INDEX.md +333 -0
- package/MiniAppCommunication.ts +71 -0
- package/OFFICIAL_REFERENCES.md +278 -0
- package/QUICK_REFERENCE.md +298 -0
- package/Readme.md +514 -3
- package/SUMMARY.md +305 -0
- package/TaskCard.tsx +25 -8
- package/index.ts +15 -1
- package/package.json +16 -2
package/Readme.md
CHANGED
|
@@ -1,3 +1,514 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
# React Native Demo Library by Rinkal
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
A React Native library for **MiniApp to Container communication**. Send events from your MiniApp (DemoLib) to your Container App (DemoApp).
|
|
5
|
+
|
|
6
|
+
## 🎯 Simple Flow
|
|
7
|
+
|
|
8
|
+
```
|
|
9
|
+
MiniApp (DemoLib) ----sends events----> Container App (DemoApp)
|
|
10
|
+
TaskCard clicks Your app receives data
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install react-native-demo-library-by-rinkal
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## 🚀 Quick Start
|
|
22
|
+
|
|
23
|
+
### For MiniApp (DemoLib) - Send Data
|
|
24
|
+
|
|
25
|
+
```tsx
|
|
26
|
+
import { TaskCard } from 'react-native-demo-library-by-rinkal';
|
|
27
|
+
import MiniAppCommunication from 'react-native-demo-library-by-rinkal/MiniAppCommunication';
|
|
28
|
+
|
|
29
|
+
// Use TaskCard - automatically sends events when clicked
|
|
30
|
+
<TaskCard title="My Task" taskId="task_123" />
|
|
31
|
+
|
|
32
|
+
// Or send custom events
|
|
33
|
+
MiniAppCommunication.sendToContainer('myEvent', {
|
|
34
|
+
data: 'Hello from MiniApp!'
|
|
35
|
+
});
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### For Container App (DemoApp) - Receive Data
|
|
39
|
+
|
|
40
|
+
```tsx
|
|
41
|
+
import React, { useEffect, useState } from 'react';
|
|
42
|
+
import ContainerCommunication from 'react-native-demo-library-by-rinkal/ContainerCommunication';
|
|
43
|
+
|
|
44
|
+
const ContainerApp = () => {
|
|
45
|
+
const [events, setEvents] = useState([]);
|
|
46
|
+
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
// Listen to task clicks from miniapp
|
|
49
|
+
const subscription = ContainerCommunication.onTaskClick((data) => {
|
|
50
|
+
console.log('Task clicked:', data.taskTitle);
|
|
51
|
+
setEvents(prev => [...prev, data]);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
// Cleanup
|
|
55
|
+
return () => subscription.remove();
|
|
56
|
+
}, []);
|
|
57
|
+
|
|
58
|
+
return (
|
|
59
|
+
<View>
|
|
60
|
+
{events.map(event => (
|
|
61
|
+
<Text key={event.taskId}>{event.taskTitle}</Text>
|
|
62
|
+
))}
|
|
63
|
+
</View>
|
|
64
|
+
);
|
|
65
|
+
};
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
## 📚 Complete Documentation
|
|
71
|
+
|
|
72
|
+
- **[CONTAINER_APP_SETUP.md](./CONTAINER_APP_SETUP.md)** ⭐ **START HERE** - Complete setup guide for Container App
|
|
73
|
+
- **[QUICK_REFERENCE.md](./QUICK_REFERENCE.md)** - Quick code examples
|
|
74
|
+
- **[CommunicationExample.tsx](./CommunicationExample.tsx)** - Working examples with Container App code
|
|
75
|
+
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
## 📦 What's Included
|
|
79
|
+
|
|
80
|
+
### UI Components
|
|
81
|
+
- **TaskCard** - Interactive task card that sends events to container when clicked
|
|
82
|
+
|
|
83
|
+
### Communication Methods
|
|
84
|
+
|
|
85
|
+
#### From MiniApp (Send)
|
|
86
|
+
```tsx
|
|
87
|
+
import MiniAppCommunication from 'react-native-demo-library-by-rinkal/MiniAppCommunication';
|
|
88
|
+
|
|
89
|
+
// Send task click
|
|
90
|
+
MiniAppCommunication.sendTaskClick('task_123', 'Task Title');
|
|
91
|
+
|
|
92
|
+
// Send user action
|
|
93
|
+
MiniAppCommunication.sendUserAction('buttonClick', { button: 'submit' });
|
|
94
|
+
|
|
95
|
+
// Send data update
|
|
96
|
+
MiniAppCommunication.sendDataUpdate('settings', { theme: 'dark' });
|
|
97
|
+
|
|
98
|
+
// Send custom event
|
|
99
|
+
MiniAppCommunication.sendToContainer('customEvent', { any: 'data' });
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
#### From Container App (Receive)
|
|
103
|
+
```tsx
|
|
104
|
+
import ContainerCommunication from 'react-native-demo-library-by-rinkal/ContainerCommunication';
|
|
105
|
+
|
|
106
|
+
// Listen to task clicks
|
|
107
|
+
ContainerCommunication.onTaskClick((data) => {
|
|
108
|
+
console.log(data.taskId, data.taskTitle);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
// Listen to user actions
|
|
112
|
+
ContainerCommunication.onUserAction((data) => {
|
|
113
|
+
console.log(data.action, data.payload);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
// Listen to data updates
|
|
117
|
+
ContainerCommunication.onDataUpdate((data) => {
|
|
118
|
+
console.log(data.key, data.value);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
// Listen to custom events
|
|
122
|
+
ContainerCommunication.listenFromMiniApp('customEvent', (data) => {
|
|
123
|
+
console.log(data);
|
|
124
|
+
});
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
---
|
|
128
|
+
|
|
129
|
+
## 💡 Real Example
|
|
130
|
+
|
|
131
|
+
### MiniApp Component (DemoLib)
|
|
132
|
+
```tsx
|
|
133
|
+
import React from 'react';
|
|
134
|
+
import { View, Button } from 'react-native';
|
|
135
|
+
import { TaskCard } from 'react-native-demo-library-by-rinkal';
|
|
136
|
+
import MiniAppCommunication from 'react-native-demo-library-by-rinkal/MiniAppCommunication';
|
|
137
|
+
|
|
138
|
+
const MiniAppScreen = () => {
|
|
139
|
+
return (
|
|
140
|
+
<View>
|
|
141
|
+
{/* TaskCard sends event automatically on click */}
|
|
142
|
+
<TaskCard title="Buy groceries" taskId="task_1" />
|
|
143
|
+
<TaskCard title="Pay bills" taskId="task_2" />
|
|
144
|
+
|
|
145
|
+
{/* Custom button sends custom event */}
|
|
146
|
+
<Button
|
|
147
|
+
title="Complete Purchase"
|
|
148
|
+
onPress={() => {
|
|
149
|
+
MiniAppCommunication.sendToContainer('purchase', {
|
|
150
|
+
productId: 'prod_123',
|
|
151
|
+
amount: 99.99
|
|
152
|
+
});
|
|
153
|
+
}}
|
|
154
|
+
/>
|
|
155
|
+
</View>
|
|
156
|
+
);
|
|
157
|
+
};
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
### Container App Component (DemoApp)
|
|
161
|
+
```tsx
|
|
162
|
+
import React, { useEffect, useState } from 'react';
|
|
163
|
+
import { View, Text, FlatList } from 'react-native';
|
|
164
|
+
import ContainerCommunication from 'react-native-demo-library-by-rinkal/ContainerCommunication';
|
|
165
|
+
|
|
166
|
+
const ContainerAppScreen = () => {
|
|
167
|
+
const [tasks, setTasks] = useState([]);
|
|
168
|
+
const [purchases, setPurchases] = useState([]);
|
|
169
|
+
|
|
170
|
+
useEffect(() => {
|
|
171
|
+
// Listen to task clicks from MiniApp
|
|
172
|
+
const taskSub = ContainerCommunication.onTaskClick((data) => {
|
|
173
|
+
setTasks(prev => [...prev, data]);
|
|
174
|
+
// Navigate to task detail or show notification
|
|
175
|
+
alert(`Task clicked: ${data.taskTitle}`);
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
// Listen to purchase events from MiniApp
|
|
179
|
+
const purchaseSub = ContainerCommunication.listenFromMiniApp('purchase', (data) => {
|
|
180
|
+
setPurchases(prev => [...prev, data]);
|
|
181
|
+
// Process purchase
|
|
182
|
+
console.log('Processing purchase:', data.amount);
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
// Cleanup
|
|
186
|
+
return () => {
|
|
187
|
+
taskSub.remove();
|
|
188
|
+
purchaseSub.remove();
|
|
189
|
+
};
|
|
190
|
+
}, []);
|
|
191
|
+
|
|
192
|
+
return (
|
|
193
|
+
<View>
|
|
194
|
+
<Text>Tasks from MiniApp:</Text>
|
|
195
|
+
<FlatList
|
|
196
|
+
data={tasks}
|
|
197
|
+
keyExtractor={item => item.taskId}
|
|
198
|
+
renderItem={({ item }) => <Text>{item.taskTitle}</Text>}
|
|
199
|
+
/>
|
|
200
|
+
|
|
201
|
+
<Text>Purchases: {purchases.length}</Text>
|
|
202
|
+
</View>
|
|
203
|
+
);
|
|
204
|
+
};
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
---
|
|
208
|
+
|
|
209
|
+
## 📖 API Reference
|
|
210
|
+
|
|
211
|
+
### MiniAppCommunication (Send from MiniApp)
|
|
212
|
+
|
|
213
|
+
| Method | Description | Parameters |
|
|
214
|
+
|--------|-------------|------------|
|
|
215
|
+
| `sendTaskClick(taskId, title)` | Send task click event | taskId: string, title: string |
|
|
216
|
+
| `sendUserAction(action, payload)` | Send user action | action: string, payload: any |
|
|
217
|
+
| `sendDataUpdate(key, value)` | Send data update | key: string, value: any |
|
|
218
|
+
| `sendToContainer(eventName, data)` | Send custom event | eventName: string, data: any |
|
|
219
|
+
|
|
220
|
+
### ContainerCommunication (Receive in Container)
|
|
221
|
+
|
|
222
|
+
| Method | Description | Returns |
|
|
223
|
+
|--------|-------------|---------|
|
|
224
|
+
| `onTaskClick(callback)` | Listen to task clicks | Subscription |
|
|
225
|
+
| `onUserAction(callback)` | Listen to user actions | Subscription |
|
|
226
|
+
| `onDataUpdate(callback)` | Listen to data updates | Subscription |
|
|
227
|
+
| `listenFromMiniApp(eventName, callback)` | Listen to custom events | Subscription |
|
|
228
|
+
| `removeAllListeners()` | Remove all listeners | void |
|
|
229
|
+
|
|
230
|
+
---
|
|
231
|
+
|
|
232
|
+
## 🔧 TypeScript Support
|
|
233
|
+
|
|
234
|
+
Full TypeScript support included:
|
|
235
|
+
|
|
236
|
+
```tsx
|
|
237
|
+
import { TaskClickData, UserActionData, DataUpdateEvent } from 'react-native-demo-library-by-rinkal/MiniAppCommunication';
|
|
238
|
+
|
|
239
|
+
ContainerCommunication.onTaskClick((data: TaskClickData) => {
|
|
240
|
+
console.log(data.taskId); // ✅ Type-safe
|
|
241
|
+
});
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
---
|
|
245
|
+
|
|
246
|
+
## 📖 Official Documentation
|
|
247
|
+
|
|
248
|
+
Based on React Native's official event system:
|
|
249
|
+
- **React Native Native Modules**: https://reactnative.dev/docs/native-modules-intro
|
|
250
|
+
- **Native Modules iOS**: https://reactnative.dev/docs/native-modules-ios
|
|
251
|
+
- **Native Modules Android**: https://reactnative.dev/docs/native-modules-android
|
|
252
|
+
- **DeviceEventEmitter**: https://reactnative.dev/docs/native-modules-android
|
|
253
|
+
|
|
254
|
+
---
|
|
255
|
+
|
|
256
|
+
## 🎯 Key Features
|
|
257
|
+
|
|
258
|
+
✅ **Simple** - Just 2 lines to send/receive events
|
|
259
|
+
✅ **Type-Safe** - Full TypeScript support
|
|
260
|
+
✅ **Reliable** - Based on React Native's official EventEmitter
|
|
261
|
+
✅ **Documented** - Comprehensive guides included
|
|
262
|
+
✅ **Production-Ready** - Console logging for debugging
|
|
263
|
+
|
|
264
|
+
---
|
|
265
|
+
|
|
266
|
+
## 📚 Documentation Files
|
|
267
|
+
|
|
268
|
+
| File | Description |
|
|
269
|
+
|------|-------------|
|
|
270
|
+
| [CONTAINER_APP_SETUP.md](./CONTAINER_APP_SETUP.md) | **Complete setup guide for Container App** ⭐ |
|
|
271
|
+
| [QUICK_REFERENCE.md](./QUICK_REFERENCE.md) | Quick code snippets |
|
|
272
|
+
| [CommunicationExample.tsx](./CommunicationExample.tsx) | Working examples |
|
|
273
|
+
| [OFFICIAL_REFERENCES.md](./OFFICIAL_REFERENCES.md) | Official docs links |
|
|
274
|
+
|
|
275
|
+
---
|
|
276
|
+
|
|
277
|
+
## ✅ Quick Checklist
|
|
278
|
+
|
|
279
|
+
### In MiniApp (DemoLib):
|
|
280
|
+
- [x] Components already send events (TaskCard)
|
|
281
|
+
- [x] Use `MiniAppCommunication.sendToContainer()` for custom events
|
|
282
|
+
|
|
283
|
+
### In Container App (DemoApp):
|
|
284
|
+
- [ ] Install library: `npm install react-native-demo-library-by-rinkal`
|
|
285
|
+
- [ ] Import: `import ContainerCommunication from 'react-native-demo-library-by-rinkal/ContainerCommunication'`
|
|
286
|
+
- [ ] Setup listeners in `useEffect`
|
|
287
|
+
- [ ] Don't forget cleanup with `.remove()`
|
|
288
|
+
|
|
289
|
+
---
|
|
290
|
+
|
|
291
|
+
## 🐛 Troubleshooting
|
|
292
|
+
|
|
293
|
+
**Events not received?**
|
|
294
|
+
1. Check you're using `ContainerCommunication.onTaskClick()` or similar methods
|
|
295
|
+
2. Make sure listener is set up before MiniApp sends events
|
|
296
|
+
3. Verify cleanup is in place (`subscription.remove()`)
|
|
297
|
+
4. Check console logs - all events are logged
|
|
298
|
+
|
|
299
|
+
**See [CONTAINER_APP_SETUP.md](./CONTAINER_APP_SETUP.md) for detailed troubleshooting**
|
|
300
|
+
|
|
301
|
+
---
|
|
302
|
+
|
|
303
|
+
## 📄 License
|
|
304
|
+
ISC
|
|
305
|
+
|
|
306
|
+
## 👨💻 Author
|
|
307
|
+
Rinkal
|
|
308
|
+
|
|
309
|
+
## 📌 Version
|
|
310
|
+
1.3.0
|
|
311
|
+
|
|
312
|
+
---
|
|
313
|
+
|
|
314
|
+
## 🚀 Get Started Now!
|
|
315
|
+
|
|
316
|
+
1. **For Container App setup**: Read [CONTAINER_APP_SETUP.md](./CONTAINER_APP_SETUP.md)
|
|
317
|
+
2. **For quick examples**: Read [QUICK_REFERENCE.md](./QUICK_REFERENCE.md)
|
|
318
|
+
3. **For working code**: See [CommunicationExample.tsx](./CommunicationExample.tsx)
|
|
319
|
+
|
|
320
|
+
## Features
|
|
321
|
+
|
|
322
|
+
### UI Components
|
|
323
|
+
- **TaskCard**: Customizable task card component
|
|
324
|
+
- **TaskDemoCard**: Demo task card component
|
|
325
|
+
|
|
326
|
+
### Communication Patterns
|
|
327
|
+
1. **Event Emitter Pattern** - One-way event-based communication
|
|
328
|
+
2. **Callback Pattern** - Direct function invocation
|
|
329
|
+
3. **Promise-Based Pattern** - Async request-response
|
|
330
|
+
4. **Shared State Pattern** - Bidirectional state synchronization
|
|
331
|
+
5. **Native Bridge Pattern** - Direct native module communication
|
|
332
|
+
6. **Message Queue Pattern** - Reliable message delivery
|
|
333
|
+
|
|
334
|
+
## Installation
|
|
335
|
+
|
|
336
|
+
```bash
|
|
337
|
+
npm install react-native-demo-library-by-rinkal
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
## Quick Start
|
|
341
|
+
|
|
342
|
+
### Using UI Components
|
|
343
|
+
|
|
344
|
+
```typescript
|
|
345
|
+
import { TaskCard, TaskDemoCard } from 'react-native-demo-library-by-rinkal';
|
|
346
|
+
|
|
347
|
+
const App = () => {
|
|
348
|
+
return (
|
|
349
|
+
<View>
|
|
350
|
+
<TaskCard title="My Task" />
|
|
351
|
+
<TaskDemoCard />
|
|
352
|
+
</View>
|
|
353
|
+
);
|
|
354
|
+
};
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
### Using Communication Patterns
|
|
358
|
+
|
|
359
|
+
#### MiniApp Side
|
|
360
|
+
```typescript
|
|
361
|
+
import MiniAppCommunication from 'react-native-demo-library-by-rinkal';
|
|
362
|
+
|
|
363
|
+
// Initialize
|
|
364
|
+
MiniAppCommunication.initialize();
|
|
365
|
+
|
|
366
|
+
// Send event
|
|
367
|
+
MiniAppCommunication.sendEvent('userAction', { action: 'click' });
|
|
368
|
+
|
|
369
|
+
// Send request and wait for response
|
|
370
|
+
const result = await MiniAppCommunication.request('getData', { id: 123 });
|
|
371
|
+
|
|
372
|
+
// Update shared state
|
|
373
|
+
MiniAppCommunication.setState('userData', { name: 'John' });
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
#### Container Side
|
|
377
|
+
```typescript
|
|
378
|
+
import ContainerCommunication from 'react-native-demo-library-by-rinkal';
|
|
379
|
+
|
|
380
|
+
// Initialize
|
|
381
|
+
ContainerCommunication.initialize();
|
|
382
|
+
|
|
383
|
+
// Listen to events
|
|
384
|
+
ContainerCommunication.onEvent('userAction', (data) => {
|
|
385
|
+
console.log('Received:', data);
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
// Register request handler
|
|
389
|
+
ContainerCommunication.registerHandler('getData', async (data) => {
|
|
390
|
+
return { result: 'success' };
|
|
391
|
+
});
|
|
392
|
+
|
|
393
|
+
// Subscribe to state changes
|
|
394
|
+
ContainerCommunication.subscribeToState('userData', (newValue) => {
|
|
395
|
+
console.log('State updated:', newValue);
|
|
396
|
+
});
|
|
397
|
+
```
|
|
398
|
+
|
|
399
|
+
## Documentation
|
|
400
|
+
|
|
401
|
+
### Comprehensive Guides
|
|
402
|
+
- **[COMMUNICATION_DOCS.md](./COMMUNICATION_DOCS.md)** - Complete usage guide with examples
|
|
403
|
+
- **[OFFICIAL_REFERENCES.md](./OFFICIAL_REFERENCES.md)** - All official documentation references
|
|
404
|
+
|
|
405
|
+
### Example Components
|
|
406
|
+
- **[CommunicationExample.tsx](./CommunicationExample.tsx)** - Working examples for both miniapp and container
|
|
407
|
+
|
|
408
|
+
## Official Documentation References
|
|
409
|
+
|
|
410
|
+
All implementations are based on official documentation:
|
|
411
|
+
|
|
412
|
+
1. **React Native Events**: https://reactnative.dev/docs/native-modules-ios#sending-events-to-javascript
|
|
413
|
+
2. **React Native Callbacks**: https://reactnative.dev/docs/native-modules-ios#callbacks
|
|
414
|
+
3. **React Native Promises**: https://reactnative.dev/docs/native-modules-ios#promises
|
|
415
|
+
4. **Native Modules**: https://reactnative.dev/docs/native-modules-intro
|
|
416
|
+
5. **Node.js EventEmitter**: https://nodejs.org/api/events.html
|
|
417
|
+
6. **Redux Pattern**: https://redux.js.org/introduction/getting-started
|
|
418
|
+
7. **MDN Web Docs - Promises**: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise
|
|
419
|
+
8. **MDN Web Docs - postMessage**: https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage
|
|
420
|
+
|
|
421
|
+
See [OFFICIAL_REFERENCES.md](./OFFICIAL_REFERENCES.md) for the complete list.
|
|
422
|
+
|
|
423
|
+
## Communication Patterns Comparison
|
|
424
|
+
|
|
425
|
+
| Pattern | Direction | Async | Reliability | Best For |
|
|
426
|
+
|---------|-----------|-------|-------------|----------|
|
|
427
|
+
| Event Emitter | Bi-directional | No | Medium | Real-time updates |
|
|
428
|
+
| Callback | Uni-directional | No | High | Direct invocation |
|
|
429
|
+
| Promise | Request-Response | Yes | High | Data fetching |
|
|
430
|
+
| Shared State | Bi-directional | No | High | State sync |
|
|
431
|
+
| Native Bridge | Uni-directional | Yes | Medium | Native features |
|
|
432
|
+
| Message Queue | Uni-directional | Yes | Very High | Offline support |
|
|
433
|
+
|
|
434
|
+
## Architecture
|
|
435
|
+
|
|
436
|
+
```
|
|
437
|
+
┌─────────────────────────────────────────────────────────┐
|
|
438
|
+
│ MiniApp │
|
|
439
|
+
│ ┌──────────────────────────────────────────────────┐ │
|
|
440
|
+
│ │ MiniAppCommunication │ │
|
|
441
|
+
│ │ ✓ Event Emitter ✓ Callbacks │ │
|
|
442
|
+
│ │ ✓ Promises ✓ Shared State │ │
|
|
443
|
+
│ │ ✓ Native Bridge ✓ Message Queue │ │
|
|
444
|
+
│ └──────────────────────────────────────────────────┘ │
|
|
445
|
+
└─────────────────┬───────────────────────────────────────┘
|
|
446
|
+
│ Communication Layer
|
|
447
|
+
┌─────────────────┴───────────────────────────────────────┐
|
|
448
|
+
│ Container App │
|
|
449
|
+
│ ┌──────────────────────────────────────────────────┐ │
|
|
450
|
+
│ │ ContainerCommunication │ │
|
|
451
|
+
│ │ ✓ Event Listener ✓ Request Handlers │ │
|
|
452
|
+
│ │ ✓ State Manager ✓ Message Handler │ │
|
|
453
|
+
│ └──────────────────────────────────────────────────┘ │
|
|
454
|
+
└─────────────────────────────────────────────────────────┘
|
|
455
|
+
```
|
|
456
|
+
|
|
457
|
+
## Complete Example
|
|
458
|
+
|
|
459
|
+
```typescript
|
|
460
|
+
import React, { useEffect } from 'react';
|
|
461
|
+
import { View, Button } from 'react-native';
|
|
462
|
+
import { MiniAppExample, ContainerExample } from 'react-native-demo-library-by-rinkal';
|
|
463
|
+
|
|
464
|
+
// For MiniApp
|
|
465
|
+
const MiniApp = () => <MiniAppExample />;
|
|
466
|
+
|
|
467
|
+
// For Container
|
|
468
|
+
const Container = () => <ContainerExample />;
|
|
469
|
+
```
|
|
470
|
+
|
|
471
|
+
## API Reference
|
|
472
|
+
|
|
473
|
+
### MiniAppCommunication
|
|
474
|
+
|
|
475
|
+
- `initialize()` - Initialize communication system
|
|
476
|
+
- `sendEvent(eventName, data)` - Send event to container
|
|
477
|
+
- `onEvent(eventName, callback)` - Listen to events from container
|
|
478
|
+
- `request(action, data)` - Send request and wait for response
|
|
479
|
+
- `registerCallback(id, callback)` - Register callback function
|
|
480
|
+
- `getState(key)` - Get shared state value
|
|
481
|
+
- `setState(key, value)` - Set shared state value
|
|
482
|
+
- `subscribeToState(key, listener)` - Subscribe to state changes
|
|
483
|
+
- `callNative(module, method, ...args)` - Call native module method
|
|
484
|
+
- `queueMessage(type, payload)` - Queue message for delivery
|
|
485
|
+
- `cleanup()` - Cleanup resources
|
|
486
|
+
|
|
487
|
+
### ContainerCommunication
|
|
488
|
+
|
|
489
|
+
- `initialize()` - Initialize communication system
|
|
490
|
+
- `sendEvent(eventName, data)` - Send event to miniapp
|
|
491
|
+
- `onEvent(eventName, callback)` - Listen to events from miniapp
|
|
492
|
+
- `registerHandler(action, handler)` - Register request handler
|
|
493
|
+
- `getState(key)` - Get shared state value
|
|
494
|
+
- `setState(key, value)` - Set shared state value
|
|
495
|
+
- `subscribeToState(key, listener)` - Subscribe to state changes
|
|
496
|
+
- `registerMessageHandler(type, handler)` - Register message handler
|
|
497
|
+
- `cleanup()` - Cleanup resources
|
|
498
|
+
|
|
499
|
+
## Requirements
|
|
500
|
+
|
|
501
|
+
- React: 19.1.0
|
|
502
|
+
- React Native: 0.81.5
|
|
503
|
+
|
|
504
|
+
## License
|
|
505
|
+
ISC
|
|
506
|
+
|
|
507
|
+
## Author
|
|
508
|
+
Rinkal
|
|
509
|
+
|
|
510
|
+
## Version
|
|
511
|
+
1.3.0
|
|
512
|
+
|
|
513
|
+
## Support
|
|
514
|
+
For issues and questions, please refer to the documentation files included in this package.
|