@umituz/react-native-settings 1.10.2 → 1.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 +1 -1
- package/src/index.ts +6 -0
- package/src/presentation/components/CloudSyncSetting.tsx +65 -0
- package/src/presentation/components/SettingItem.tsx +11 -3
- package/src/presentation/components/StorageClearSetting.tsx +45 -0
- package/src/presentation/components/UserProfileHeader.tsx +44 -30
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -61,3 +61,9 @@ export type { UserProfileHeaderProps } from './presentation/components/UserProfi
|
|
|
61
61
|
|
|
62
62
|
export { DisclaimerSetting } from './presentation/components/DisclaimerSetting';
|
|
63
63
|
|
|
64
|
+
export { CloudSyncSetting } from './presentation/components/CloudSyncSetting';
|
|
65
|
+
export type { CloudSyncSettingProps } from './presentation/components/CloudSyncSetting';
|
|
66
|
+
|
|
67
|
+
export { StorageClearSetting } from './presentation/components/StorageClearSetting';
|
|
68
|
+
export type { StorageClearSettingProps } from './presentation/components/StorageClearSetting';
|
|
69
|
+
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cloud Sync Setting Component
|
|
3
|
+
* Single Responsibility: Display cloud sync setting item
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import React from "react";
|
|
7
|
+
import { Cloud } from "lucide-react-native";
|
|
8
|
+
import { SettingItem } from "./SettingItem";
|
|
9
|
+
import type { SettingItemProps } from "./SettingItem";
|
|
10
|
+
|
|
11
|
+
export interface CloudSyncSettingProps {
|
|
12
|
+
title?: string;
|
|
13
|
+
description?: string;
|
|
14
|
+
isSyncing?: boolean;
|
|
15
|
+
lastSynced?: Date | null;
|
|
16
|
+
onPress?: () => void;
|
|
17
|
+
iconColor?: string;
|
|
18
|
+
titleColor?: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const CloudSyncSetting: React.FC<CloudSyncSettingProps> = ({
|
|
22
|
+
title = "Cloud Sync",
|
|
23
|
+
description,
|
|
24
|
+
isSyncing = false,
|
|
25
|
+
lastSynced,
|
|
26
|
+
onPress,
|
|
27
|
+
iconColor,
|
|
28
|
+
titleColor,
|
|
29
|
+
}) => {
|
|
30
|
+
const formatLastSynced = (date: Date | null | undefined): string => {
|
|
31
|
+
if (!date) return "Never synced";
|
|
32
|
+
const now = new Date();
|
|
33
|
+
const diff = now.getTime() - date.getTime();
|
|
34
|
+
const minutes = Math.floor(diff / 60000);
|
|
35
|
+
const hours = Math.floor(minutes / 60);
|
|
36
|
+
const days = Math.floor(hours / 24);
|
|
37
|
+
|
|
38
|
+
if (minutes < 1) return "Just now";
|
|
39
|
+
if (minutes < 60) return `${minutes}m ago`;
|
|
40
|
+
if (hours < 24) return `${hours}h ago`;
|
|
41
|
+
if (days < 7) return `${days}d ago`;
|
|
42
|
+
return date.toLocaleDateString();
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const displayDescription =
|
|
46
|
+
description ||
|
|
47
|
+
(isSyncing
|
|
48
|
+
? "Syncing..."
|
|
49
|
+
: lastSynced
|
|
50
|
+
? `Last synced: ${formatLastSynced(lastSynced)}`
|
|
51
|
+
: "Sync your data to the cloud");
|
|
52
|
+
|
|
53
|
+
return (
|
|
54
|
+
<SettingItem
|
|
55
|
+
icon={Cloud}
|
|
56
|
+
title={title}
|
|
57
|
+
value={displayDescription}
|
|
58
|
+
onPress={onPress}
|
|
59
|
+
iconColor={iconColor}
|
|
60
|
+
titleColor={titleColor}
|
|
61
|
+
disabled={isSyncing}
|
|
62
|
+
/>
|
|
63
|
+
);
|
|
64
|
+
};
|
|
65
|
+
|
|
@@ -32,6 +32,8 @@ export interface SettingItemProps {
|
|
|
32
32
|
titleColor?: string;
|
|
33
33
|
/** Test ID for E2E testing */
|
|
34
34
|
testID?: string;
|
|
35
|
+
/** Disable the item */
|
|
36
|
+
disabled?: boolean;
|
|
35
37
|
}
|
|
36
38
|
|
|
37
39
|
export const SettingItem: React.FC<SettingItemProps> = ({
|
|
@@ -46,6 +48,7 @@ export const SettingItem: React.FC<SettingItemProps> = ({
|
|
|
46
48
|
iconColor,
|
|
47
49
|
titleColor,
|
|
48
50
|
testID,
|
|
51
|
+
disabled = false,
|
|
49
52
|
}) => {
|
|
50
53
|
const tokens = useAppDesignTokens();
|
|
51
54
|
const colors = tokens.colors;
|
|
@@ -59,8 +62,8 @@ export const SettingItem: React.FC<SettingItemProps> = ({
|
|
|
59
62
|
{ backgroundColor: colors.backgroundPrimary },
|
|
60
63
|
]}
|
|
61
64
|
onPress={onPress}
|
|
62
|
-
disabled={showSwitch}
|
|
63
|
-
activeOpacity={0.7}
|
|
65
|
+
disabled={showSwitch || disabled}
|
|
66
|
+
activeOpacity={disabled ? 1 : 0.7}
|
|
64
67
|
testID={testID}
|
|
65
68
|
>
|
|
66
69
|
<View style={styles.content}>
|
|
@@ -80,7 +83,12 @@ export const SettingItem: React.FC<SettingItemProps> = ({
|
|
|
80
83
|
<Text
|
|
81
84
|
style={[
|
|
82
85
|
styles.title,
|
|
83
|
-
{
|
|
86
|
+
{
|
|
87
|
+
color: disabled
|
|
88
|
+
? colors.textSecondary
|
|
89
|
+
: titleColor || colors.textPrimary,
|
|
90
|
+
opacity: disabled ? 0.5 : 1,
|
|
91
|
+
},
|
|
84
92
|
]}
|
|
85
93
|
numberOfLines={1}
|
|
86
94
|
>
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Storage Clear Setting Component
|
|
3
|
+
* Single Responsibility: Display storage clear setting (DEV only)
|
|
4
|
+
* Only visible in __DEV__ mode
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import React from "react";
|
|
8
|
+
import { Trash2 } from "lucide-react-native";
|
|
9
|
+
import { SettingItem } from "./SettingItem";
|
|
10
|
+
|
|
11
|
+
export interface StorageClearSettingProps {
|
|
12
|
+
title?: string;
|
|
13
|
+
description?: string;
|
|
14
|
+
onPress?: () => void;
|
|
15
|
+
iconColor?: string;
|
|
16
|
+
titleColor?: string;
|
|
17
|
+
isLast?: boolean;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const StorageClearSetting: React.FC<StorageClearSettingProps> = ({
|
|
21
|
+
title = "Clear All Storage",
|
|
22
|
+
description = "Clear all local storage data (DEV only)",
|
|
23
|
+
onPress,
|
|
24
|
+
iconColor = "#EF4444",
|
|
25
|
+
titleColor = "#EF4444",
|
|
26
|
+
isLast = false,
|
|
27
|
+
}) => {
|
|
28
|
+
// Only render in DEV mode
|
|
29
|
+
if (!__DEV__) {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return (
|
|
34
|
+
<SettingItem
|
|
35
|
+
icon={Trash2}
|
|
36
|
+
title={title}
|
|
37
|
+
value={description}
|
|
38
|
+
onPress={onPress}
|
|
39
|
+
iconColor={iconColor}
|
|
40
|
+
titleColor={titleColor}
|
|
41
|
+
isLast={isLast}
|
|
42
|
+
/>
|
|
43
|
+
);
|
|
44
|
+
};
|
|
45
|
+
|
|
@@ -5,9 +5,10 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import React from "react";
|
|
8
|
-
import { View,
|
|
8
|
+
import { View, TouchableOpacity, StyleSheet, Image } from "react-native";
|
|
9
9
|
import { ChevronRight } from "lucide-react-native";
|
|
10
10
|
import { useAppDesignTokens } from "@umituz/react-native-design-system-theme";
|
|
11
|
+
import { AtomicText } from "@umituz/react-native-design-system-atoms";
|
|
11
12
|
import { useNavigation } from "@react-navigation/native";
|
|
12
13
|
|
|
13
14
|
export interface UserProfileHeaderProps {
|
|
@@ -58,34 +59,42 @@ export const UserProfileHeader: React.FC<UserProfileHeaderProps> = ({
|
|
|
58
59
|
style={[
|
|
59
60
|
styles.container,
|
|
60
61
|
{
|
|
61
|
-
backgroundColor: colors.
|
|
62
|
-
|
|
62
|
+
backgroundColor: colors.surface,
|
|
63
|
+
paddingHorizontal: spacing.md,
|
|
64
|
+
paddingVertical: spacing.md,
|
|
65
|
+
marginHorizontal: spacing.md,
|
|
63
66
|
},
|
|
64
67
|
]}
|
|
65
68
|
onPress={handlePress}
|
|
66
69
|
activeOpacity={0.7}
|
|
67
70
|
>
|
|
68
71
|
<View style={styles.content}>
|
|
69
|
-
<
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
72
|
+
<View style={[styles.avatarContainer, { borderColor: `${colors.primary}30` }]}>
|
|
73
|
+
<Image
|
|
74
|
+
source={{ uri: finalAvatarUrl }}
|
|
75
|
+
style={styles.avatar}
|
|
76
|
+
/>
|
|
77
|
+
</View>
|
|
78
|
+
<View style={[styles.textContainer, { marginLeft: spacing.md }]}>
|
|
79
|
+
<AtomicText
|
|
80
|
+
type="headlineSmall"
|
|
81
|
+
style={[styles.name, { color: colors.textPrimary, marginBottom: spacing.xs }]}
|
|
76
82
|
numberOfLines={1}
|
|
77
83
|
>
|
|
78
84
|
{finalDisplayName}
|
|
79
|
-
</
|
|
80
|
-
<
|
|
85
|
+
</AtomicText>
|
|
86
|
+
<AtomicText
|
|
87
|
+
type="bodySmall"
|
|
81
88
|
style={[styles.id, { color: colors.textSecondary }]}
|
|
82
89
|
numberOfLines={1}
|
|
83
90
|
>
|
|
84
|
-
ID: {finalUserId.substring(0,
|
|
85
|
-
</
|
|
91
|
+
ID: {finalUserId.substring(0, 10)}...
|
|
92
|
+
</AtomicText>
|
|
86
93
|
</View>
|
|
87
94
|
</View>
|
|
88
|
-
<
|
|
95
|
+
<View style={[styles.chevronContainer, { marginLeft: spacing.sm }]}>
|
|
96
|
+
<ChevronRight size={22} color={colors.textSecondary} strokeWidth={2.5} />
|
|
97
|
+
</View>
|
|
89
98
|
</TouchableOpacity>
|
|
90
99
|
);
|
|
91
100
|
};
|
|
@@ -95,37 +104,42 @@ const styles = StyleSheet.create({
|
|
|
95
104
|
flexDirection: "row",
|
|
96
105
|
alignItems: "center",
|
|
97
106
|
justifyContent: "space-between",
|
|
98
|
-
paddingHorizontal: 20,
|
|
99
|
-
paddingVertical: 20,
|
|
100
|
-
marginHorizontal: 16,
|
|
101
107
|
marginTop: 0,
|
|
102
108
|
marginBottom: 0,
|
|
103
|
-
borderRadius:
|
|
104
|
-
|
|
109
|
+
borderRadius: 20,
|
|
110
|
+
minHeight: 80,
|
|
105
111
|
},
|
|
106
112
|
content: {
|
|
107
113
|
flexDirection: "row",
|
|
108
114
|
alignItems: "center",
|
|
109
115
|
flex: 1,
|
|
110
116
|
},
|
|
117
|
+
avatarContainer: {
|
|
118
|
+
width: 64,
|
|
119
|
+
height: 64,
|
|
120
|
+
borderRadius: 32,
|
|
121
|
+
borderWidth: 2,
|
|
122
|
+
overflow: "hidden",
|
|
123
|
+
backgroundColor: "transparent",
|
|
124
|
+
},
|
|
111
125
|
avatar: {
|
|
112
|
-
width:
|
|
113
|
-
height:
|
|
114
|
-
borderRadius: 28,
|
|
115
|
-
borderWidth: 2.5,
|
|
126
|
+
width: "100%",
|
|
127
|
+
height: "100%",
|
|
116
128
|
},
|
|
117
129
|
textContainer: {
|
|
118
|
-
marginLeft: 16,
|
|
119
130
|
flex: 1,
|
|
120
131
|
},
|
|
121
132
|
name: {
|
|
122
|
-
|
|
123
|
-
fontWeight: "600",
|
|
124
|
-
marginBottom: 4,
|
|
133
|
+
fontWeight: "700",
|
|
125
134
|
},
|
|
126
135
|
id: {
|
|
127
|
-
|
|
128
|
-
|
|
136
|
+
fontWeight: "500",
|
|
137
|
+
opacity: 0.7,
|
|
138
|
+
},
|
|
139
|
+
chevronContainer: {
|
|
140
|
+
justifyContent: "center",
|
|
141
|
+
alignItems: "center",
|
|
129
142
|
},
|
|
130
143
|
});
|
|
131
144
|
|
|
145
|
+
|