@haposoft/cafekit 0.3.1 → 0.3.5

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.
@@ -0,0 +1,508 @@
1
+ # React Native Customization - Impact Analysis
2
+
3
+ Hướng dẫn customize Impact Analysis cho React Native projects.
4
+
5
+ ## React Native Project Structure
6
+
7
+ ### Typical Structure
8
+ ```
9
+ thanksgift-react-native/
10
+ ├── src/
11
+ │ ├── components/ # React components
12
+ │ ├── screens/ # Screen components
13
+ │ ├── navigation/ # React Navigation
14
+ │ ├── services/ # API services
15
+ │ ├── hooks/ # Custom hooks
16
+ │ ├── utils/ # Utilities
17
+ │ ├── store/ # State management (Redux/Zustand/Context)
18
+ │ ├── types/ # TypeScript types
19
+ │ ├── assets/ # Images, fonts
20
+ │ └── constants/ # Constants
21
+ ├── android/ # Android native code
22
+ ├── ios/ # iOS native code
23
+ ├── App.tsx # Root component
24
+ ├── package.json
25
+ └── tsconfig.json
26
+ ```
27
+
28
+ ## Feature Mapping for React Native
29
+
30
+ ### Pattern-Based Detection
31
+
32
+ | File Pattern | Feature | User Actions |
33
+ |-------------|---------|--------------|
34
+ | `**/screens/Auth/**`, `**/screens/Login/**` | Authentication & Login | Login, Logout, Sign Up, Password Reset, Biometric Auth |
35
+ | `**/screens/Profile/**`, `**/screens/User/**` | User Profile | View Profile, Edit Profile, Upload Avatar, Change Settings |
36
+ | `**/screens/Home/**`, `**/screens/Feed/**` | Home Feed | View Feed, Refresh, Pull to Refresh, Infinite Scroll |
37
+ | `**/screens/Product/**`, `**/screens/Item/**` | Product/Item Display | View Details, Add to Cart, Share, Favorite |
38
+ | `**/screens/Cart/**`, `**/screens/Checkout/**` | Shopping Cart | Add Item, Remove Item, Update Quantity, Checkout |
39
+ | `**/screens/Payment/**` | Payment | Select Payment Method, Process Payment, View Receipt |
40
+ | `**/screens/Order/**` | Order Management | View Orders, Track Order, Cancel Order |
41
+ | `**/navigation/**` | Navigation | Navigate Between Screens, Deep Linking, Tab Navigation |
42
+ | `**/services/api/**` | API Integration | Fetch Data, Post Data, Handle Errors, Retry Logic |
43
+ | `**/store/**`, `**/context/**` | State Management | Update State, Subscribe to Changes, Persist State |
44
+ | `**/hooks/use***` | Custom Hooks | Reusable Logic, Side Effects, State Management |
45
+ | `**/components/Button/**`, `**/components/Input/**` | UI Components | User Interaction, Form Input, Validation |
46
+ | `**/utils/storage/**` | Local Storage | Save Data, Load Data, Clear Data (AsyncStorage) |
47
+ | `**/utils/notification/**` | Push Notifications | Send Notification, Handle Notification, Request Permission |
48
+ | `**/utils/camera/**`, `**/utils/image/**` | Camera/Image | Take Photo, Pick Image, Upload Image |
49
+ | `**/utils/location/**` | Location Services | Get Location, Track Location, Request Permission |
50
+ | `**/android/**`, `**/ios/**` | Native Code | Native Modules, Permissions, Platform-Specific |
51
+
52
+ ### Content-Based Detection
53
+
54
+ | Keywords | Feature | User Actions |
55
+ |----------|---------|--------------|
56
+ | `AsyncStorage`, `@react-native-async-storage` | Local Storage | Save, Load, Clear Data |
57
+ | `react-navigation`, `useNavigation`, `navigate` | Navigation | Navigate, Go Back, Reset Stack |
58
+ | `fetch`, `axios`, `api.` | API Calls | Fetch Data, Post Data, Handle Errors |
59
+ | `useState`, `useEffect`, `useContext` | State Management | Update State, Side Effects |
60
+ | `redux`, `useDispatch`, `useSelector` | Redux State | Dispatch Actions, Select State |
61
+ | `zustand`, `create` | Zustand Store | Update Store, Subscribe |
62
+ | `Camera`, `ImagePicker`, `launchCamera` | Camera/Image | Take Photo, Pick Image |
63
+ | `Geolocation`, `getCurrentPosition` | Location | Get Location, Track |
64
+ | `PushNotification`, `messaging` | Notifications | Send, Receive, Handle |
65
+ | `Linking`, `openURL` | Deep Linking | Open URL, Handle Deep Link |
66
+ | `PermissionsAndroid`, `request` | Permissions | Request, Check Permission |
67
+ | `Platform.OS`, `Platform.select` | Platform-Specific | iOS/Android Differences |
68
+ | `Animated`, `useAnimatedStyle` | Animations | Animate Views, Gestures |
69
+ | `FlatList`, `ScrollView`, `renderItem` | Lists | Render List, Scroll, Refresh |
70
+
71
+ ## React Native Specific Edge Cases
72
+
73
+ ### 1. Platform-Specific Issues
74
+
75
+ ```typescript
76
+ // ❌ Not handling platform differences
77
+ const styles = StyleSheet.create({
78
+ container: {
79
+ paddingTop: 20 // Wrong on iOS with notch
80
+ }
81
+ });
82
+
83
+ // ✅ Platform-specific handling
84
+ import { Platform, StatusBar } from 'react-native';
85
+
86
+ const styles = StyleSheet.create({
87
+ container: {
88
+ paddingTop: Platform.OS === 'ios' ? StatusBar.currentHeight : 0
89
+ }
90
+ });
91
+ ```
92
+
93
+ **Check:**
94
+ - [ ] Platform.OS checks for iOS/Android differences
95
+ - [ ] SafeAreaView for notch/home indicator
96
+ - [ ] StatusBar height handling
97
+ - [ ] Platform-specific permissions
98
+
99
+ ### 2. AsyncStorage Issues
100
+
101
+ ```typescript
102
+ // ❌ Not handling async errors
103
+ const data = await AsyncStorage.getItem('user');
104
+ const user = JSON.parse(data);
105
+
106
+ // ✅ Proper error handling
107
+ try {
108
+ const data = await AsyncStorage.getItem('user');
109
+ const user = data ? JSON.parse(data) : null;
110
+ return user;
111
+ } catch (error) {
112
+ console.error('AsyncStorage error:', error);
113
+ return null;
114
+ }
115
+ ```
116
+
117
+ **Check:**
118
+ - [ ] Try-catch for AsyncStorage operations
119
+ - [ ] Null checks before JSON.parse
120
+ - [ ] Storage quota limits
121
+ - [ ] Migration for storage schema changes
122
+
123
+ ### 3. Navigation Issues
124
+
125
+ ```typescript
126
+ // ❌ Navigation without safety checks
127
+ navigation.navigate('Profile', { userId: user.id });
128
+
129
+ // ✅ Safe navigation
130
+ if (navigation.canGoBack()) {
131
+ navigation.goBack();
132
+ } else {
133
+ navigation.navigate('Home');
134
+ }
135
+
136
+ // Check if user exists
137
+ if (user?.id) {
138
+ navigation.navigate('Profile', { userId: user.id });
139
+ }
140
+ ```
141
+
142
+ **Check:**
143
+ - [ ] Navigation params validation
144
+ - [ ] canGoBack() before goBack()
145
+ - [ ] Deep link handling
146
+ - [ ] Navigation state persistence
147
+
148
+ ### 4. Image/Camera Issues
149
+
150
+ ```typescript
151
+ // ❌ Not handling permissions
152
+ const result = await ImagePicker.launchCamera();
153
+
154
+ // ✅ Request permissions first
155
+ import { PermissionsAndroid, Platform } from 'react-native';
156
+
157
+ async function takePhoto() {
158
+ if (Platform.OS === 'android') {
159
+ const granted = await PermissionsAndroid.request(
160
+ PermissionsAndroid.PERMISSIONS.CAMERA
161
+ );
162
+ if (granted !== PermissionsAndroid.RESULTS.GRANTED) {
163
+ Alert.alert('Permission denied');
164
+ return;
165
+ }
166
+ }
167
+
168
+ const result = await ImagePicker.launchCamera();
169
+ if (!result.cancelled) {
170
+ // Handle image
171
+ }
172
+ }
173
+ ```
174
+
175
+ **Check:**
176
+ - [ ] Permission requests before camera/gallery
177
+ - [ ] Handle permission denied
178
+ - [ ] Image size limits
179
+ - [ ] Image compression
180
+ - [ ] Upload error handling
181
+
182
+ ### 5. FlatList Performance
183
+
184
+ ```typescript
185
+ // ❌ No optimization
186
+ <FlatList
187
+ data={items}
188
+ renderItem={({ item }) => <ItemCard item={item} />}
189
+ />
190
+
191
+ // ✅ Optimized
192
+ <FlatList
193
+ data={items}
194
+ renderItem={({ item }) => <ItemCard item={item} />}
195
+ keyExtractor={(item) => item.id}
196
+ getItemLayout={(data, index) => ({
197
+ length: ITEM_HEIGHT,
198
+ offset: ITEM_HEIGHT * index,
199
+ index,
200
+ })}
201
+ removeClippedSubviews={true}
202
+ maxToRenderPerBatch={10}
203
+ windowSize={10}
204
+ initialNumToRender={10}
205
+ />
206
+ ```
207
+
208
+ **Check:**
209
+ - [ ] keyExtractor provided
210
+ - [ ] getItemLayout for fixed height items
211
+ - [ ] removeClippedSubviews enabled
212
+ - [ ] Pagination for large lists
213
+ - [ ] Memoized renderItem
214
+
215
+ ### 6. State Management Issues
216
+
217
+ ```typescript
218
+ // ❌ Direct state mutation
219
+ const [user, setUser] = useState({ name: 'John' });
220
+ user.name = 'Jane'; // Wrong!
221
+
222
+ // ✅ Immutable updates
223
+ setUser({ ...user, name: 'Jane' });
224
+
225
+ // ❌ Missing cleanup
226
+ useEffect(() => {
227
+ const subscription = api.subscribe();
228
+ // Missing cleanup!
229
+ }, []);
230
+
231
+ // ✅ Proper cleanup
232
+ useEffect(() => {
233
+ const subscription = api.subscribe();
234
+ return () => subscription.unsubscribe();
235
+ }, []);
236
+ ```
237
+
238
+ **Check:**
239
+ - [ ] Immutable state updates
240
+ - [ ] useEffect cleanup functions
241
+ - [ ] Dependency arrays correct
242
+ - [ ] Avoid infinite loops
243
+
244
+ ### 7. API/Network Issues
245
+
246
+ ```typescript
247
+ // ❌ No timeout or retry
248
+ const response = await fetch(url);
249
+
250
+ // ✅ Timeout and retry logic
251
+ const fetchWithTimeout = async (url, timeout = 10000) => {
252
+ const controller = new AbortController();
253
+ const id = setTimeout(() => controller.abort(), timeout);
254
+
255
+ try {
256
+ const response = await fetch(url, {
257
+ signal: controller.signal
258
+ });
259
+ clearTimeout(id);
260
+ return response;
261
+ } catch (error) {
262
+ if (error.name === 'AbortError') {
263
+ throw new Error('Request timeout');
264
+ }
265
+ throw error;
266
+ }
267
+ };
268
+ ```
269
+
270
+ **Check:**
271
+ - [ ] Network timeout handling
272
+ - [ ] Retry logic for failed requests
273
+ - [ ] Offline mode handling
274
+ - [ ] Loading states
275
+ - [ ] Error messages user-friendly
276
+
277
+ ## React Native Test Scenarios
278
+
279
+ ### Template: Navigation Test
280
+
281
+ ```markdown
282
+ ## Test Scenario: Screen Navigation
283
+
284
+ **Objective:** Verify navigation works correctly
285
+
286
+ **Preconditions:**
287
+ - App launched
288
+ - User logged in (if required)
289
+
290
+ **Test Steps:**
291
+ 1. Tap on {button/tab}
292
+ 2. Verify screen transition
293
+ 3. Verify screen content loaded
294
+ 4. Tap back button
295
+ 5. Verify returned to previous screen
296
+
297
+ **Expected Results:**
298
+ - Smooth transition animation
299
+ - No white flash
300
+ - Content loads within 2 seconds
301
+ - Back button works correctly
302
+ - Navigation state preserved
303
+
304
+ **Edge Cases:**
305
+ - Deep link navigation
306
+ - Navigation with params
307
+ - Navigation when offline
308
+ - Rapid taps (debouncing)
309
+
310
+ **Platforms:**
311
+ - [ ] iOS
312
+ - [ ] Android
313
+ ```
314
+
315
+ ### Template: Permission Test
316
+
317
+ ```markdown
318
+ ## Test Scenario: Camera Permission
319
+
320
+ **Objective:** Verify camera permission flow
321
+
322
+ **Preconditions:**
323
+ - App installed fresh (no permissions granted)
324
+
325
+ **Test Steps:**
326
+ 1. Tap "Take Photo" button
327
+ 2. Observe permission dialog
328
+ 3. Grant permission
329
+ 4. Verify camera opens
330
+ 5. Take photo
331
+ 6. Verify photo saved
332
+
333
+ **Expected Results:**
334
+ - Permission dialog shows
335
+ - Clear explanation why permission needed
336
+ - Camera opens after grant
337
+ - Photo captured successfully
338
+ - Photo displayed in app
339
+
340
+ **Edge Cases:**
341
+ - Permission denied
342
+ - Permission denied permanently (iOS)
343
+ - Permission revoked in settings
344
+ - Camera not available (simulator)
345
+
346
+ **Platforms:**
347
+ - [ ] iOS (different permission flow)
348
+ - [ ] Android (runtime permissions)
349
+ ```
350
+
351
+ ### Template: Offline Mode Test
352
+
353
+ ```markdown
354
+ ## Test Scenario: Offline Functionality
355
+
356
+ **Objective:** Verify app works offline
357
+
358
+ **Preconditions:**
359
+ - App has cached data
360
+ - Network connected initially
361
+
362
+ **Test Steps:**
363
+ 1. Load screen with data
364
+ 2. Turn off network (Airplane mode)
365
+ 3. Navigate to different screens
366
+ 4. Try to refresh data
367
+ 5. Turn on network
368
+ 6. Verify data syncs
369
+
370
+ **Expected Results:**
371
+ - Cached data displays offline
372
+ - Clear "offline" indicator shown
373
+ - Actions queued for later sync
374
+ - No crashes when offline
375
+ - Data syncs when online
376
+
377
+ **Edge Cases:**
378
+ - No cached data
379
+ - Partial sync failures
380
+ - Network switches during request
381
+ - Long offline period
382
+
383
+ **Platforms:**
384
+ - [ ] iOS
385
+ - [ ] Android
386
+ ```
387
+
388
+ ## Customization for thanksgift-react-native
389
+
390
+ ### 1. Update Feature Mapping
391
+
392
+ Based on your project structure, update patterns in:
393
+ - `references/change-detection.md`
394
+ - Add React Native specific patterns
395
+
396
+ ### 2. Add React Native Edge Cases
397
+
398
+ Add to `references/edge-case-identification.md`:
399
+ - Platform-specific issues
400
+ - AsyncStorage issues
401
+ - Navigation issues
402
+ - Permission issues
403
+ - Image/Camera issues
404
+ - FlatList performance
405
+
406
+ ### 3. Add React Native Test Templates
407
+
408
+ Add to `references/test-scenario-generation.md`:
409
+ - Navigation tests
410
+ - Permission tests
411
+ - Offline mode tests
412
+ - Platform-specific tests
413
+
414
+ ### 4. Create Custom Config (Optional)
415
+
416
+ Create `impact-analysis.config.js` in project root:
417
+
418
+ ```javascript
419
+ module.exports = {
420
+ // Custom feature patterns
421
+ featurePatterns: {
422
+ 'Gift Management': ['**/screens/Gift/**', '**/services/gift/**'],
423
+ 'Thank You Cards': ['**/screens/ThankYou/**', '**/components/Card/**'],
424
+ 'User Profile': ['**/screens/Profile/**', '**/services/user/**'],
425
+ },
426
+
427
+ // Custom edge case checks
428
+ edgeCaseChecks: [
429
+ 'AsyncStorage operations',
430
+ 'Platform.OS checks',
431
+ 'Permission requests',
432
+ 'Image upload size limits',
433
+ 'Navigation param validation',
434
+ ],
435
+
436
+ // Test priorities
437
+ testPriorities: {
438
+ 'Gift creation': 'P0',
439
+ 'Thank you sending': 'P0',
440
+ 'Profile update': 'P1',
441
+ 'Settings': 'P2',
442
+ }
443
+ };
444
+ ```
445
+
446
+ ## Implementation Steps
447
+
448
+ ### Step 1: Analyze Project Structure
449
+
450
+ ```bash
451
+ # Navigate to project
452
+ cd /Users/luutrungnghia/Desktop/thanksgift-react-native
453
+
454
+ # Check structure
455
+ ls -la src/
456
+
457
+ # Check dependencies
458
+ cat package.json | grep -A 20 "dependencies"
459
+ ```
460
+
461
+ ### Step 2: Identify Key Features
462
+
463
+ Look for:
464
+ - Main screens (src/screens/)
465
+ - API services (src/services/)
466
+ - State management (src/store/ or src/context/)
467
+ - Navigation structure (src/navigation/)
468
+ - Custom hooks (src/hooks/)
469
+
470
+ ### Step 3: Customize Feature Patterns
471
+
472
+ Update patterns based on actual structure:
473
+ - Gift-related features
474
+ - Thank you card features
475
+ - User management
476
+ - Notification features
477
+ - Payment features (if any)
478
+
479
+ ### Step 4: Add Project-Specific Edge Cases
480
+
481
+ Common for gift apps:
482
+ - Image upload for gift photos
483
+ - Push notifications for thank you reminders
484
+ - Offline gift creation
485
+ - Payment processing
486
+ - Social sharing
487
+
488
+ ### Step 5: Create Test Scenarios
489
+
490
+ Focus on:
491
+ - Gift creation flow
492
+ - Thank you card sending
493
+ - Image upload
494
+ - Notifications
495
+ - Offline mode
496
+
497
+ ## Next Steps
498
+
499
+ 1. **Share project structure** - Copy project to workspace or share structure
500
+ 2. **Identify key features** - List main features of thanksgift app
501
+ 3. **Customize patterns** - Update feature mapping for your app
502
+ 4. **Add edge cases** - Add gift-app specific edge cases
503
+ 5. **Create test templates** - Create test scenarios for key flows
504
+
505
+ Would you like me to:
506
+ - Analyze specific parts of your project?
507
+ - Create custom feature patterns?
508
+ - Generate test scenarios for specific features?