@myop/react-native 0.0.4 → 0.0.6

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 CHANGED
@@ -10,7 +10,9 @@ Embed [Myop](https://myop.dev) components in your React Native applications.
10
10
  - Load Myop components by ID or custom configuration
11
11
  - Two-way communication between React Native and embedded components
12
12
  - Customizable loading and fallback states
13
- - Support for both V1 and V2 component formats
13
+ - Component preloading for instant rendering
14
+ - Full component proxy API for DOM manipulation
15
+ - Configurable scroll, zoom, and text selection
14
16
  - TypeScript support
15
17
 
16
18
  ## Installation
@@ -90,23 +92,53 @@ Listen for events from your component's `myop_cta_handler`:
90
92
  />
91
93
  ```
92
94
 
93
- ### Executing Commands
95
+ ### Component Proxy API
94
96
 
95
- Access the component instance for direct command execution:
97
+ Access the component instance for direct manipulation:
96
98
 
97
99
  ```tsx
98
- const [component, setComponent] = useState(null);
100
+ import { IMyopComponentProxy } from '@myop/react-native';
101
+
102
+ const [component, setComponent] = useState<IMyopComponentProxy | null>(null);
99
103
 
100
104
  <MyopComponent
101
105
  componentId="abc123"
102
- onLoad={(instance) => setComponent(() => instance)}
106
+ onLoad={(proxy) => setComponent(proxy)}
103
107
  style={{ flex: 1 }}
104
108
  />
105
109
 
106
- // Execute commands on the component
107
- const handleReset = () => {
108
- component?.('.reset()');
109
- };
110
+ // Send data to component
111
+ component?.props.myop_init_interface({ theme: 'dark' });
112
+
113
+ // DOM manipulation
114
+ component?.element.style.set('opacity', '0.5');
115
+ component?.element.set('style.background', 'red');
116
+
117
+ // Get values (async)
118
+ const opacity = await component?.element.style.get('opacity');
119
+ const scrollTop = await component?.element.get('scrollTop');
120
+
121
+ // Lifecycle methods
122
+ component?.hide();
123
+ component?.show();
124
+ component?.dispose();
125
+ ```
126
+
127
+ ### Loading & Error States
128
+
129
+ By default, no loader is shown while the component loads. The Myop-branded fallback is displayed automatically on error.
130
+
131
+ ### Using the Default Myop Loader
132
+
133
+ ```tsx
134
+ import { MyopComponent, MyopLoader } from '@myop/react-native';
135
+
136
+ <MyopComponent
137
+ componentId="abc123"
138
+ loader={<MyopLoader />} // Opt-in to default Myop loader
139
+ fadeDuration={300}
140
+ style={{ flex: 1 }}
141
+ />
110
142
  ```
111
143
 
112
144
  ### Custom Loading State
@@ -128,13 +160,13 @@ import { ActivityIndicator, View } from 'react-native';
128
160
  />
129
161
  ```
130
162
 
131
- Set `loader={null}` to disable the loading state entirely.
132
-
133
- ### Custom Fallback State
163
+ ### Custom Error Fallback
134
164
 
135
165
  Display a custom view when the component fails to load:
136
166
 
137
167
  ```tsx
168
+ import { MyopComponent, MyopFallback } from '@myop/react-native';
169
+
138
170
  <MyopComponent
139
171
  componentId="abc123"
140
172
  fallback={
@@ -145,6 +177,13 @@ Display a custom view when the component fails to load:
145
177
  onError={(error) => console.error('Load failed:', error)}
146
178
  style={{ flex: 1 }}
147
179
  />
180
+
181
+ // Or use the default Myop fallback explicitly
182
+ <MyopComponent
183
+ componentId="abc123"
184
+ fallback={<MyopFallback />}
185
+ style={{ flex: 1 }}
186
+ />
148
187
  ```
149
188
 
150
189
  ### Using Component Configuration
@@ -182,6 +221,62 @@ Target different deployment environments:
182
221
  />
183
222
  ```
184
223
 
224
+ ### WebView Behavior
225
+
226
+ Control scroll, zoom, and text selection:
227
+
228
+ ```tsx
229
+ <MyopComponent
230
+ componentId="abc123"
231
+ scrollEnabled={true} // Enable scrolling (default: false)
232
+ zoomEnabled={true} // Enable pinch-to-zoom (default: false)
233
+ selectionEnabled={true} // Enable text selection (default: false)
234
+ style={{ flex: 1 }}
235
+ />
236
+ ```
237
+
238
+ ### Preloading Components
239
+
240
+ Preload components for instant rendering when they're displayed:
241
+
242
+ ```tsx
243
+ import { preloadComponents, isPreloaded } from '@myop/react-native';
244
+
245
+ // Preload on app startup or before navigating
246
+ await preloadComponents(['component-1', 'component-2']);
247
+
248
+ // Check if component is preloaded
249
+ if (isPreloaded('component-1')) {
250
+ // Component will render instantly without loader
251
+ }
252
+ ```
253
+
254
+ ### Configuration APIs
255
+
256
+ Configure the CloudRepository for custom endpoints or local development:
257
+
258
+ ```tsx
259
+ import {
260
+ enableLocalDev,
261
+ setCloudRepositoryUrl,
262
+ setCloudRepository,
263
+ setEnvironment,
264
+ getCloudRepository
265
+ } from '@myop/react-native';
266
+
267
+ // Enable local development mode (connects to localhost:9292)
268
+ enableLocalDev();
269
+
270
+ // Use a custom endpoint
271
+ setCloudRepositoryUrl('https://custom.myop.dev');
272
+
273
+ // Set default environment for all components
274
+ setEnvironment('staging');
275
+
276
+ // Get the current CloudRepository instance
277
+ const repo = getCloudRepository();
278
+ ```
279
+
185
280
  ## API Reference
186
281
 
187
282
  ### MyopComponent Props
@@ -192,13 +287,16 @@ Target different deployment environments:
192
287
  | `componentConfig` | `IComponentInstanceConfig` | - | Full component configuration object |
193
288
  | `data` | `any` | - | Data passed to `myop_init_interface` |
194
289
  | `on` | `(action: string, payload?: any) => void` | - | Handler for `myop_cta_handler` events |
195
- | `onLoad` | `(instance: (cmd: string) => void) => void` | - | Callback when component loads |
290
+ | `onLoad` | `(proxy: IMyopComponentProxy) => void` | - | Callback with component proxy when loaded |
196
291
  | `onError` | `(error: string) => void` | - | Callback when component fails to load |
197
- | `loader` | `ReactNode` | `<MyopLoader />` | Custom loading component |
198
- | `fallback` | `ReactNode` | `<MyopFallback />` | Custom fallback component |
292
+ | `loader` | `ReactNode` | `null` | Loading component (default: no loader). Use `<MyopLoader />` for default Myop loader |
293
+ | `fallback` | `ReactNode` | `<MyopFallback />` | Error fallback component (default: Myop-branded fallback) |
199
294
  | `fadeDuration` | `number` | `200` | Loader fade-out duration in ms |
200
295
  | `environment` | `string` | `"production"` | Target environment |
201
- | `v1Mode` | `boolean` | `false` | Use V1 component format |
296
+ | `preview` | `boolean` | `false` | Load preview version of component |
297
+ | `scrollEnabled` | `boolean` | `false` | Enable WebView scrolling |
298
+ | `zoomEnabled` | `boolean` | `false` | Enable pinch-to-zoom |
299
+ | `selectionEnabled` | `boolean` | `false` | Enable text selection |
202
300
  | `style` | `StyleProp<ViewStyle>` | - | Container styles |
203
301
 
204
302
  Either `componentId` or `componentConfig` must be provided.
@@ -211,9 +309,43 @@ Either `componentId` or `componentConfig` must be provided.
211
309
  | `MyopLoader` | Default animated loading state |
212
310
  | `MyopFallback` | Default error/fallback state |
213
311
 
312
+ ### Exported Functions
313
+
314
+ | Function | Description |
315
+ |----------|-------------|
316
+ | `preloadComponents(ids, env?, preview?)` | Preload components for instant rendering |
317
+ | `isPreloaded(componentId, env?, preview?)` | Check if a component is cached |
318
+ | `enableLocalDev()` | Enable local development mode (localhost:9292) |
319
+ | `setCloudRepositoryUrl(url)` | Set a custom CloudRepository URL |
320
+ | `setCloudRepository(repository)` | Set a custom CloudRepository instance |
321
+ | `setEnvironment(env)` | Set the default environment |
322
+ | `getCloudRepository()` | Get the current CloudRepository instance |
323
+
214
324
  ### Types
215
325
 
216
326
  ```typescript
327
+ interface IMyopComponentProxy {
328
+ id: string;
329
+ props: {
330
+ myop_init_interface: (data: any) => void;
331
+ myop_cta_handler: ((action: string, payload?: any) => void) | null;
332
+ };
333
+ element: IElementProxy;
334
+ dispose: () => void;
335
+ hide: () => void;
336
+ show: () => void;
337
+ inspect: () => void;
338
+ }
339
+
340
+ interface IElementProxy {
341
+ set: (path: string, value: any) => void;
342
+ get: (path: string) => Promise<any>;
343
+ style: {
344
+ set: (property: string, value: string) => void;
345
+ get: (property: string) => Promise<string>;
346
+ };
347
+ }
348
+
217
349
  interface IComponentInstanceConfig {
218
350
  id: string;
219
351
  componentId: string;
@@ -1,20 +1,59 @@
1
1
  import React, { ReactNode } from 'react';
2
2
  import { StyleProp, ViewStyle } from 'react-native';
3
3
  import type { IComponentInstanceConfig } from './types';
4
+ /**
5
+ * Element proxy for accessing/modifying the component's DOM element
6
+ */
7
+ export interface IElementProxy {
8
+ /** Set a property on the element (e.g., element.style.background = 'red') */
9
+ set: (path: string, value: any) => void;
10
+ /** Get a property from the element (e.g., element.style.background) - returns Promise */
11
+ get: (path: string) => Promise<any>;
12
+ /** Style proxy for convenient access */
13
+ style: {
14
+ set: (property: string, value: string) => void;
15
+ get: (property: string) => Promise<string>;
16
+ };
17
+ }
18
+ /**
19
+ * Proxy interface for window.myopComponent in WebView
20
+ * Mirrors the IMyopComponent interface from @myop/sdk
21
+ */
22
+ export interface IMyopComponentProxy {
23
+ /** Component ID */
24
+ id: string;
25
+ /** Props object with myop_init_interface and myop_cta_handler */
26
+ props: {
27
+ myop_init_interface: (data: any) => void;
28
+ myop_cta_handler: ((action: string, payload?: any) => void) | null;
29
+ };
30
+ /** Element proxy for DOM manipulation */
31
+ element: IElementProxy;
32
+ /** Dispose the component */
33
+ dispose: () => void;
34
+ /** Hide the component */
35
+ hide: () => void;
36
+ /** Show the component */
37
+ show: () => void;
38
+ /** Inspect the component (debug) */
39
+ inspect: () => void;
40
+ }
4
41
  interface IPropTypes {
5
42
  style?: StyleProp<ViewStyle> | undefined;
6
43
  componentId?: string;
7
44
  componentConfig?: IComponentInstanceConfig;
8
- onLoad?: (myopComponent: (command: string) => void) => void;
45
+ onLoad?: (myopComponent: IMyopComponentProxy) => void;
9
46
  onError?: (error: string) => void;
10
47
  on?: (action: string, payload?: any) => void;
11
48
  data?: any;
12
49
  loader?: ReactNode;
13
50
  fallback?: ReactNode;
14
51
  fadeDuration?: number;
15
- v1Mode?: boolean;
16
52
  environment?: string;
17
53
  preview?: boolean;
54
+ scrollEnabled?: boolean;
55
+ zoomEnabled?: boolean;
56
+ selectionEnabled?: boolean;
18
57
  }
19
58
  export declare const MyopComponent: (props: IPropTypes) => React.JSX.Element;
20
59
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"MyopComponent.d.ts","sourceRoot":"","sources":["../src/MyopComponent.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAmB,SAAS,EAAuD,MAAM,OAAO,CAAC;AAG/G,OAAO,EAAC,SAAS,EAAE,SAAS,EAAC,MAAM,cAAc,CAA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