@umituz/react-native-settings 4.8.0 → 4.10.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/index.ts +2 -0
- package/src/presentation/components/DevSettingsSection.tsx +105 -0
- package/src/presentation/navigation/SettingsStackNavigator.tsx +9 -1
- package/src/presentation/screens/SettingsScreen.tsx +5 -0
- package/src/presentation/screens/components/SettingsContent.tsx +14 -0
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -76,3 +76,5 @@ export type { CloudSyncSettingProps } from './presentation/components/CloudSyncS
|
|
|
76
76
|
export { StorageClearSetting } from './presentation/components/StorageClearSetting';
|
|
77
77
|
export type { StorageClearSettingProps } from './presentation/components/StorageClearSetting';
|
|
78
78
|
|
|
79
|
+
export { DevSettingsSection } from './presentation/components/DevSettingsSection';
|
|
80
|
+
export type { DevSettingsProps } from './presentation/components/DevSettingsSection';
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dev Settings Section Component
|
|
3
|
+
* Only visible in __DEV__ mode
|
|
4
|
+
* Provides development utilities like clearing storage
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import React from "react";
|
|
8
|
+
import { Alert } from "react-native";
|
|
9
|
+
import { Feather } from "@expo/vector-icons";
|
|
10
|
+
import { useLocalization } from "@umituz/react-native-localization";
|
|
11
|
+
import { useAppDesignTokens } from "@umituz/react-native-design-system-theme";
|
|
12
|
+
import { storageRepository } from "@umituz/react-native-storage";
|
|
13
|
+
import { SettingsSection } from "./SettingsSection";
|
|
14
|
+
import { SettingItem } from "./SettingItem";
|
|
15
|
+
|
|
16
|
+
// Icon wrapper for SettingItem compatibility
|
|
17
|
+
const TrashIcon: React.FC<{ size?: number; color?: string }> = ({ size = 24, color }) => (
|
|
18
|
+
<Feather name="trash-2" size={size} color={color} />
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
export interface DevSettingsProps {
|
|
22
|
+
/** Enable dev settings section (default: true in __DEV__ mode) */
|
|
23
|
+
enabled?: boolean;
|
|
24
|
+
/** Optional callback after storage is cleared (e.g., reload app) */
|
|
25
|
+
onAfterClear?: () => Promise<void>;
|
|
26
|
+
/** Custom title for the section */
|
|
27
|
+
sectionTitle?: string;
|
|
28
|
+
/** Custom title for clear data button */
|
|
29
|
+
clearDataTitle?: string;
|
|
30
|
+
/** Custom description for clear data button */
|
|
31
|
+
clearDataDescription?: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export const DevSettingsSection: React.FC<DevSettingsProps> = ({
|
|
35
|
+
enabled = true,
|
|
36
|
+
onAfterClear,
|
|
37
|
+
sectionTitle,
|
|
38
|
+
clearDataTitle,
|
|
39
|
+
clearDataDescription,
|
|
40
|
+
}) => {
|
|
41
|
+
const { t } = useLocalization();
|
|
42
|
+
const tokens = useAppDesignTokens();
|
|
43
|
+
|
|
44
|
+
// Only render in development mode and when enabled
|
|
45
|
+
if (!__DEV__ || !enabled) {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const handleClearData = () => {
|
|
50
|
+
Alert.alert(
|
|
51
|
+
t("settings.devSettings.clearData.confirmTitle") || "Clear All Data?",
|
|
52
|
+
t("settings.devSettings.clearData.confirmMessage") || "This will clear all app data and reset to initial state. This action cannot be undone.",
|
|
53
|
+
[
|
|
54
|
+
{
|
|
55
|
+
text: t("common.cancel") || "Cancel",
|
|
56
|
+
style: "cancel",
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
text: t("common.confirm") || "Confirm",
|
|
60
|
+
style: "destructive",
|
|
61
|
+
onPress: async () => {
|
|
62
|
+
try {
|
|
63
|
+
// Clear all storage using the package's storageRepository
|
|
64
|
+
await storageRepository.clearAll();
|
|
65
|
+
|
|
66
|
+
// Call optional after-clear callback (e.g., reload app)
|
|
67
|
+
if (onAfterClear) {
|
|
68
|
+
await onAfterClear();
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
Alert.alert(
|
|
72
|
+
t("common.success") || "Success",
|
|
73
|
+
t("settings.devSettings.clearData.success") || "All data cleared successfully"
|
|
74
|
+
);
|
|
75
|
+
} catch {
|
|
76
|
+
Alert.alert(
|
|
77
|
+
t("common.error") || "Error",
|
|
78
|
+
t("settings.devSettings.clearData.error") || "Failed to clear data"
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
]
|
|
84
|
+
);
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
return (
|
|
88
|
+
<SettingsSection
|
|
89
|
+
title={sectionTitle || t("settings.devSettings.title") || "Developer"}
|
|
90
|
+
>
|
|
91
|
+
<SettingItem
|
|
92
|
+
icon={TrashIcon}
|
|
93
|
+
title={clearDataTitle || t("settings.devSettings.clearData.title") || "Clear All Data"}
|
|
94
|
+
value={
|
|
95
|
+
clearDataDescription ||
|
|
96
|
+
t("settings.devSettings.clearData.description") || "Reset app to initial state (DEV only)"
|
|
97
|
+
}
|
|
98
|
+
onPress={handleClearData}
|
|
99
|
+
iconColor={tokens.colors.error}
|
|
100
|
+
titleColor={tokens.colors.error}
|
|
101
|
+
isLast={true}
|
|
102
|
+
/>
|
|
103
|
+
</SettingsSection>
|
|
104
|
+
);
|
|
105
|
+
};
|
|
@@ -11,6 +11,7 @@ import { useAppDesignTokens } from "@umituz/react-native-design-system-theme";
|
|
|
11
11
|
import { SettingsScreen } from "../screens/SettingsScreen";
|
|
12
12
|
import { AppearanceScreen } from "../screens/AppearanceScreen";
|
|
13
13
|
import type { SettingsConfig } from "../screens/types";
|
|
14
|
+
import type { DevSettingsProps } from "../components/DevSettingsSection";
|
|
14
15
|
|
|
15
16
|
// Default param list - can be extended by apps
|
|
16
17
|
export type SettingsStackParamList = {
|
|
@@ -58,6 +59,11 @@ export interface SettingsStackNavigatorProps {
|
|
|
58
59
|
component: React.ComponentType<any>;
|
|
59
60
|
options?: any;
|
|
60
61
|
}>;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Dev settings (only shown in __DEV__ mode)
|
|
65
|
+
*/
|
|
66
|
+
devSettings?: DevSettingsProps;
|
|
61
67
|
}
|
|
62
68
|
|
|
63
69
|
const Stack = createStackNavigator<SettingsStackParamList>();
|
|
@@ -68,6 +74,7 @@ export const SettingsStackNavigator: React.FC<SettingsStackNavigatorProps> = ({
|
|
|
68
74
|
showUserProfile = false,
|
|
69
75
|
userProfile,
|
|
70
76
|
additionalScreens = [],
|
|
77
|
+
devSettings,
|
|
71
78
|
}) => {
|
|
72
79
|
const tokens = useAppDesignTokens();
|
|
73
80
|
|
|
@@ -93,11 +100,12 @@ export const SettingsStackNavigator: React.FC<SettingsStackNavigatorProps> = ({
|
|
|
93
100
|
appVersion={appVersion}
|
|
94
101
|
showUserProfile={showUserProfile}
|
|
95
102
|
userProfile={userProfile}
|
|
103
|
+
devSettings={devSettings}
|
|
96
104
|
/>
|
|
97
105
|
);
|
|
98
106
|
Wrapper.displayName = "SettingsScreenWrapper";
|
|
99
107
|
return Wrapper;
|
|
100
|
-
}, [config, appVersion, showUserProfile, userProfile]);
|
|
108
|
+
}, [config, appVersion, showUserProfile, userProfile, devSettings]);
|
|
101
109
|
|
|
102
110
|
return (
|
|
103
111
|
<Stack.Navigator screenOptions={screenOptions}>
|
|
@@ -16,6 +16,7 @@ import { SettingsErrorBoundary } from "../components/SettingsErrorBoundary";
|
|
|
16
16
|
import { normalizeSettingsConfig } from "./utils/normalizeConfig";
|
|
17
17
|
import { useFeatureDetection } from "./hooks/useFeatureDetection";
|
|
18
18
|
import type { SettingsConfig, CustomSettingsSection } from "./types";
|
|
19
|
+
import type { DevSettingsProps } from "../components/DevSettingsSection";
|
|
19
20
|
|
|
20
21
|
export interface SettingsScreenProps {
|
|
21
22
|
config?: SettingsConfig;
|
|
@@ -48,6 +49,8 @@ export interface SettingsScreenProps {
|
|
|
48
49
|
featureOptions?: {
|
|
49
50
|
notificationServiceAvailable?: boolean;
|
|
50
51
|
};
|
|
52
|
+
/** Dev settings (only shown in __DEV__ mode) */
|
|
53
|
+
devSettings?: DevSettingsProps;
|
|
51
54
|
}
|
|
52
55
|
|
|
53
56
|
export const SettingsScreen: React.FC<SettingsScreenProps> = ({
|
|
@@ -61,6 +64,7 @@ export const SettingsScreen: React.FC<SettingsScreenProps> = ({
|
|
|
61
64
|
showCloseButton = false,
|
|
62
65
|
onClose,
|
|
63
66
|
featureOptions,
|
|
67
|
+
devSettings,
|
|
64
68
|
}) => {
|
|
65
69
|
const navigation = useNavigation();
|
|
66
70
|
const { themeMode } = useDesignSystemTheme();
|
|
@@ -92,6 +96,7 @@ export const SettingsScreen: React.FC<SettingsScreenProps> = ({
|
|
|
92
96
|
appVersion={appVersion}
|
|
93
97
|
customSections={customSections}
|
|
94
98
|
showCloseButton={showCloseButton}
|
|
99
|
+
devSettings={devSettings}
|
|
95
100
|
/>
|
|
96
101
|
</SettingsErrorBoundary>
|
|
97
102
|
</View>
|
|
@@ -11,6 +11,7 @@ import { useLocalization } from "@umituz/react-native-localization";
|
|
|
11
11
|
import { SettingsFooter } from "../../components/SettingsFooter";
|
|
12
12
|
import { UserProfileHeader } from "../../components/UserProfileHeader";
|
|
13
13
|
import { SettingsSection } from "../../components/SettingsSection";
|
|
14
|
+
import { DevSettingsSection, DevSettingsProps } from "../../components/DevSettingsSection";
|
|
14
15
|
import { NotificationsSection } from "@umituz/react-native-notifications";
|
|
15
16
|
import { AboutSection } from "@umituz/react-native-about";
|
|
16
17
|
import { LegalSection } from "@umituz/react-native-legal";
|
|
@@ -59,6 +60,8 @@ interface SettingsContentProps {
|
|
|
59
60
|
appVersion?: string;
|
|
60
61
|
customSections?: CustomSettingsSection[];
|
|
61
62
|
showCloseButton?: boolean;
|
|
63
|
+
/** Dev settings (only shown in __DEV__ mode) */
|
|
64
|
+
devSettings?: DevSettingsProps;
|
|
62
65
|
}
|
|
63
66
|
|
|
64
67
|
export const SettingsContent: React.FC<SettingsContentProps> = ({
|
|
@@ -72,6 +75,7 @@ export const SettingsContent: React.FC<SettingsContentProps> = ({
|
|
|
72
75
|
appVersion,
|
|
73
76
|
customSections = [],
|
|
74
77
|
showCloseButton = false,
|
|
78
|
+
devSettings,
|
|
75
79
|
}) => {
|
|
76
80
|
const tokens = useAppDesignTokens();
|
|
77
81
|
const insets = useSafeAreaInsets();
|
|
@@ -216,6 +220,16 @@ export const SettingsContent: React.FC<SettingsContentProps> = ({
|
|
|
216
220
|
</View>
|
|
217
221
|
)}
|
|
218
222
|
|
|
223
|
+
{devSettings && (
|
|
224
|
+
<DevSettingsSection
|
|
225
|
+
enabled={devSettings.enabled}
|
|
226
|
+
onAfterClear={devSettings.onAfterClear}
|
|
227
|
+
sectionTitle={devSettings.sectionTitle}
|
|
228
|
+
clearDataTitle={devSettings.clearDataTitle}
|
|
229
|
+
clearDataDescription={devSettings.clearDataDescription}
|
|
230
|
+
/>
|
|
231
|
+
)}
|
|
232
|
+
|
|
219
233
|
{showFooter && <SettingsFooter versionText={footerText} appVersion={appVersion} />}
|
|
220
234
|
</ScrollView>
|
|
221
235
|
);
|