@umituz/react-native-ai-generation-content 1.17.229 → 1.17.230
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/LICENSE +21 -0
- package/README.md +346 -0
- package/package.json +1 -3
- package/src/domain/README.md +503 -0
- package/src/domains/content-moderation/README.md +363 -0
- package/src/domains/creations/README.md +394 -0
- package/src/domains/face-detection/README.md +395 -0
- package/src/domains/prompts/README.md +387 -0
- package/src/features/ai-hug/README.md +276 -0
- package/src/features/ai-kiss/README.md +276 -0
- package/src/features/anime-selfie/README.md +325 -0
- package/src/features/audio-generation/README.md +370 -0
- package/src/features/colorization/README.md +289 -0
- package/src/features/couple-future/README.md +270 -0
- package/src/features/face-swap/README.md +234 -0
- package/src/features/future-prediction/README.md +281 -0
- package/src/features/hd-touch-up/README.md +309 -0
- package/src/features/image-captioning/README.md +361 -0
- package/src/features/image-to-image/README.md +418 -0
- package/src/features/image-to-video/README.md +369 -0
- package/src/features/inpainting/README.md +302 -0
- package/src/features/meme-generator/README.md +327 -0
- package/src/features/photo-restoration/README.md +286 -0
- package/src/features/remove-background/README.md +292 -0
- package/src/features/remove-object/README.md +352 -0
- package/src/features/replace-background/README.md +288 -0
- package/src/features/script-generator/README.md +362 -0
- package/src/features/shared/README.md +280 -0
- package/src/features/sketch-to-image/README.md +296 -0
- package/src/features/style-transfer/README.md +301 -0
- package/src/features/text-to-image/README.md +228 -0
- package/src/features/text-to-video/README.md +245 -0
- package/src/features/text-to-voice/README.md +335 -0
- package/src/features/upscaling/README.md +247 -0
- package/src/infrastructure/config/README.md +310 -0
- package/src/infrastructure/middleware/README.md +378 -0
- package/src/infrastructure/orchestration/README.md +362 -0
- package/src/infrastructure/services/README.md +382 -0
- package/src/infrastructure/utils/README.md +523 -0
- package/src/infrastructure/wrappers/README.md +336 -0
- package/src/presentation/components/README.md +535 -0
- package/src/presentation/hooks/README.md +380 -0
- package/src/presentation/layouts/README.md +374 -0
- package/src/presentation/screens/README.md +430 -0
- package/src/presentation/layouts/types/.npmignore.tmp +0 -0
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
# Presentation Hooks
|
|
2
|
+
|
|
3
|
+
Custom React hooks for AI generation features.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
The hooks module provides custom React hooks that encapsulate AI generation logic and state management. These hooks make it easy to integrate AI features into your React Native components.
|
|
8
|
+
|
|
9
|
+
## Core Hooks
|
|
10
|
+
|
|
11
|
+
### useGeneration
|
|
12
|
+
|
|
13
|
+
Main hook for generation operations:
|
|
14
|
+
|
|
15
|
+
```tsx
|
|
16
|
+
import { useGeneration } from '@umituz/react-native-ai-generation-content';
|
|
17
|
+
|
|
18
|
+
function MyComponent() {
|
|
19
|
+
const { generate, state } = useGeneration({
|
|
20
|
+
featureType: 'text-to-image',
|
|
21
|
+
userId: 'user-123',
|
|
22
|
+
onProgress: (progress) => {
|
|
23
|
+
console.log('Progress:', progress);
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
const handleGenerate = async () => {
|
|
28
|
+
await generate({
|
|
29
|
+
prompt: 'A beautiful sunset',
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
return (
|
|
34
|
+
<View>
|
|
35
|
+
<Button onPress={handleGenerate} title="Generate" />
|
|
36
|
+
{state.isProcessing && <Text>Processing...</Text>}
|
|
37
|
+
{state.result && <Image source={{ uri: state.result.imageUrl }} />}
|
|
38
|
+
</View>
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### useBackgroundGeneration
|
|
44
|
+
|
|
45
|
+
Background generation hook:
|
|
46
|
+
|
|
47
|
+
```tsx
|
|
48
|
+
import { useBackgroundGeneration } from '@umituz/react-native-ai-generation-content';
|
|
49
|
+
|
|
50
|
+
function BackgroundGenerator() {
|
|
51
|
+
const { startGeneration, jobs, addJobListener } = useBackgroundGeneration({
|
|
52
|
+
userId: 'user-123',
|
|
53
|
+
onJobComplete: (job) => {
|
|
54
|
+
console.log('Job complete:', job.result);
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
const startBackgroundGen = async () => {
|
|
59
|
+
await startGeneration({
|
|
60
|
+
featureType: 'text-to-image',
|
|
61
|
+
inputData: { prompt: 'A sunset' },
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
return (
|
|
66
|
+
<View>
|
|
67
|
+
<Button onPress={startBackgroundGen} title="Start Background" />
|
|
68
|
+
{jobs.map(job => (
|
|
69
|
+
<Text key={job.id}>{job.status}: {job.progress}%</Text>
|
|
70
|
+
))}
|
|
71
|
+
</View>
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### usePendingJobs
|
|
77
|
+
|
|
78
|
+
Manage pending generation jobs:
|
|
79
|
+
|
|
80
|
+
```tsx
|
|
81
|
+
import { usePendingJobs } from '@umituz/react-native-ai-generation-content';
|
|
82
|
+
|
|
83
|
+
function JobsList() {
|
|
84
|
+
const { jobs, loading, refresh, deleteJob } = usePendingJobs({
|
|
85
|
+
userId: 'user-123',
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
return (
|
|
89
|
+
<FlatList
|
|
90
|
+
data={jobs}
|
|
91
|
+
refreshing={loading}
|
|
92
|
+
onRefresh={refresh}
|
|
93
|
+
keyExtractor={(item) => item.id}
|
|
94
|
+
renderItem={({ item }) => (
|
|
95
|
+
<JobCard
|
|
96
|
+
job={item}
|
|
97
|
+
onPress={() => viewJob(item.id)}
|
|
98
|
+
onDelete={() => deleteJob(item.id)}
|
|
99
|
+
/>
|
|
100
|
+
)}
|
|
101
|
+
/>
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### usePhotoGeneration
|
|
107
|
+
|
|
108
|
+
Photo generation hook:
|
|
109
|
+
|
|
110
|
+
```tsx
|
|
111
|
+
import { usePhotoGeneration } from '@umituz/react-native-ai-generation-content';
|
|
112
|
+
|
|
113
|
+
function PhotoGenerator() {
|
|
114
|
+
const { generate, state, reset } = usePhotoGeneration({
|
|
115
|
+
featureType: 'text-to-image',
|
|
116
|
+
userId: 'user-123',
|
|
117
|
+
onSuccess: (result) => {
|
|
118
|
+
console.log('Success:', result.imageUrl);
|
|
119
|
+
},
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
return (
|
|
123
|
+
<View>
|
|
124
|
+
<PhotoUploadCard
|
|
125
|
+
image={state.image}
|
|
126
|
+
onSelectImage={state.selectImage}
|
|
127
|
+
/>
|
|
128
|
+
<Button
|
|
129
|
+
onPress={() => generate({ prompt: 'A sunset' })}
|
|
130
|
+
disabled={!state.canGenerate}
|
|
131
|
+
title="Generate"
|
|
132
|
+
/>
|
|
133
|
+
</View>
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### useGenerationFlow
|
|
139
|
+
|
|
140
|
+
Multi-step generation flow:
|
|
141
|
+
|
|
142
|
+
```tsx
|
|
143
|
+
import { useGenerationFlow } from '@umituz/react-native-ai-generation-content';
|
|
144
|
+
|
|
145
|
+
function FlowGenerator() {
|
|
146
|
+
const { flow, currentStep, nextStep, prevStep, reset } = useGenerationFlow({
|
|
147
|
+
steps: [
|
|
148
|
+
{
|
|
149
|
+
id: 'photo',
|
|
150
|
+
type: 'photo-upload',
|
|
151
|
+
title: 'Upload Photo',
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
id: 'prompt',
|
|
155
|
+
type: 'text-input',
|
|
156
|
+
title: 'Enter Prompt',
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
id: 'generate',
|
|
160
|
+
type: 'generation',
|
|
161
|
+
title: 'Generate',
|
|
162
|
+
},
|
|
163
|
+
],
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
return (
|
|
167
|
+
<View>
|
|
168
|
+
<StepIndicator currentStep={currentStep} steps={flow.steps} />
|
|
169
|
+
{currentStep.id === 'photo' && <PhotoUploadStep />}
|
|
170
|
+
{currentStep.id === 'prompt' && <PromptInputStep />}
|
|
171
|
+
{currentStep.id === 'generate' && <GenerationStep />}
|
|
172
|
+
<Button onPress={nextStep} title="Next" />
|
|
173
|
+
</View>
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### useGenerationCallbacksBuilder
|
|
179
|
+
|
|
180
|
+
Build generation callbacks:
|
|
181
|
+
|
|
182
|
+
```tsx
|
|
183
|
+
import { useGenerationCallbacksBuilder } from '@umituz/react-native-ai-generation-content';
|
|
184
|
+
|
|
185
|
+
function Generator() {
|
|
186
|
+
const { callbacks, buildCallbacks } = useGenerationCallbacksBuilder({
|
|
187
|
+
featureType: 'text-to-image',
|
|
188
|
+
userId: 'user-123',
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
const handleGenerate = async () => {
|
|
192
|
+
const builtCallbacks = await buildCallbacks({
|
|
193
|
+
onBeforeGenerate: async () => {
|
|
194
|
+
console.log('Starting generation...');
|
|
195
|
+
},
|
|
196
|
+
onAfterGenerate: async (result) => {
|
|
197
|
+
console.log('Generation complete:', result);
|
|
198
|
+
},
|
|
199
|
+
onError: async (error) => {
|
|
200
|
+
console.error('Error:', error);
|
|
201
|
+
},
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
await generateWithCallbacks(builtCallbacks);
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
### useAIFeatureCallbacks
|
|
210
|
+
|
|
211
|
+
AI feature-specific callbacks:
|
|
212
|
+
|
|
213
|
+
```tsx
|
|
214
|
+
import { useAIFeatureCallbacks } from '@umituz/react-native-ai-generation-content';
|
|
215
|
+
|
|
216
|
+
function AIGenerator() {
|
|
217
|
+
const { callbacks, setCallbacks } = useAIFeatureCallbacks({
|
|
218
|
+
featureType: 'text-to-image',
|
|
219
|
+
onProgress: (progress) => {
|
|
220
|
+
console.log('Progress:', progress);
|
|
221
|
+
},
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
return (
|
|
225
|
+
<View>
|
|
226
|
+
<Button
|
|
227
|
+
onPress={() => callbacks.generate({ prompt: 'A sunset' })}
|
|
228
|
+
title="Generate"
|
|
229
|
+
/>
|
|
230
|
+
</View>
|
|
231
|
+
);
|
|
232
|
+
}
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
## Utility Hooks
|
|
236
|
+
|
|
237
|
+
### useAsyncState
|
|
238
|
+
|
|
239
|
+
Manage async state:
|
|
240
|
+
|
|
241
|
+
```tsx
|
|
242
|
+
import { useAsyncState } from '@umituz/react-native-ai-generation-content';
|
|
243
|
+
|
|
244
|
+
function DataLoader() {
|
|
245
|
+
const { data, loading, error, execute } = useAsyncState(async () => {
|
|
246
|
+
return await fetchData();
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
return (
|
|
250
|
+
<View>
|
|
251
|
+
{loading && <ActivityIndicator />}
|
|
252
|
+
{error && <Text>Error: {error.message}</Text>}
|
|
253
|
+
{data && <Text>{data}</Text>}
|
|
254
|
+
<Button onPress={execute} title="Reload" />
|
|
255
|
+
</View>
|
|
256
|
+
);
|
|
257
|
+
}
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
## Hook Parameters
|
|
261
|
+
|
|
262
|
+
### UseGenerationOptions
|
|
263
|
+
|
|
264
|
+
```tsx
|
|
265
|
+
interface UseGenerationOptions {
|
|
266
|
+
featureType: string;
|
|
267
|
+
userId: string;
|
|
268
|
+
providerId?: string;
|
|
269
|
+
onProgress?: (progress: number) => void;
|
|
270
|
+
onSuccess?: (result: GenerationResult) => void;
|
|
271
|
+
onError?: (error: Error) => void;
|
|
272
|
+
}
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
### UseGenerationReturn
|
|
276
|
+
|
|
277
|
+
```tsx
|
|
278
|
+
interface UseGenerationReturn {
|
|
279
|
+
generate: (input: any) => Promise<GenerationResult>;
|
|
280
|
+
state: {
|
|
281
|
+
isProcessing: boolean;
|
|
282
|
+
progress: number;
|
|
283
|
+
result: GenerationResult | null;
|
|
284
|
+
error: Error | null;
|
|
285
|
+
};
|
|
286
|
+
reset: () => void;
|
|
287
|
+
}
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
### UseBackgroundGenerationOptions
|
|
291
|
+
|
|
292
|
+
```tsx
|
|
293
|
+
interface UseBackgroundGenerationOptions {
|
|
294
|
+
userId: string;
|
|
295
|
+
onJobComplete?: (job: BackgroundJob) => void;
|
|
296
|
+
onJobError?: (job: BackgroundJob) => void;
|
|
297
|
+
}
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
### UsePendingJobsOptions
|
|
301
|
+
|
|
302
|
+
```tsx
|
|
303
|
+
interface UsePendingJobsOptions {
|
|
304
|
+
userId: string;
|
|
305
|
+
autoRefresh?: boolean;
|
|
306
|
+
refreshInterval?: number;
|
|
307
|
+
}
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
## Advanced Usage
|
|
311
|
+
|
|
312
|
+
### Custom Hook Composition
|
|
313
|
+
|
|
314
|
+
```tsx
|
|
315
|
+
function useCustomGenerator() {
|
|
316
|
+
const generation = useGeneration({
|
|
317
|
+
featureType: 'text-to-image',
|
|
318
|
+
userId: 'user-123',
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
const moderation = useModeration();
|
|
322
|
+
|
|
323
|
+
const generateWithModeration = async (prompt: string) => {
|
|
324
|
+
// Check moderation first
|
|
325
|
+
const isSafe = await moderation.checkPrompt(prompt);
|
|
326
|
+
if (!isSafe) {
|
|
327
|
+
throw new Error('Prompt violates content policy');
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
// Generate
|
|
331
|
+
return await generation.generate({ prompt });
|
|
332
|
+
};
|
|
333
|
+
|
|
334
|
+
return {
|
|
335
|
+
...generation,
|
|
336
|
+
generate: generateWithModeration,
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
### Hook with Persistence
|
|
342
|
+
|
|
343
|
+
```tsx
|
|
344
|
+
import { useAsyncStorage } from '@umituz/react-native-ai-generation-content';
|
|
345
|
+
|
|
346
|
+
function usePersistedGeneration() {
|
|
347
|
+
const [history, setHistory] = useState([]);
|
|
348
|
+
|
|
349
|
+
const { generate, state } = useGeneration({
|
|
350
|
+
featureType: 'text-to-image',
|
|
351
|
+
userId: 'user-123',
|
|
352
|
+
onSuccess: async (result) => {
|
|
353
|
+
// Save to history
|
|
354
|
+
const newHistory = [...history, result];
|
|
355
|
+
setHistory(newHistory);
|
|
356
|
+
await AsyncStorage.setItem('generation_history', JSON.stringify(newHistory));
|
|
357
|
+
},
|
|
358
|
+
});
|
|
359
|
+
|
|
360
|
+
return { generate, state, history };
|
|
361
|
+
}
|
|
362
|
+
```
|
|
363
|
+
|
|
364
|
+
## Best Practices
|
|
365
|
+
|
|
366
|
+
1. **Cleanup**: Always cleanup effects
|
|
367
|
+
2. **Error Handling**: Handle errors in hooks
|
|
368
|
+
3. **Loading States**: Show loading to users
|
|
369
|
+
4. **Memoization**: Use useMemo/useCallback for performance
|
|
370
|
+
5. **Type Safety**: Use proper TypeScript types
|
|
371
|
+
|
|
372
|
+
## Related
|
|
373
|
+
|
|
374
|
+
- [Components](../components/) - UI components
|
|
375
|
+
- [Layouts](../layouts/) - Layout components
|
|
376
|
+
- [Screens](../screens/) - Screen components
|
|
377
|
+
|
|
378
|
+
## License
|
|
379
|
+
|
|
380
|
+
MIT
|