@umituz/react-native-settings 4.9.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,13 +2,16 @@
|
|
|
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";
|
|
14
|
+
import { storageRepository } from "@umituz/react-native-storage";
|
|
12
15
|
import { SettingsSection } from "./SettingsSection";
|
|
13
16
|
import { SettingItem } from "./SettingItem";
|
|
14
17
|
|
|
@@ -17,56 +20,74 @@ const TrashIcon: React.FC<{ size?: number; color?: string }> = ({ size = 24, col
|
|
|
17
20
|
<Feather name="trash-2" size={size} color={color} />
|
|
18
21
|
);
|
|
19
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
|
+
|
|
20
38
|
export interface DevSettingsProps {
|
|
21
|
-
/**
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
|
|
25
|
-
/** Custom
|
|
26
|
-
|
|
27
|
-
/** Custom description for clear data button */
|
|
28
|
-
clearDataDescription?: string;
|
|
39
|
+
/** Enable dev settings section (default: true in __DEV__ mode) */
|
|
40
|
+
enabled?: boolean;
|
|
41
|
+
/** Callback after storage is cleared - use this to reload the app */
|
|
42
|
+
onAfterClear?: () => Promise<void>;
|
|
43
|
+
/** Custom texts (optional - defaults to English) */
|
|
44
|
+
texts?: Partial<typeof DEFAULT_TEXTS>;
|
|
29
45
|
}
|
|
30
46
|
|
|
31
47
|
export const DevSettingsSection: React.FC<DevSettingsProps> = ({
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
clearDataDescription,
|
|
48
|
+
enabled = true,
|
|
49
|
+
onAfterClear,
|
|
50
|
+
texts = {},
|
|
36
51
|
}) => {
|
|
37
|
-
const { t } = useLocalization();
|
|
38
52
|
const tokens = useAppDesignTokens();
|
|
39
53
|
|
|
40
|
-
//
|
|
41
|
-
|
|
42
|
-
return null;
|
|
43
|
-
}
|
|
54
|
+
// Merge custom texts with defaults
|
|
55
|
+
const t = { ...DEFAULT_TEXTS, ...texts };
|
|
44
56
|
|
|
45
|
-
//
|
|
46
|
-
if (!
|
|
57
|
+
// Only render in development mode and when enabled
|
|
58
|
+
if (!__DEV__ || !enabled) {
|
|
47
59
|
return null;
|
|
48
60
|
}
|
|
49
61
|
|
|
50
62
|
const handleClearData = () => {
|
|
51
63
|
Alert.alert(
|
|
52
|
-
t
|
|
53
|
-
t
|
|
64
|
+
t.confirmTitle,
|
|
65
|
+
t.confirmMessage,
|
|
54
66
|
[
|
|
55
67
|
{
|
|
56
|
-
text: t
|
|
68
|
+
text: t.cancelButton,
|
|
57
69
|
style: "cancel",
|
|
58
70
|
},
|
|
59
71
|
{
|
|
60
|
-
text: t
|
|
72
|
+
text: t.confirmButton,
|
|
61
73
|
style: "destructive",
|
|
62
74
|
onPress: async () => {
|
|
63
75
|
try {
|
|
64
|
-
|
|
76
|
+
// Clear all storage
|
|
77
|
+
await storageRepository.clearAll();
|
|
78
|
+
|
|
79
|
+
// If callback provided, call it (e.g., reload app)
|
|
80
|
+
if (onAfterClear) {
|
|
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");
|
|
88
|
+
}
|
|
65
89
|
} catch {
|
|
66
|
-
Alert.alert(
|
|
67
|
-
t("common.error") || "Error",
|
|
68
|
-
t("settings.devSettings.clearData.error") || "Failed to clear data"
|
|
69
|
-
);
|
|
90
|
+
Alert.alert(t.errorTitle, t.errorMessage);
|
|
70
91
|
}
|
|
71
92
|
},
|
|
72
93
|
},
|
|
@@ -75,16 +96,11 @@ export const DevSettingsSection: React.FC<DevSettingsProps> = ({
|
|
|
75
96
|
};
|
|
76
97
|
|
|
77
98
|
return (
|
|
78
|
-
<SettingsSection
|
|
79
|
-
title={sectionTitle || t("settings.devSettings.title") || "Developer"}
|
|
80
|
-
>
|
|
99
|
+
<SettingsSection title={t.sectionTitle}>
|
|
81
100
|
<SettingItem
|
|
82
101
|
icon={TrashIcon}
|
|
83
|
-
title={
|
|
84
|
-
value={
|
|
85
|
-
clearDataDescription ||
|
|
86
|
-
t("settings.devSettings.clearData.description") || "Reset app to initial state (DEV only)"
|
|
87
|
-
}
|
|
102
|
+
title={t.clearTitle}
|
|
103
|
+
value={t.clearDescription}
|
|
88
104
|
onPress={handleClearData}
|
|
89
105
|
iconColor={tokens.colors.error}
|
|
90
106
|
titleColor={tokens.colors.error}
|
|
@@ -222,10 +222,9 @@ export const SettingsContent: React.FC<SettingsContentProps> = ({
|
|
|
222
222
|
|
|
223
223
|
{devSettings && (
|
|
224
224
|
<DevSettingsSection
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
clearDataDescription={devSettings.clearDataDescription}
|
|
225
|
+
enabled={devSettings.enabled}
|
|
226
|
+
onAfterClear={devSettings.onAfterClear}
|
|
227
|
+
texts={devSettings.texts}
|
|
229
228
|
/>
|
|
230
229
|
)}
|
|
231
230
|
|