@umituz/react-native-settings 4.20.56 → 4.20.58
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 +146 -4
- package/package.json +1 -2
- package/src/__tests__/setup.ts +1 -4
- package/src/application/README.md +322 -0
- package/src/domains/about/README.md +452 -0
- package/src/domains/about/presentation/hooks/README.md +350 -0
- package/src/domains/appearance/README.md +596 -0
- package/src/domains/appearance/hooks/README.md +366 -0
- package/src/domains/appearance/infrastructure/services/README.md +455 -0
- package/src/domains/appearance/presentation/components/README.md +493 -0
- package/src/domains/cloud-sync/README.md +451 -0
- package/src/domains/cloud-sync/presentation/components/README.md +493 -0
- package/src/domains/dev/README.md +477 -0
- package/src/domains/disclaimer/README.md +421 -0
- package/src/domains/disclaimer/presentation/components/README.md +394 -0
- package/src/domains/faqs/README.md +586 -0
- package/src/domains/feedback/README.md +565 -0
- package/src/domains/feedback/presentation/hooks/README.md +428 -0
- package/src/domains/legal/README.md +549 -0
- package/src/domains/rating/README.md +452 -0
- package/src/domains/rating/presentation/components/README.md +475 -0
- package/src/domains/video-tutorials/README.md +482 -0
- package/src/domains/video-tutorials/presentation/components/README.md +433 -0
- package/src/infrastructure/README.md +509 -0
- package/src/infrastructure/repositories/README.md +475 -0
- package/src/infrastructure/services/README.md +510 -0
- package/src/presentation/components/README.md +482 -0
- package/src/presentation/components/SettingsErrorBoundary/README.md +455 -0
- package/src/presentation/components/SettingsFooter/README.md +446 -0
- package/src/presentation/components/SettingsItemCard/README.md +457 -0
- package/src/presentation/components/SettingsSection/README.md +421 -0
- package/src/presentation/hooks/README.md +413 -0
- package/src/presentation/hooks/mutations/README.md +430 -0
- package/src/presentation/hooks/queries/README.md +441 -0
- package/src/presentation/navigation/README.md +532 -0
- package/src/presentation/navigation/components/README.md +330 -0
- package/src/presentation/navigation/hooks/README.md +399 -0
- package/src/presentation/navigation/utils/README.md +442 -0
- package/src/presentation/screens/README.md +525 -0
- package/src/presentation/screens/components/SettingsContent/README.md +404 -0
- package/src/presentation/screens/components/SettingsHeader/README.md +322 -0
- package/src/presentation/screens/components/sections/CustomSettingsList/README.md +388 -0
- package/src/presentation/screens/components/sections/FeatureSettingsSection/README.md +232 -0
- package/src/presentation/screens/components/sections/IdentitySettingsSection/README.md +325 -0
- package/src/presentation/screens/components/sections/ProfileSectionLoader/README.md +480 -0
- package/src/presentation/screens/components/sections/SupportSettingsSection/README.md +391 -0
- package/src/presentation/screens/hooks/README.md +383 -0
- package/src/presentation/screens/types/README.md +439 -0
- package/src/presentation/screens/utils/README.md +288 -0
|
@@ -0,0 +1,439 @@
|
|
|
1
|
+
# Settings Screen Types
|
|
2
|
+
|
|
3
|
+
TypeScript type definitions for settings screen configuration, components, and utilities.
|
|
4
|
+
|
|
5
|
+
## Types
|
|
6
|
+
|
|
7
|
+
### SettingsConfig
|
|
8
|
+
|
|
9
|
+
Main configuration object for the settings screen.
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
interface SettingsConfig {
|
|
13
|
+
appearance?: FeatureVisibility | AppearanceConfig;
|
|
14
|
+
language?: FeatureVisibility | LanguageConfig;
|
|
15
|
+
notifications?: FeatureVisibility | NotificationsConfig;
|
|
16
|
+
about?: FeatureVisibility | AboutConfig;
|
|
17
|
+
legal?: FeatureVisibility | LegalConfig;
|
|
18
|
+
disclaimer?: FeatureVisibility | DisclaimerConfig;
|
|
19
|
+
userProfile?: boolean | UserProfileConfig;
|
|
20
|
+
feedback?: FeatureVisibility | FeedbackConfig;
|
|
21
|
+
rating?: FeatureVisibility | RatingConfig;
|
|
22
|
+
faqs?: FeatureVisibility | FAQConfig;
|
|
23
|
+
cloudSync?: FeatureVisibility | CloudSyncConfig;
|
|
24
|
+
subscription?: FeatureVisibility | SubscriptionConfig;
|
|
25
|
+
wallet?: FeatureVisibility | WalletConfig;
|
|
26
|
+
emptyStateText?: string;
|
|
27
|
+
}
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
#### Usage Examples
|
|
31
|
+
|
|
32
|
+
**Simple Configuration:**
|
|
33
|
+
|
|
34
|
+
```typescript
|
|
35
|
+
const config: SettingsConfig = {
|
|
36
|
+
appearance: true,
|
|
37
|
+
language: true,
|
|
38
|
+
notifications: 'auto',
|
|
39
|
+
about: false,
|
|
40
|
+
};
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
**Advanced Configuration:**
|
|
44
|
+
|
|
45
|
+
```typescript
|
|
46
|
+
const config: SettingsConfig = {
|
|
47
|
+
appearance: {
|
|
48
|
+
enabled: true,
|
|
49
|
+
route: 'CustomAppearance',
|
|
50
|
+
showThemeSection: true,
|
|
51
|
+
showColorsSection: true,
|
|
52
|
+
},
|
|
53
|
+
language: {
|
|
54
|
+
enabled: 'auto',
|
|
55
|
+
route: 'LanguageSelection',
|
|
56
|
+
showFlags: true,
|
|
57
|
+
},
|
|
58
|
+
subscription: {
|
|
59
|
+
enabled: true,
|
|
60
|
+
title: 'Upgrade to Pro',
|
|
61
|
+
onPress: () => navigation.navigate('Upgrade'),
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### FeatureVisibility
|
|
67
|
+
|
|
68
|
+
Feature enablement type:
|
|
69
|
+
|
|
70
|
+
```typescript
|
|
71
|
+
type FeatureVisibility = boolean | 'auto';
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
- `true`: Always show feature
|
|
75
|
+
- `false`: Never show feature
|
|
76
|
+
- `'auto'`: Automatically detect based on navigation
|
|
77
|
+
|
|
78
|
+
### NormalizedConfig
|
|
79
|
+
|
|
80
|
+
Normalized configuration with consistent structure:
|
|
81
|
+
|
|
82
|
+
```typescript
|
|
83
|
+
interface NormalizedConfig {
|
|
84
|
+
appearance: {
|
|
85
|
+
enabled: boolean;
|
|
86
|
+
config?: AppearanceConfig;
|
|
87
|
+
};
|
|
88
|
+
language: {
|
|
89
|
+
enabled: boolean;
|
|
90
|
+
config?: LanguageConfig;
|
|
91
|
+
};
|
|
92
|
+
notifications: {
|
|
93
|
+
enabled: boolean;
|
|
94
|
+
config?: NotificationsConfig;
|
|
95
|
+
};
|
|
96
|
+
// ... other features
|
|
97
|
+
}
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### CustomSettingsSection
|
|
101
|
+
|
|
102
|
+
Type for custom settings sections:
|
|
103
|
+
|
|
104
|
+
```typescript
|
|
105
|
+
interface CustomSettingsSection {
|
|
106
|
+
id?: string;
|
|
107
|
+
title: string;
|
|
108
|
+
order?: number;
|
|
109
|
+
content?: ReactNode;
|
|
110
|
+
items?: CustomSettingsItem[];
|
|
111
|
+
}
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### CustomSettingsItem
|
|
115
|
+
|
|
116
|
+
Type for custom settings items:
|
|
117
|
+
|
|
118
|
+
```typescript
|
|
119
|
+
interface CustomSettingsItem {
|
|
120
|
+
id?: string;
|
|
121
|
+
title: string;
|
|
122
|
+
subtitle?: string;
|
|
123
|
+
icon: IconName;
|
|
124
|
+
onPress?: () => void;
|
|
125
|
+
rightIcon?: IconName;
|
|
126
|
+
iconBgColor?: string;
|
|
127
|
+
iconColor?: string;
|
|
128
|
+
}
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
## Content Configuration Types
|
|
132
|
+
|
|
133
|
+
### AppearanceConfig
|
|
134
|
+
|
|
135
|
+
```typescript
|
|
136
|
+
interface AppearanceConfig {
|
|
137
|
+
enabled?: FeatureVisibility;
|
|
138
|
+
route?: string;
|
|
139
|
+
showThemeSection?: boolean;
|
|
140
|
+
showColorsSection?: boolean;
|
|
141
|
+
showPreviewSection?: boolean;
|
|
142
|
+
}
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### LanguageConfig
|
|
146
|
+
|
|
147
|
+
```typescript
|
|
148
|
+
interface LanguageConfig {
|
|
149
|
+
enabled?: FeatureVisibility;
|
|
150
|
+
route?: string;
|
|
151
|
+
showFlags?: boolean;
|
|
152
|
+
}
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### NotificationsConfig
|
|
156
|
+
|
|
157
|
+
```typescript
|
|
158
|
+
interface NotificationsConfig {
|
|
159
|
+
enabled?: FeatureVisibility;
|
|
160
|
+
route?: string;
|
|
161
|
+
showQuietHours?: boolean;
|
|
162
|
+
showCategories?: boolean;
|
|
163
|
+
}
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
### AboutConfig
|
|
167
|
+
|
|
168
|
+
```typescript
|
|
169
|
+
interface AboutConfig {
|
|
170
|
+
enabled?: FeatureVisibility;
|
|
171
|
+
route?: string;
|
|
172
|
+
appName?: string;
|
|
173
|
+
version?: string;
|
|
174
|
+
buildNumber?: string;
|
|
175
|
+
developer?: string;
|
|
176
|
+
contactEmail?: string;
|
|
177
|
+
websiteUrl?: string;
|
|
178
|
+
websiteDisplay?: string;
|
|
179
|
+
moreAppsUrl?: string;
|
|
180
|
+
}
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
### LegalConfig
|
|
184
|
+
|
|
185
|
+
```typescript
|
|
186
|
+
interface LegalConfig {
|
|
187
|
+
enabled?: FeatureVisibility;
|
|
188
|
+
route?: string;
|
|
189
|
+
showPrivacy?: boolean;
|
|
190
|
+
showTerms?: boolean;
|
|
191
|
+
showEula?: boolean;
|
|
192
|
+
privacyPolicyUrl?: string;
|
|
193
|
+
termsOfServiceUrl?: string;
|
|
194
|
+
eulaUrl?: string;
|
|
195
|
+
}
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
### DisclaimerConfig
|
|
199
|
+
|
|
200
|
+
```typescript
|
|
201
|
+
interface DisclaimerConfig {
|
|
202
|
+
enabled?: FeatureVisibility;
|
|
203
|
+
route?: string;
|
|
204
|
+
title?: string;
|
|
205
|
+
message?: string;
|
|
206
|
+
shortMessage?: string;
|
|
207
|
+
}
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
## User Feature Types
|
|
211
|
+
|
|
212
|
+
### UserProfileConfig
|
|
213
|
+
|
|
214
|
+
```typescript
|
|
215
|
+
interface UserProfileConfig {
|
|
216
|
+
displayName?: string;
|
|
217
|
+
userId?: string;
|
|
218
|
+
isAnonymous?: boolean;
|
|
219
|
+
avatarUrl?: string;
|
|
220
|
+
accountSettingsRoute?: string;
|
|
221
|
+
onPress?: () => void;
|
|
222
|
+
anonymousDisplayName?: string;
|
|
223
|
+
avatarServiceUrl?: string;
|
|
224
|
+
}
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
### FeedbackConfig
|
|
228
|
+
|
|
229
|
+
```typescript
|
|
230
|
+
interface FeedbackConfig {
|
|
231
|
+
enabled?: FeatureVisibility;
|
|
232
|
+
title?: string;
|
|
233
|
+
description?: string;
|
|
234
|
+
feedbackTypes?: FeedbackType[];
|
|
235
|
+
}
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
### RatingConfig
|
|
239
|
+
|
|
240
|
+
```typescript
|
|
241
|
+
interface RatingConfig {
|
|
242
|
+
enabled?: FeatureVisibility;
|
|
243
|
+
title?: string;
|
|
244
|
+
description?: string;
|
|
245
|
+
storeUrl?: string;
|
|
246
|
+
}
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
### FAQConfig
|
|
250
|
+
|
|
251
|
+
```typescript
|
|
252
|
+
interface FAQConfig {
|
|
253
|
+
enabled?: FeatureVisibility;
|
|
254
|
+
title?: string;
|
|
255
|
+
description?: string;
|
|
256
|
+
categories?: FAQCategory[];
|
|
257
|
+
}
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
### SubscriptionConfig
|
|
261
|
+
|
|
262
|
+
```typescript
|
|
263
|
+
interface SubscriptionConfig {
|
|
264
|
+
enabled?: FeatureVisibility;
|
|
265
|
+
title?: string;
|
|
266
|
+
description?: string;
|
|
267
|
+
icon?: string;
|
|
268
|
+
onPress?: () => void;
|
|
269
|
+
sectionTitle?: string;
|
|
270
|
+
}
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
### WalletConfig
|
|
274
|
+
|
|
275
|
+
```typescript
|
|
276
|
+
interface WalletConfig {
|
|
277
|
+
enabled?: FeatureVisibility;
|
|
278
|
+
title?: string;
|
|
279
|
+
description?: string;
|
|
280
|
+
icon?: string;
|
|
281
|
+
route?: string;
|
|
282
|
+
sectionTitle?: string;
|
|
283
|
+
}
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
### CloudSyncConfig
|
|
287
|
+
|
|
288
|
+
```typescript
|
|
289
|
+
interface CloudSyncConfig {
|
|
290
|
+
enabled?: FeatureVisibility;
|
|
291
|
+
title?: string;
|
|
292
|
+
description?: string;
|
|
293
|
+
}
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
## Base Types
|
|
297
|
+
|
|
298
|
+
### BaseTypes.ts
|
|
299
|
+
|
|
300
|
+
```typescript
|
|
301
|
+
type FeatureVisibility = boolean | 'auto';
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
### ContentConfig.ts
|
|
305
|
+
|
|
306
|
+
```typescript
|
|
307
|
+
export interface AppearanceConfig { ... }
|
|
308
|
+
export interface LanguageConfig { ... }
|
|
309
|
+
export interface NotificationsConfig { ... }
|
|
310
|
+
export interface AboutConfig { ... }
|
|
311
|
+
export interface LegalConfig { ... }
|
|
312
|
+
export interface DisclaimerConfig { ... }
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
### UserFeatureConfig.ts
|
|
316
|
+
|
|
317
|
+
```typescript
|
|
318
|
+
export interface UserProfileConfig { ... }
|
|
319
|
+
export interface FeedbackConfig { ... }
|
|
320
|
+
export interface RatingConfig { ... }
|
|
321
|
+
export interface FAQConfig { ... }
|
|
322
|
+
export interface CloudSyncConfig { ... }
|
|
323
|
+
export interface SubscriptionConfig { ... }
|
|
324
|
+
export interface WalletConfig { ... }
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
## Type Guards
|
|
328
|
+
|
|
329
|
+
### Checking Config Type
|
|
330
|
+
|
|
331
|
+
```typescript
|
|
332
|
+
function isAppearanceConfig(
|
|
333
|
+
value: FeatureVisibility | AppearanceConfig
|
|
334
|
+
): value is AppearanceConfig {
|
|
335
|
+
return typeof value === 'object' && value !== null;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
// Usage
|
|
339
|
+
if (isAppearanceConfig(config.appearance)) {
|
|
340
|
+
console.log(config.appearance.route); // TypeScript knows this exists
|
|
341
|
+
}
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
### Checking Feature Enabled
|
|
345
|
+
|
|
346
|
+
```typescript
|
|
347
|
+
function isFeatureEnabled(
|
|
348
|
+
value: FeatureVisibility | any
|
|
349
|
+
): boolean {
|
|
350
|
+
if (value === 'auto') return true; // Will be detected
|
|
351
|
+
if (typeof value === 'boolean') return value;
|
|
352
|
+
if (value?.enabled === 'auto') return true;
|
|
353
|
+
return value?.enabled === true;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
// Usage
|
|
357
|
+
if (isFeatureEnabled(config.appearance)) {
|
|
358
|
+
// Feature is enabled
|
|
359
|
+
}
|
|
360
|
+
```
|
|
361
|
+
|
|
362
|
+
## Type Exports
|
|
363
|
+
|
|
364
|
+
All types are exported from:
|
|
365
|
+
|
|
366
|
+
```typescript
|
|
367
|
+
// types/index.ts
|
|
368
|
+
export * from './BaseTypes';
|
|
369
|
+
export * from './ContentConfig';
|
|
370
|
+
export * from './UserFeatureConfig';
|
|
371
|
+
export * from './CustomSection';
|
|
372
|
+
export * from './SettingsConfig';
|
|
373
|
+
```
|
|
374
|
+
|
|
375
|
+
## Usage Examples
|
|
376
|
+
|
|
377
|
+
### Type-Safe Config
|
|
378
|
+
|
|
379
|
+
```typescript
|
|
380
|
+
import type { SettingsConfig, AppearanceConfig } from '@umituz/react-native-settings';
|
|
381
|
+
|
|
382
|
+
const config: SettingsConfig = {
|
|
383
|
+
appearance: {
|
|
384
|
+
enabled: true,
|
|
385
|
+
route: 'CustomAppearance',
|
|
386
|
+
showThemeSection: true,
|
|
387
|
+
showColorsSection: false,
|
|
388
|
+
},
|
|
389
|
+
};
|
|
390
|
+
```
|
|
391
|
+
|
|
392
|
+
### Custom Section Type
|
|
393
|
+
|
|
394
|
+
```typescript
|
|
395
|
+
import type { CustomSettingsSection } from '@umituz/react-native-settings';
|
|
396
|
+
|
|
397
|
+
const customSection: CustomSettingsSection = {
|
|
398
|
+
id: 'custom',
|
|
399
|
+
title: 'CUSTOM SECTION',
|
|
400
|
+
order: 1,
|
|
401
|
+
items: [
|
|
402
|
+
{
|
|
403
|
+
id: 'item1',
|
|
404
|
+
title: 'Custom Item',
|
|
405
|
+
icon: 'settings-outline',
|
|
406
|
+
onPress: () => console.log('Pressed'),
|
|
407
|
+
},
|
|
408
|
+
],
|
|
409
|
+
};
|
|
410
|
+
```
|
|
411
|
+
|
|
412
|
+
### Type Inference
|
|
413
|
+
|
|
414
|
+
```typescript
|
|
415
|
+
import { normalizeSettingsConfig } from '@umituz/react-native-settings';
|
|
416
|
+
import type { NormalizedConfig } from '@umituz/react-native-settings';
|
|
417
|
+
|
|
418
|
+
const normalized: NormalizedConfig = normalizeSettingsConfig(config);
|
|
419
|
+
```
|
|
420
|
+
|
|
421
|
+
## Best Practices
|
|
422
|
+
|
|
423
|
+
1. **Type Safety**: Always use proper TypeScript types
|
|
424
|
+
2. **Type Guards**: Use type guards for config objects
|
|
425
|
+
3. **Defaults**: Provide sensible defaults for all config
|
|
426
|
+
4. **Validation**: Validate config at runtime
|
|
427
|
+
5. **Documentation**: Document custom config objects
|
|
428
|
+
6. **Type Exports**: Use centralized type exports
|
|
429
|
+
7. **Generic Types**: Leverage generics for reusability
|
|
430
|
+
|
|
431
|
+
## Related
|
|
432
|
+
|
|
433
|
+
- **normalizeConfig**: Config normalization utilities
|
|
434
|
+
- **useFeatureDetection**: Feature detection hook
|
|
435
|
+
- **SettingsScreen**: Main screen component
|
|
436
|
+
|
|
437
|
+
## License
|
|
438
|
+
|
|
439
|
+
MIT
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
# Settings Screen Utilities
|
|
2
|
+
|
|
3
|
+
Utility functions for normalizing and managing settings screen configuration.
|
|
4
|
+
|
|
5
|
+
## Functions
|
|
6
|
+
|
|
7
|
+
### normalizeSettingsConfig
|
|
8
|
+
|
|
9
|
+
Normalizes the settings configuration object to a consistent format.
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
import { normalizeSettingsConfig } from '@umituz/react-native-settings';
|
|
13
|
+
|
|
14
|
+
const config = {
|
|
15
|
+
appearance: true,
|
|
16
|
+
notifications: 'auto',
|
|
17
|
+
about: false,
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const normalized = normalizeSettingsConfig(config);
|
|
21
|
+
// Returns: NormalizedConfig with enabled flags and config objects
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
#### Parameters
|
|
25
|
+
|
|
26
|
+
| Parameter | Type | Description |
|
|
27
|
+
|-----------|------|-------------|
|
|
28
|
+
| `config` | `SettingsConfig \| undefined` | Raw configuration object |
|
|
29
|
+
|
|
30
|
+
#### Returns
|
|
31
|
+
|
|
32
|
+
`NormalizedConfig` - Normalized configuration with consistent structure
|
|
33
|
+
|
|
34
|
+
#### Examples
|
|
35
|
+
|
|
36
|
+
**Basic Config:**
|
|
37
|
+
|
|
38
|
+
```typescript
|
|
39
|
+
const config = {
|
|
40
|
+
appearance: true,
|
|
41
|
+
language: true,
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const normalized = normalizeSettingsConfig(config);
|
|
45
|
+
// {
|
|
46
|
+
// appearance: { enabled: true },
|
|
47
|
+
// language: { enabled: true },
|
|
48
|
+
// notifications: { enabled: false },
|
|
49
|
+
// // ... others default to { enabled: false }
|
|
50
|
+
// }
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
**Auto Detection:**
|
|
54
|
+
|
|
55
|
+
```typescript
|
|
56
|
+
const config = {
|
|
57
|
+
appearance: 'auto', // Enable if screen exists
|
|
58
|
+
language: 'auto',
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const normalized = normalizeSettingsConfig(config);
|
|
62
|
+
// Will check navigation for screen availability
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
**Advanced Config:**
|
|
66
|
+
|
|
67
|
+
```typescript
|
|
68
|
+
const config = {
|
|
69
|
+
appearance: {
|
|
70
|
+
enabled: true,
|
|
71
|
+
route: 'CustomAppearance',
|
|
72
|
+
showThemeSection: true,
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const normalized = normalizeSettingsConfig(config);
|
|
77
|
+
// {
|
|
78
|
+
// appearance: { enabled: true, config: { route: '...', showThemeSection: true } }
|
|
79
|
+
// }
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### normalizeConfigValue
|
|
83
|
+
|
|
84
|
+
Normalizes a single config value to enabled/config format.
|
|
85
|
+
|
|
86
|
+
```typescript
|
|
87
|
+
import { normalizeConfigValue } from '@umituz/react-native-settings';
|
|
88
|
+
|
|
89
|
+
// Boolean
|
|
90
|
+
normalizeConfigValue(true, false)
|
|
91
|
+
// { enabled: true }
|
|
92
|
+
|
|
93
|
+
// Auto
|
|
94
|
+
normalizeConfigValue('auto', false)
|
|
95
|
+
// { enabled: false } (will be determined dynamically)
|
|
96
|
+
|
|
97
|
+
// Object
|
|
98
|
+
normalizeConfigValue({ enabled: true, route: 'Custom' }, false)
|
|
99
|
+
// { enabled: true, config: { enabled: true, route: 'Custom' } }
|
|
100
|
+
|
|
101
|
+
// Undefined
|
|
102
|
+
normalizeConfigValue(undefined, true)
|
|
103
|
+
// { enabled: true }
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
#### Type Parameters
|
|
107
|
+
|
|
108
|
+
| Parameter | Type | Description |
|
|
109
|
+
|-----------|------|-------------|
|
|
110
|
+
| `T` | Config object type | Type of config object |
|
|
111
|
+
| `value` | `FeatureVisibility \| T \| undefined` | Config value to normalize |
|
|
112
|
+
| `defaultValue` | `FeatureVisibility` | Default enabled state |
|
|
113
|
+
|
|
114
|
+
## NormalizedConfig Structure
|
|
115
|
+
|
|
116
|
+
```typescript
|
|
117
|
+
interface NormalizedConfig {
|
|
118
|
+
appearance: {
|
|
119
|
+
enabled: boolean;
|
|
120
|
+
config?: AppearanceConfig;
|
|
121
|
+
};
|
|
122
|
+
language: {
|
|
123
|
+
enabled: boolean;
|
|
124
|
+
config?: LanguageConfig;
|
|
125
|
+
};
|
|
126
|
+
notifications: {
|
|
127
|
+
enabled: boolean;
|
|
128
|
+
config?: NotificationsConfig;
|
|
129
|
+
};
|
|
130
|
+
about: {
|
|
131
|
+
enabled: boolean;
|
|
132
|
+
config?: AboutConfig;
|
|
133
|
+
};
|
|
134
|
+
legal: {
|
|
135
|
+
enabled: boolean;
|
|
136
|
+
config?: LegalConfig;
|
|
137
|
+
};
|
|
138
|
+
disclaimer: {
|
|
139
|
+
enabled: boolean;
|
|
140
|
+
config?: DisclaimerConfig;
|
|
141
|
+
};
|
|
142
|
+
userProfile: {
|
|
143
|
+
enabled: boolean;
|
|
144
|
+
config?: UserProfileConfig;
|
|
145
|
+
};
|
|
146
|
+
feedback: {
|
|
147
|
+
enabled: boolean;
|
|
148
|
+
config?: FeedbackConfig;
|
|
149
|
+
};
|
|
150
|
+
rating: {
|
|
151
|
+
enabled: boolean;
|
|
152
|
+
config?: RatingConfig;
|
|
153
|
+
};
|
|
154
|
+
faqs: {
|
|
155
|
+
enabled: boolean;
|
|
156
|
+
config?: FAQConfig;
|
|
157
|
+
};
|
|
158
|
+
subscription: {
|
|
159
|
+
enabled: boolean;
|
|
160
|
+
config?: SubscriptionConfig;
|
|
161
|
+
};
|
|
162
|
+
wallet: {
|
|
163
|
+
enabled: boolean;
|
|
164
|
+
config?: WalletConfig;
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
## FeatureVisibility
|
|
170
|
+
|
|
171
|
+
Type alias for feature enablement:
|
|
172
|
+
|
|
173
|
+
```typescript
|
|
174
|
+
type FeatureVisibility = boolean | 'auto';
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
- `true`: Feature is enabled
|
|
178
|
+
- `false`: Feature is disabled
|
|
179
|
+
- `'auto'`: Feature is automatically detected (checks navigation)
|
|
180
|
+
|
|
181
|
+
## Default Values
|
|
182
|
+
|
|
183
|
+
Default values for each feature:
|
|
184
|
+
|
|
185
|
+
| Feature | Default | Description |
|
|
186
|
+
|---------|---------|-------------|
|
|
187
|
+
| `appearance` | `'auto'` | Auto-detect |
|
|
188
|
+
| `language` | `'auto'` | Auto-detect |
|
|
189
|
+
| `notifications` | `'auto'` | Auto-detect |
|
|
190
|
+
| `about` | `'auto'` | Auto-detect |
|
|
191
|
+
| `legal` | `'auto'` | Auto-detect |
|
|
192
|
+
| `disclaimer` | `false` | Disabled |
|
|
193
|
+
| `userProfile` | `false` | Disabled |
|
|
194
|
+
| `feedback` | `false` | Disabled |
|
|
195
|
+
| `rating` | `false` | Disabled |
|
|
196
|
+
| `faqs` | `false` | Disabled |
|
|
197
|
+
| `subscription` | `false` | Disabled |
|
|
198
|
+
| `wallet` | `false` | Disabled |
|
|
199
|
+
|
|
200
|
+
## Usage Examples
|
|
201
|
+
|
|
202
|
+
### Complete Normalization
|
|
203
|
+
|
|
204
|
+
```typescript
|
|
205
|
+
import { normalizeSettingsConfig } from '@umituz/react-native-settings';
|
|
206
|
+
|
|
207
|
+
function SettingsScreenWrapper() {
|
|
208
|
+
const rawConfig = {
|
|
209
|
+
appearance: true,
|
|
210
|
+
language: {
|
|
211
|
+
enabled: true,
|
|
212
|
+
route: 'LanguageSelection',
|
|
213
|
+
showFlags: true,
|
|
214
|
+
},
|
|
215
|
+
notifications: 'auto',
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
const normalized = normalizeSettingsConfig(rawConfig);
|
|
219
|
+
|
|
220
|
+
return (
|
|
221
|
+
<SettingsContent
|
|
222
|
+
normalizedConfig={normalized}
|
|
223
|
+
features={normalized}
|
|
224
|
+
/>
|
|
225
|
+
);
|
|
226
|
+
}
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
### Feature Detection Integration
|
|
230
|
+
|
|
231
|
+
```typescript
|
|
232
|
+
import { normalizeSettingsConfig, useFeatureDetection } from '@umituz/react-native-settings';
|
|
233
|
+
|
|
234
|
+
function SettingsScreenWithDetection() {
|
|
235
|
+
const navigation = useNavigation();
|
|
236
|
+
const config = {
|
|
237
|
+
appearance: 'auto',
|
|
238
|
+
language: 'auto',
|
|
239
|
+
notifications: 'auto',
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
const normalized = normalizeSettingsConfig(config);
|
|
243
|
+
const features = useFeatureDetection(normalized, navigation, {
|
|
244
|
+
notificationServiceAvailable: true,
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
return (
|
|
248
|
+
<SettingsContent
|
|
249
|
+
normalizedConfig={normalized}
|
|
250
|
+
features={features}
|
|
251
|
+
/>
|
|
252
|
+
);
|
|
253
|
+
}
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
## Auto Detection
|
|
257
|
+
|
|
258
|
+
When using `'auto'`, features are detected based on:
|
|
259
|
+
|
|
260
|
+
1. **Navigation State**: Checks if screen exists in navigation stack
|
|
261
|
+
2. **Config Override**: Respects `enabled: true/false` in config object
|
|
262
|
+
3. **Service Availability**: Checks if required services are available
|
|
263
|
+
|
|
264
|
+
```typescript
|
|
265
|
+
// Auto detection flow
|
|
266
|
+
appearance.config?.enabled === true // Explicitly enabled
|
|
267
|
+
|| (appearance.config?.enabled !== false // Not explicitly disabled
|
|
268
|
+
&& hasNavigationScreen(navigation, 'Appearance')) // Screen exists
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
## Best Practices
|
|
272
|
+
|
|
273
|
+
1. **Always Normalize**: Normalize config before passing to components
|
|
274
|
+
2. **Use Auto**: Use `'auto'` for features that should be conditionally shown
|
|
275
|
+
3. **Explicit Control**: Use boolean for features that must be shown/hidden
|
|
276
|
+
4. **Advanced Config**: Use config objects for detailed customization
|
|
277
|
+
5. **Feature Detection**: Always use with `useFeatureDetection` hook
|
|
278
|
+
6. **Type Safety**: Leverage TypeScript for config type checking
|
|
279
|
+
|
|
280
|
+
## Related
|
|
281
|
+
|
|
282
|
+
- **useFeatureDetection**: Hook for detecting features
|
|
283
|
+
- **SettingsConfig**: Configuration types
|
|
284
|
+
- **SettingsContent**: Content component
|
|
285
|
+
|
|
286
|
+
## License
|
|
287
|
+
|
|
288
|
+
MIT
|