@umituz/react-native-settings 4.10.0 → 4.11.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
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}
|
|
@@ -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
|
|