@umituz/react-native-settings 4.10.0 → 4.12.0
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/package.json +1 -1
- package/src/presentation/components/DevSettingsSection.tsx +42 -36
- package/src/presentation/components/UserProfileHeader.tsx +9 -0
- package/src/presentation/screens/components/SettingsContent.tsx +1 -3
- package/LICENSE +0 -22
- package/src/domain/repositories/ISettingsRepository.ts +0 -58
package/package.json
CHANGED
|
@@ -2,12 +2,14 @@
|
|
|
2
2
|
* Dev Settings Section Component
|
|
3
3
|
* Only visible in __DEV__ mode
|
|
4
4
|
* Provides development utilities like clearing storage
|
|
5
|
+
*
|
|
6
|
+
* NOTE: This component uses hardcoded English text since it's DEV-only
|
|
7
|
+
* and doesn't need localization support.
|
|
5
8
|
*/
|
|
6
9
|
|
|
7
10
|
import React from "react";
|
|
8
11
|
import { Alert } from "react-native";
|
|
9
12
|
import { Feather } from "@expo/vector-icons";
|
|
10
|
-
import { useLocalization } from "@umituz/react-native-localization";
|
|
11
13
|
import { useAppDesignTokens } from "@umituz/react-native-design-system-theme";
|
|
12
14
|
import { storageRepository } from "@umituz/react-native-storage";
|
|
13
15
|
import { SettingsSection } from "./SettingsSection";
|
|
@@ -18,29 +20,40 @@ const TrashIcon: React.FC<{ size?: number; color?: string }> = ({ size = 24, col
|
|
|
18
20
|
<Feather name="trash-2" size={size} color={color} />
|
|
19
21
|
);
|
|
20
22
|
|
|
23
|
+
// Default texts (English only - DEV feature)
|
|
24
|
+
const DEFAULT_TEXTS = {
|
|
25
|
+
sectionTitle: "Developer",
|
|
26
|
+
clearTitle: "Clear All Data",
|
|
27
|
+
clearDescription: "Reset app to initial state (DEV only)",
|
|
28
|
+
confirmTitle: "Clear All Data?",
|
|
29
|
+
confirmMessage: "This will clear all app data and reset to initial state. This action cannot be undone.",
|
|
30
|
+
cancelButton: "Cancel",
|
|
31
|
+
confirmButton: "Clear",
|
|
32
|
+
successTitle: "Success",
|
|
33
|
+
successMessage: "All data cleared. Restarting app...",
|
|
34
|
+
errorTitle: "Error",
|
|
35
|
+
errorMessage: "Failed to clear data",
|
|
36
|
+
};
|
|
37
|
+
|
|
21
38
|
export interface DevSettingsProps {
|
|
22
39
|
/** Enable dev settings section (default: true in __DEV__ mode) */
|
|
23
40
|
enabled?: boolean;
|
|
24
|
-
/**
|
|
41
|
+
/** Callback after storage is cleared - use this to reload the app */
|
|
25
42
|
onAfterClear?: () => Promise<void>;
|
|
26
|
-
/** Custom
|
|
27
|
-
|
|
28
|
-
/** Custom title for clear data button */
|
|
29
|
-
clearDataTitle?: string;
|
|
30
|
-
/** Custom description for clear data button */
|
|
31
|
-
clearDataDescription?: string;
|
|
43
|
+
/** Custom texts (optional - defaults to English) */
|
|
44
|
+
texts?: Partial<typeof DEFAULT_TEXTS>;
|
|
32
45
|
}
|
|
33
46
|
|
|
34
47
|
export const DevSettingsSection: React.FC<DevSettingsProps> = ({
|
|
35
48
|
enabled = true,
|
|
36
49
|
onAfterClear,
|
|
37
|
-
|
|
38
|
-
clearDataTitle,
|
|
39
|
-
clearDataDescription,
|
|
50
|
+
texts = {},
|
|
40
51
|
}) => {
|
|
41
|
-
const { t } = useLocalization();
|
|
42
52
|
const tokens = useAppDesignTokens();
|
|
43
53
|
|
|
54
|
+
// Merge custom texts with defaults
|
|
55
|
+
const t = { ...DEFAULT_TEXTS, ...texts };
|
|
56
|
+
|
|
44
57
|
// Only render in development mode and when enabled
|
|
45
58
|
if (!__DEV__ || !enabled) {
|
|
46
59
|
return null;
|
|
@@ -48,35 +61,33 @@ export const DevSettingsSection: React.FC<DevSettingsProps> = ({
|
|
|
48
61
|
|
|
49
62
|
const handleClearData = () => {
|
|
50
63
|
Alert.alert(
|
|
51
|
-
t
|
|
52
|
-
t
|
|
64
|
+
t.confirmTitle,
|
|
65
|
+
t.confirmMessage,
|
|
53
66
|
[
|
|
54
67
|
{
|
|
55
|
-
text: t
|
|
68
|
+
text: t.cancelButton,
|
|
56
69
|
style: "cancel",
|
|
57
70
|
},
|
|
58
71
|
{
|
|
59
|
-
text: t
|
|
72
|
+
text: t.confirmButton,
|
|
60
73
|
style: "destructive",
|
|
61
74
|
onPress: async () => {
|
|
62
75
|
try {
|
|
63
|
-
// Clear all storage
|
|
76
|
+
// Clear all storage
|
|
64
77
|
await storageRepository.clearAll();
|
|
65
78
|
|
|
66
|
-
//
|
|
79
|
+
// If callback provided, call it (e.g., reload app)
|
|
67
80
|
if (onAfterClear) {
|
|
68
|
-
|
|
81
|
+
Alert.alert(t.successTitle, t.successMessage);
|
|
82
|
+
// Small delay to show the alert before reload
|
|
83
|
+
setTimeout(async () => {
|
|
84
|
+
await onAfterClear();
|
|
85
|
+
}, 500);
|
|
86
|
+
} else {
|
|
87
|
+
Alert.alert(t.successTitle, "All data cleared successfully");
|
|
69
88
|
}
|
|
70
|
-
|
|
71
|
-
Alert.alert(
|
|
72
|
-
t("common.success") || "Success",
|
|
73
|
-
t("settings.devSettings.clearData.success") || "All data cleared successfully"
|
|
74
|
-
);
|
|
75
89
|
} catch {
|
|
76
|
-
Alert.alert(
|
|
77
|
-
t("common.error") || "Error",
|
|
78
|
-
t("settings.devSettings.clearData.error") || "Failed to clear data"
|
|
79
|
-
);
|
|
90
|
+
Alert.alert(t.errorTitle, t.errorMessage);
|
|
80
91
|
}
|
|
81
92
|
},
|
|
82
93
|
},
|
|
@@ -85,16 +96,11 @@ export const DevSettingsSection: React.FC<DevSettingsProps> = ({
|
|
|
85
96
|
};
|
|
86
97
|
|
|
87
98
|
return (
|
|
88
|
-
<SettingsSection
|
|
89
|
-
title={sectionTitle || t("settings.devSettings.title") || "Developer"}
|
|
90
|
-
>
|
|
99
|
+
<SettingsSection title={t.sectionTitle}>
|
|
91
100
|
<SettingItem
|
|
92
101
|
icon={TrashIcon}
|
|
93
|
-
title={
|
|
94
|
-
value={
|
|
95
|
-
clearDataDescription ||
|
|
96
|
-
t("settings.devSettings.clearData.description") || "Reset app to initial state (DEV only)"
|
|
97
|
-
}
|
|
102
|
+
title={t.clearTitle}
|
|
103
|
+
value={t.clearDescription}
|
|
98
104
|
onPress={handleClearData}
|
|
99
105
|
iconColor={tokens.colors.error}
|
|
100
106
|
titleColor={tokens.colors.error}
|
|
@@ -111,6 +111,15 @@ export const UserProfileHeader: React.FC<UserProfileHeaderProps> = ({
|
|
|
111
111
|
>
|
|
112
112
|
{finalDisplayName}
|
|
113
113
|
</AtomicText>
|
|
114
|
+
{userId && (
|
|
115
|
+
<AtomicText
|
|
116
|
+
type="bodySmall"
|
|
117
|
+
style={[styles.id, { color: colors.textSecondary }]}
|
|
118
|
+
numberOfLines={1}
|
|
119
|
+
>
|
|
120
|
+
{userId}
|
|
121
|
+
</AtomicText>
|
|
122
|
+
)}
|
|
114
123
|
</View>
|
|
115
124
|
</View>
|
|
116
125
|
{shouldShowChevron && (
|
|
@@ -224,9 +224,7 @@ export const SettingsContent: React.FC<SettingsContentProps> = ({
|
|
|
224
224
|
<DevSettingsSection
|
|
225
225
|
enabled={devSettings.enabled}
|
|
226
226
|
onAfterClear={devSettings.onAfterClear}
|
|
227
|
-
|
|
228
|
-
clearDataTitle={devSettings.clearDataTitle}
|
|
229
|
-
clearDataDescription={devSettings.clearDataDescription}
|
|
227
|
+
texts={devSettings.texts}
|
|
230
228
|
/>
|
|
231
229
|
)}
|
|
232
230
|
|
package/LICENSE
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2024 Ümit UZ
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
22
|
-
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Settings Repository Interface
|
|
3
|
-
*
|
|
4
|
-
* Defines contracts for settings persistence and retrieval
|
|
5
|
-
* Pure business logic - no dependencies on external frameworks
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
export interface UserSettings {
|
|
9
|
-
userId: string;
|
|
10
|
-
theme: 'light' | 'dark' | 'auto';
|
|
11
|
-
language: string;
|
|
12
|
-
notificationsEnabled: boolean;
|
|
13
|
-
emailNotifications: boolean;
|
|
14
|
-
pushNotifications: boolean;
|
|
15
|
-
soundEnabled: boolean;
|
|
16
|
-
vibrationEnabled: boolean;
|
|
17
|
-
privacyMode: boolean;
|
|
18
|
-
updatedAt: Date;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export interface SettingsError extends Error {
|
|
22
|
-
code: 'LOAD_FAILED' | 'SAVE_FAILED' | 'NOT_FOUND' | 'INVALID_DATA';
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export type SettingsResult<T> = {
|
|
26
|
-
success: true;
|
|
27
|
-
data: T;
|
|
28
|
-
} | {
|
|
29
|
-
success: false;
|
|
30
|
-
error: SettingsError;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Settings Repository Interface
|
|
35
|
-
* Repository pattern for settings management
|
|
36
|
-
*/
|
|
37
|
-
export interface ISettingsRepository {
|
|
38
|
-
/**
|
|
39
|
-
* Load user settings from persistent storage
|
|
40
|
-
*/
|
|
41
|
-
loadSettings(userId: string): Promise<SettingsResult<UserSettings>>;
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Save user settings to persistent storage
|
|
45
|
-
*/
|
|
46
|
-
saveSettings(settings: Partial<UserSettings>): Promise<SettingsResult<UserSettings>>;
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Reset settings to default values
|
|
50
|
-
*/
|
|
51
|
-
resetSettings(userId: string): Promise<SettingsResult<UserSettings>>;
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Get default settings for a user
|
|
55
|
-
*/
|
|
56
|
-
getDefaultSettings(userId: string): UserSettings;
|
|
57
|
-
}
|
|
58
|
-
|