@umituz/react-native-settings 5.4.17 → 5.4.19
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/dist/core/base/BaseService.d.ts +86 -0
- package/dist/core/index.d.ts +27 -0
- package/dist/core/patterns/Modal/ModalConfig.d.ts +197 -0
- package/dist/core/patterns/Modal/useModalState.d.ts +53 -0
- package/dist/core/patterns/Screen/ScreenConfig.d.ts +273 -0
- package/dist/core/patterns/Screen/useScreenData.d.ts +62 -0
- package/dist/core/utils/logger.d.ts +76 -0
- package/dist/core/utils/validators.d.ts +114 -0
- package/dist/domains/ai-consent/index.d.ts +37 -0
- package/dist/domains/ai-consent/presentation/components/AIConsentModal.d.ts +26 -0
- package/dist/domains/ai-consent/presentation/components/AIConsentSetting.d.ts +28 -0
- package/dist/domains/ai-consent/presentation/hooks/useAIConsent.d.ts +27 -0
- package/dist/domains/ai-consent/presentation/screens/AIConsentScreen.d.ts +37 -0
- package/dist/domains/disclaimer/index.d.ts +0 -2
- package/dist/domains/disclaimer/presentation/components/DisclaimerSetting.d.ts +1 -2
- package/dist/domains/disclaimer/presentation/screens/DisclaimerScreen.d.ts +11 -20
- package/dist/domains/feedback/index.d.ts +2 -1
- package/dist/domains/feedback/presentation/components/SupportSection.d.ts +1 -1
- package/dist/domains/feedback/presentation/screens/FeedbackScreen.d.ts +21 -0
- package/dist/domains/gamification/types/index.d.ts +1 -0
- package/dist/domains/gamification/utils/calculations.d.ts +3 -0
- package/dist/domains/localization/index.d.ts +1 -1
- package/dist/domains/localization/infrastructure/config/i18n.d.ts +1 -1
- package/dist/domains/notifications/infrastructure/services/NotificationService.d.ts +5 -2
- package/dist/domains/notifications/quietHours/infrastructure/hooks/useQuietHoursActions.d.ts +4 -4
- package/dist/domains/rating/application/services/RatingService.d.ts +50 -21
- package/dist/domains/rating/index.d.ts +2 -2
- package/dist/domains/rating/presentation/hooks/useAppRating.d.ts +1 -1
- package/dist/domains/rating/presentation/screens/RatingPromptScreen.d.ts +22 -0
- package/dist/index.d.ts +4 -0
- package/dist/infrastructure/services/SettingsService.d.ts +5 -2
- package/dist/presentation/components/GenericModal.d.ts +35 -0
- package/dist/presentation/components/GenericScreen.d.ts +41 -0
- package/dist/presentation/components/index.d.ts +17 -0
- package/dist/presentation/navigation/hooks/useSettingsNavigation.d.ts +21 -15
- package/dist/presentation/navigation/types.d.ts +8 -0
- package/dist/presentation/navigation/utils/navigationHelpers.d.ts +1 -1
- package/package.json +1 -1
- package/src/domains/ai-consent/index.ts +53 -0
- package/src/domains/ai-consent/presentation/components/AIConsentModal.tsx +64 -0
- package/src/domains/ai-consent/presentation/components/AIConsentSetting.tsx +106 -0
- package/src/domains/ai-consent/presentation/hooks/useAIConsent.ts +125 -0
- package/src/domains/ai-consent/presentation/screens/AIConsentScreen.tsx +414 -0
- package/src/index.ts +3 -0
- package/src/presentation/navigation/hooks/useSettingsScreens.ts +9 -1
- package/src/presentation/navigation/types.ts +2 -0
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BaseService
|
|
3
|
+
*
|
|
4
|
+
* Abstract base class for all domain services.
|
|
5
|
+
* Provides consistent error handling, logging, and result patterns.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* class MyService extends BaseService {
|
|
10
|
+
* protected serviceName = 'MyService';
|
|
11
|
+
*
|
|
12
|
+
* async doSomething(input: Input): Promise<Data> {
|
|
13
|
+
* return this.execute('doSomething', async () => {
|
|
14
|
+
* // Your logic here
|
|
15
|
+
* return result;
|
|
16
|
+
* });
|
|
17
|
+
* }
|
|
18
|
+
* }
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export type Result<T> = {
|
|
22
|
+
success: true;
|
|
23
|
+
data: T;
|
|
24
|
+
} | {
|
|
25
|
+
success: false;
|
|
26
|
+
error: string;
|
|
27
|
+
};
|
|
28
|
+
export type AsyncResult<T> = Promise<Result<T>>;
|
|
29
|
+
/**
|
|
30
|
+
* Abstract base service with error handling and logging
|
|
31
|
+
*/
|
|
32
|
+
export declare abstract class BaseService {
|
|
33
|
+
/**
|
|
34
|
+
* Service name for logging (must be implemented by subclass)
|
|
35
|
+
*/
|
|
36
|
+
protected abstract serviceName: string;
|
|
37
|
+
/**
|
|
38
|
+
* Execute an operation with automatic error handling and logging
|
|
39
|
+
*
|
|
40
|
+
* @param operation - Operation name for logging
|
|
41
|
+
* @param fn - Async function to execute
|
|
42
|
+
* @returns Result object with success flag
|
|
43
|
+
*/
|
|
44
|
+
protected execute<T>(operation: string, fn: () => Promise<T>): AsyncResult<T>;
|
|
45
|
+
/**
|
|
46
|
+
* Execute without error handling (for critical operations that should crash)
|
|
47
|
+
*
|
|
48
|
+
* @param operation - Operation name for logging
|
|
49
|
+
* @param fn - Async function to execute
|
|
50
|
+
* @returns Direct result from function
|
|
51
|
+
*/
|
|
52
|
+
protected executeUnsafe<T>(operation: string, fn: () => Promise<T>): Promise<T>;
|
|
53
|
+
/**
|
|
54
|
+
* Execute a synchronous operation with error handling
|
|
55
|
+
*
|
|
56
|
+
* @param operation - Operation name for logging
|
|
57
|
+
* @param fn - Sync function to execute
|
|
58
|
+
* @returns Result object with success flag
|
|
59
|
+
*/
|
|
60
|
+
protected executeSync<T>(operation: string, fn: () => T): Result<T>;
|
|
61
|
+
/**
|
|
62
|
+
* Log error in development mode
|
|
63
|
+
*
|
|
64
|
+
* @param operation - Operation name
|
|
65
|
+
* @param error - Error to log
|
|
66
|
+
*/
|
|
67
|
+
protected logError(operation: string, error: unknown): void;
|
|
68
|
+
/**
|
|
69
|
+
* Log info in development mode
|
|
70
|
+
*
|
|
71
|
+
* @param operation - Operation name
|
|
72
|
+
* @param message - Message to log
|
|
73
|
+
*/
|
|
74
|
+
protected logInfo(operation: string, message: string): void;
|
|
75
|
+
/**
|
|
76
|
+
* Log warning in development mode
|
|
77
|
+
*
|
|
78
|
+
* @param operation - Operation name
|
|
79
|
+
* @param message - Warning message
|
|
80
|
+
*/
|
|
81
|
+
protected logWarning(operation: string, message: string): void;
|
|
82
|
+
/**
|
|
83
|
+
* Check if running in development mode
|
|
84
|
+
*/
|
|
85
|
+
protected get isDev(): boolean;
|
|
86
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core Layer - Public API
|
|
3
|
+
*
|
|
4
|
+
* Foundational utilities and base classes for the entire application.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* import { BaseService, logger, ModalPresets } from '@/core';
|
|
9
|
+
*
|
|
10
|
+
* class MyService extends BaseService {
|
|
11
|
+
* protected serviceName = 'MyService';
|
|
12
|
+
* }
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export { BaseService } from './base/BaseService';
|
|
16
|
+
export type { Result, AsyncResult } from './base/BaseService';
|
|
17
|
+
export { logger, log, createLogger } from './utils/logger';
|
|
18
|
+
export type { Logger, LogContext } from './utils/logger';
|
|
19
|
+
export { validators, valid, invalid, validateAll } from './utils/validators';
|
|
20
|
+
export type { ValidationResult } from './utils/validators';
|
|
21
|
+
export { useModalState, useModalStateWithResult } from './patterns/Modal/useModalState';
|
|
22
|
+
export type { ModalState, ModalConfig, ModalAction, ModalContent, ModalBehavior, ModalResult } from './patterns/Modal/ModalConfig';
|
|
23
|
+
export { ModalPresets, confirmed, dismissed } from './patterns/Modal/ModalConfig';
|
|
24
|
+
export { useScreenData, useSimpleScreenData } from './patterns/Screen/useScreenData';
|
|
25
|
+
export type { UseScreenDataOptions } from './patterns/Screen/useScreenData';
|
|
26
|
+
export type { ScreenData, ScreenDataState, ScreenDataActions, ScreenFetchFunction, ScreenConfig, ScreenHeader, ScreenLoading, ScreenError, ScreenEmpty, ScreenLayout, } from './patterns/Screen/ScreenConfig';
|
|
27
|
+
export { ScreenPresets } from './patterns/Screen/ScreenConfig';
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Modal Configuration Types
|
|
3
|
+
*
|
|
4
|
+
* Standardized configuration for all modal components.
|
|
5
|
+
* Ensures consistency across the application.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* const config: ModalConfig = {
|
|
10
|
+
* title: 'Rating',
|
|
11
|
+
* content: 'Rate this app',
|
|
12
|
+
* actions: [
|
|
13
|
+
* { label: 'OK', onPress: () => {}, variant: 'primary' }
|
|
14
|
+
* ]
|
|
15
|
+
* };
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
import type { ReactNode } from 'react';
|
|
19
|
+
/**
|
|
20
|
+
* Modal action button configuration
|
|
21
|
+
*/
|
|
22
|
+
export interface ModalAction {
|
|
23
|
+
/**
|
|
24
|
+
* Button label text
|
|
25
|
+
*/
|
|
26
|
+
label: string;
|
|
27
|
+
/**
|
|
28
|
+
* Button press handler
|
|
29
|
+
*/
|
|
30
|
+
onPress: () => void | Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* Button variant
|
|
33
|
+
*/
|
|
34
|
+
variant?: 'primary' | 'secondary' | 'outline' | 'text' | 'danger';
|
|
35
|
+
/**
|
|
36
|
+
* Disable button
|
|
37
|
+
*/
|
|
38
|
+
disabled?: boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Show loading indicator
|
|
41
|
+
*/
|
|
42
|
+
loading?: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Test ID for E2E testing
|
|
45
|
+
*/
|
|
46
|
+
testID?: string;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Modal content configuration
|
|
50
|
+
*/
|
|
51
|
+
export interface ModalContent {
|
|
52
|
+
/**
|
|
53
|
+
* Modal title
|
|
54
|
+
*/
|
|
55
|
+
title?: string;
|
|
56
|
+
/**
|
|
57
|
+
* Modal subtitle or description
|
|
58
|
+
*/
|
|
59
|
+
subtitle?: string;
|
|
60
|
+
/**
|
|
61
|
+
* Main content (can be string or React component)
|
|
62
|
+
*/
|
|
63
|
+
message?: string | ReactNode;
|
|
64
|
+
/**
|
|
65
|
+
* Custom icon name
|
|
66
|
+
*/
|
|
67
|
+
icon?: string;
|
|
68
|
+
/**
|
|
69
|
+
* Icon color
|
|
70
|
+
*/
|
|
71
|
+
iconColor?: string;
|
|
72
|
+
/**
|
|
73
|
+
* Custom header component (overrides title/subtitle)
|
|
74
|
+
*/
|
|
75
|
+
header?: ReactNode;
|
|
76
|
+
/**
|
|
77
|
+
* Custom body component (overrides message)
|
|
78
|
+
*/
|
|
79
|
+
body?: ReactNode;
|
|
80
|
+
/**
|
|
81
|
+
* Custom footer component (overrides actions)
|
|
82
|
+
*/
|
|
83
|
+
footer?: ReactNode;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Modal behavior configuration
|
|
87
|
+
*/
|
|
88
|
+
export interface ModalBehavior {
|
|
89
|
+
/**
|
|
90
|
+
* Close on backdrop press
|
|
91
|
+
*/
|
|
92
|
+
closeOnBackdropPress?: boolean;
|
|
93
|
+
/**
|
|
94
|
+
* Close on back button press (Android)
|
|
95
|
+
*/
|
|
96
|
+
closeOnBackPress?: boolean;
|
|
97
|
+
/**
|
|
98
|
+
* Animation type
|
|
99
|
+
*/
|
|
100
|
+
animation?: 'none' | 'slide' | 'fade' | 'scale';
|
|
101
|
+
/**
|
|
102
|
+
* Dismissible flag
|
|
103
|
+
*/
|
|
104
|
+
dismissible?: boolean;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Complete modal configuration
|
|
108
|
+
*/
|
|
109
|
+
export interface ModalConfig extends ModalContent, ModalBehavior {
|
|
110
|
+
/**
|
|
111
|
+
* Modal actions (buttons)
|
|
112
|
+
*/
|
|
113
|
+
actions?: ModalAction[];
|
|
114
|
+
/**
|
|
115
|
+
* Maximum width (for responsive design)
|
|
116
|
+
*/
|
|
117
|
+
maxWidth?: number;
|
|
118
|
+
/**
|
|
119
|
+
* Test ID for E2E testing
|
|
120
|
+
*/
|
|
121
|
+
testID?: string;
|
|
122
|
+
/**
|
|
123
|
+
* Custom container style
|
|
124
|
+
*/
|
|
125
|
+
containerStyle?: object;
|
|
126
|
+
/**
|
|
127
|
+
* Custom content style
|
|
128
|
+
*/
|
|
129
|
+
contentStyle?: object;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Modal state for useModalState hook
|
|
133
|
+
*/
|
|
134
|
+
export interface ModalState {
|
|
135
|
+
/**
|
|
136
|
+
* Modal visibility
|
|
137
|
+
*/
|
|
138
|
+
visible: boolean;
|
|
139
|
+
/**
|
|
140
|
+
* Current modal configuration
|
|
141
|
+
*/
|
|
142
|
+
config: ModalConfig | null;
|
|
143
|
+
/**
|
|
144
|
+
* Show modal with configuration
|
|
145
|
+
*/
|
|
146
|
+
show: (config: ModalConfig) => void;
|
|
147
|
+
/**
|
|
148
|
+
* Hide modal
|
|
149
|
+
*/
|
|
150
|
+
hide: () => void;
|
|
151
|
+
/**
|
|
152
|
+
* Update modal configuration
|
|
153
|
+
*/
|
|
154
|
+
update: (config: Partial<ModalConfig>) => void;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Modal result type for async operations
|
|
158
|
+
*/
|
|
159
|
+
export type ModalResult<T = void> = {
|
|
160
|
+
confirmed: true;
|
|
161
|
+
data: T;
|
|
162
|
+
} | {
|
|
163
|
+
confirmed: false;
|
|
164
|
+
};
|
|
165
|
+
/**
|
|
166
|
+
* Create a confirmed modal result
|
|
167
|
+
*/
|
|
168
|
+
export declare function confirmed<T>(data?: T): ModalResult<T>;
|
|
169
|
+
/**
|
|
170
|
+
* Create a dismissed modal result
|
|
171
|
+
*/
|
|
172
|
+
export declare function dismissed(): ModalResult<never>;
|
|
173
|
+
/**
|
|
174
|
+
* Common preset configurations
|
|
175
|
+
*/
|
|
176
|
+
export declare const ModalPresets: {
|
|
177
|
+
/**
|
|
178
|
+
* Alert modal (single OK button)
|
|
179
|
+
*/
|
|
180
|
+
alert: (title: string, message: string, okText?: string) => ModalConfig;
|
|
181
|
+
/**
|
|
182
|
+
* Confirm modal (OK and Cancel buttons)
|
|
183
|
+
*/
|
|
184
|
+
confirm: (title: string, message: string, confirmText?: string, cancelText?: string) => ModalConfig;
|
|
185
|
+
/**
|
|
186
|
+
* Info modal (just message with icon)
|
|
187
|
+
*/
|
|
188
|
+
info: (title: string, message: string, icon?: string) => ModalConfig;
|
|
189
|
+
/**
|
|
190
|
+
* Error modal (error styling)
|
|
191
|
+
*/
|
|
192
|
+
error: (title: string, message: string) => ModalConfig;
|
|
193
|
+
/**
|
|
194
|
+
* Loading modal (spinner)
|
|
195
|
+
*/
|
|
196
|
+
loading: (message: string) => ModalConfig;
|
|
197
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* useModalState Hook
|
|
3
|
+
*
|
|
4
|
+
* Generic modal state management hook.
|
|
5
|
+
* Replaces modal-specific state logic across domains.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* const modal = useModalState();
|
|
10
|
+
*
|
|
11
|
+
* // Show modal
|
|
12
|
+
* modal.show({
|
|
13
|
+
* title: 'Confirm',
|
|
14
|
+
* message: 'Are you sure?',
|
|
15
|
+
* actions: [...]
|
|
16
|
+
* });
|
|
17
|
+
*
|
|
18
|
+
* // Hide modal
|
|
19
|
+
* modal.hide();
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
import type { ModalConfig, ModalState } from './ModalConfig';
|
|
23
|
+
/**
|
|
24
|
+
* Generic modal state management hook
|
|
25
|
+
*/
|
|
26
|
+
export declare function useModalState(initialConfig?: ModalConfig | null): ModalState;
|
|
27
|
+
/**
|
|
28
|
+
* Extended modal state with result handling
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* const modal = useModalStateWithResult<string>();
|
|
33
|
+
*
|
|
34
|
+
* const result = await modal.showAsync({
|
|
35
|
+
* title: 'Input',
|
|
36
|
+
* actions: [
|
|
37
|
+
* { label: 'OK', onPress: (resolve) => resolve('data') }
|
|
38
|
+
* ]
|
|
39
|
+
* });
|
|
40
|
+
*
|
|
41
|
+
* if (result.confirmed) {
|
|
42
|
+
* console.log(result.data);
|
|
43
|
+
* }
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export declare function useModalStateWithResult<T = void>(): {
|
|
47
|
+
visible: boolean;
|
|
48
|
+
config: ModalConfig;
|
|
49
|
+
showAsync: (newConfig: ModalConfig) => Promise<import("./ModalConfig").ModalResult<T>>;
|
|
50
|
+
hide: () => void;
|
|
51
|
+
confirm: (data?: T) => void;
|
|
52
|
+
update: (updates: Partial<ModalConfig>) => void;
|
|
53
|
+
};
|
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Screen Configuration Types
|
|
3
|
+
*
|
|
4
|
+
* Standardized configuration for all screen components.
|
|
5
|
+
* Ensures consistency across the application.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* const config: ScreenConfig = {
|
|
10
|
+
* title: 'Settings',
|
|
11
|
+
* loadingMessage: 'Loading settings...',
|
|
12
|
+
* errorMessage: 'Failed to load settings'
|
|
13
|
+
* };
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
import type { ReactNode } from 'react';
|
|
17
|
+
/**
|
|
18
|
+
* Screen header configuration
|
|
19
|
+
*/
|
|
20
|
+
export interface ScreenHeader {
|
|
21
|
+
/**
|
|
22
|
+
* Header title
|
|
23
|
+
*/
|
|
24
|
+
title?: string;
|
|
25
|
+
/**
|
|
26
|
+
* Header subtitle
|
|
27
|
+
*/
|
|
28
|
+
subtitle?: string;
|
|
29
|
+
/**
|
|
30
|
+
* Show back button
|
|
31
|
+
*/
|
|
32
|
+
showBackButton?: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Custom back button handler
|
|
35
|
+
*/
|
|
36
|
+
onBackPress?: () => void;
|
|
37
|
+
/**
|
|
38
|
+
* Custom header component
|
|
39
|
+
*/
|
|
40
|
+
custom?: ReactNode;
|
|
41
|
+
/**
|
|
42
|
+
* Right action buttons
|
|
43
|
+
*/
|
|
44
|
+
actions?: Array<{
|
|
45
|
+
icon: string;
|
|
46
|
+
onPress: () => void;
|
|
47
|
+
testID?: string;
|
|
48
|
+
}>;
|
|
49
|
+
/**
|
|
50
|
+
* Test ID for E2E testing
|
|
51
|
+
*/
|
|
52
|
+
testID?: string;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Screen loading state configuration
|
|
56
|
+
*/
|
|
57
|
+
export interface ScreenLoading {
|
|
58
|
+
/**
|
|
59
|
+
* Loading spinner size
|
|
60
|
+
*/
|
|
61
|
+
size?: 'sm' | 'md' | 'lg' | 'xl';
|
|
62
|
+
/**
|
|
63
|
+
* Loading message
|
|
64
|
+
*/
|
|
65
|
+
message?: string;
|
|
66
|
+
/**
|
|
67
|
+
* Custom loading component
|
|
68
|
+
*/
|
|
69
|
+
custom?: ReactNode;
|
|
70
|
+
/**
|
|
71
|
+
* Show full container spinner
|
|
72
|
+
*/
|
|
73
|
+
fullContainer?: boolean;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Screen error state configuration
|
|
77
|
+
*/
|
|
78
|
+
export interface ScreenError {
|
|
79
|
+
/**
|
|
80
|
+
* Error message prefix
|
|
81
|
+
*/
|
|
82
|
+
prefix?: string;
|
|
83
|
+
/**
|
|
84
|
+
* Default error message (when error details unknown)
|
|
85
|
+
*/
|
|
86
|
+
message?: string;
|
|
87
|
+
/**
|
|
88
|
+
* Retry button text
|
|
89
|
+
*/
|
|
90
|
+
retryText?: string;
|
|
91
|
+
/**
|
|
92
|
+
* Show retry button
|
|
93
|
+
*/
|
|
94
|
+
showRetry?: boolean;
|
|
95
|
+
/**
|
|
96
|
+
* Retry handler
|
|
97
|
+
*/
|
|
98
|
+
onRetry?: () => void;
|
|
99
|
+
/**
|
|
100
|
+
* Custom error component
|
|
101
|
+
*/
|
|
102
|
+
custom?: ReactNode;
|
|
103
|
+
/**
|
|
104
|
+
* Error icon name
|
|
105
|
+
*/
|
|
106
|
+
icon?: string;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Screen empty state configuration
|
|
110
|
+
*/
|
|
111
|
+
export interface ScreenEmpty {
|
|
112
|
+
/**
|
|
113
|
+
* Empty state message
|
|
114
|
+
*/
|
|
115
|
+
message?: string;
|
|
116
|
+
/**
|
|
117
|
+
* Empty state description
|
|
118
|
+
*/
|
|
119
|
+
description?: string;
|
|
120
|
+
/**
|
|
121
|
+
* Empty state icon
|
|
122
|
+
*/
|
|
123
|
+
icon?: string;
|
|
124
|
+
/**
|
|
125
|
+
* Custom empty component
|
|
126
|
+
*/
|
|
127
|
+
custom?: ReactNode;
|
|
128
|
+
/**
|
|
129
|
+
* Action button label
|
|
130
|
+
*/
|
|
131
|
+
actionLabel?: string;
|
|
132
|
+
/**
|
|
133
|
+
* Action button handler
|
|
134
|
+
*/
|
|
135
|
+
onAction?: () => void;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Screen layout configuration
|
|
139
|
+
*/
|
|
140
|
+
export interface ScreenLayout {
|
|
141
|
+
/**
|
|
142
|
+
* Safe area edges
|
|
143
|
+
*/
|
|
144
|
+
edges?: Array<'top' | 'bottom' | 'left' | 'right'>;
|
|
145
|
+
/**
|
|
146
|
+
* Scrollable content
|
|
147
|
+
*/
|
|
148
|
+
scrollable?: boolean;
|
|
149
|
+
/**
|
|
150
|
+
* Keyboard avoiding view
|
|
151
|
+
*/
|
|
152
|
+
keyboardAvoiding?: boolean;
|
|
153
|
+
/**
|
|
154
|
+
* Hide scroll indicator
|
|
155
|
+
*/
|
|
156
|
+
hideScrollIndicator?: boolean;
|
|
157
|
+
/**
|
|
158
|
+
* Content container style
|
|
159
|
+
*/
|
|
160
|
+
contentContainerStyle?: object;
|
|
161
|
+
/**
|
|
162
|
+
* Test ID for E2E testing
|
|
163
|
+
*/
|
|
164
|
+
testID?: string;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Complete screen configuration
|
|
168
|
+
*/
|
|
169
|
+
export interface ScreenConfig {
|
|
170
|
+
/**
|
|
171
|
+
* Screen header configuration
|
|
172
|
+
*/
|
|
173
|
+
header?: ScreenHeader;
|
|
174
|
+
/**
|
|
175
|
+
* Loading state configuration
|
|
176
|
+
*/
|
|
177
|
+
loading?: ScreenLoading;
|
|
178
|
+
/**
|
|
179
|
+
* Error state configuration
|
|
180
|
+
*/
|
|
181
|
+
error?: ScreenError;
|
|
182
|
+
/**
|
|
183
|
+
* Empty state configuration
|
|
184
|
+
*/
|
|
185
|
+
empty?: ScreenEmpty;
|
|
186
|
+
/**
|
|
187
|
+
* Layout configuration
|
|
188
|
+
*/
|
|
189
|
+
layout?: ScreenLayout;
|
|
190
|
+
/**
|
|
191
|
+
* Custom container style
|
|
192
|
+
*/
|
|
193
|
+
containerStyle?: object;
|
|
194
|
+
/**
|
|
195
|
+
* Screen test ID
|
|
196
|
+
*/
|
|
197
|
+
testID?: string;
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Screen data state (for useScreenData hook)
|
|
201
|
+
*/
|
|
202
|
+
export interface ScreenDataState<T> {
|
|
203
|
+
/**
|
|
204
|
+
* Loading state
|
|
205
|
+
*/
|
|
206
|
+
loading: boolean;
|
|
207
|
+
/**
|
|
208
|
+
* Error message
|
|
209
|
+
*/
|
|
210
|
+
error: string | null;
|
|
211
|
+
/**
|
|
212
|
+
* Data
|
|
213
|
+
*/
|
|
214
|
+
data: T | null;
|
|
215
|
+
/**
|
|
216
|
+
* Is initialized
|
|
217
|
+
*/
|
|
218
|
+
initialized: boolean;
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Screen data actions (for useScreenData hook)
|
|
222
|
+
*/
|
|
223
|
+
export interface ScreenDataActions<T> {
|
|
224
|
+
/**
|
|
225
|
+
* Set loading state
|
|
226
|
+
*/
|
|
227
|
+
setLoading: (loading: boolean) => void;
|
|
228
|
+
/**
|
|
229
|
+
* Set error state
|
|
230
|
+
*/
|
|
231
|
+
setError: (error: string | null) => void;
|
|
232
|
+
/**
|
|
233
|
+
* Set data state
|
|
234
|
+
*/
|
|
235
|
+
setData: (data: T | null) => void;
|
|
236
|
+
/**
|
|
237
|
+
* Reset state
|
|
238
|
+
*/
|
|
239
|
+
reset: () => void;
|
|
240
|
+
/**
|
|
241
|
+
* Refresh data (calls fetch function)
|
|
242
|
+
*/
|
|
243
|
+
refresh: () => Promise<void>;
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Screen data hook return type
|
|
247
|
+
*/
|
|
248
|
+
export type ScreenData<T> = ScreenDataState<T> & ScreenDataActions<T>;
|
|
249
|
+
/**
|
|
250
|
+
* Screen fetch function type
|
|
251
|
+
*/
|
|
252
|
+
export type ScreenFetchFunction<T> = () => Promise<T>;
|
|
253
|
+
/**
|
|
254
|
+
* Common preset configurations
|
|
255
|
+
*/
|
|
256
|
+
export declare const ScreenPresets: {
|
|
257
|
+
/**
|
|
258
|
+
* Default screen configuration
|
|
259
|
+
*/
|
|
260
|
+
default: ScreenConfig;
|
|
261
|
+
/**
|
|
262
|
+
* Modal screen configuration (no back button, full edges)
|
|
263
|
+
*/
|
|
264
|
+
modal: ScreenConfig;
|
|
265
|
+
/**
|
|
266
|
+
* Loading screen configuration
|
|
267
|
+
*/
|
|
268
|
+
loading: (message?: string) => ScreenConfig;
|
|
269
|
+
/**
|
|
270
|
+
* Error screen configuration
|
|
271
|
+
*/
|
|
272
|
+
error: (message?: string) => ScreenConfig;
|
|
273
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* useScreenData Hook
|
|
3
|
+
*
|
|
4
|
+
* Generic screen data management hook.
|
|
5
|
+
* Handles loading, error, and data states for screens.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* const screenData = useScreenData({
|
|
10
|
+
* fetch: async () => await api.getData(),
|
|
11
|
+
* autoFetch: true
|
|
12
|
+
* });
|
|
13
|
+
*
|
|
14
|
+
* if (screenData.loading) return <LoadingSpinner />;
|
|
15
|
+
* if (screenData.error) return <ErrorMessage error={screenData.error} />;
|
|
16
|
+
* return <DataView data={screenData.data} />;
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
import type { ScreenData, ScreenDataState, ScreenFetchFunction } from './ScreenConfig';
|
|
20
|
+
export interface UseScreenDataOptions<T> {
|
|
21
|
+
/**
|
|
22
|
+
* Fetch function to load data
|
|
23
|
+
*/
|
|
24
|
+
fetch: ScreenFetchFunction<T>;
|
|
25
|
+
/**
|
|
26
|
+
* Auto-fetch on mount
|
|
27
|
+
*/
|
|
28
|
+
autoFetch?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Initial data
|
|
31
|
+
*/
|
|
32
|
+
initialData?: T | null;
|
|
33
|
+
/**
|
|
34
|
+
* Dependencies for re-fetching
|
|
35
|
+
*/
|
|
36
|
+
deps?: unknown[];
|
|
37
|
+
/**
|
|
38
|
+
* Error handler
|
|
39
|
+
*/
|
|
40
|
+
onError?: (error: Error) => void;
|
|
41
|
+
/**
|
|
42
|
+
* Success handler
|
|
43
|
+
*/
|
|
44
|
+
onSuccess?: (data: T) => void;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Generic screen data management hook
|
|
48
|
+
*/
|
|
49
|
+
export declare function useScreenData<T>(options: UseScreenDataOptions<T>): ScreenData<T>;
|
|
50
|
+
/**
|
|
51
|
+
* Simple version for basic use cases
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```ts
|
|
55
|
+
* const { loading, error, data, refresh } = useSimpleScreenData(
|
|
56
|
+
* async () => await api.getData()
|
|
57
|
+
* );
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
export declare function useSimpleScreenData<T>(fetch: ScreenFetchFunction<T>, autoFetch?: boolean): ScreenDataState<T> & {
|
|
61
|
+
refresh: () => Promise<void>;
|
|
62
|
+
};
|