@umituz/react-native-gamification 1.2.1 → 1.4.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.
Files changed (34) hide show
  1. package/LICENSE +5 -0
  2. package/README.md +5 -0
  3. package/package.json +8 -14
  4. package/src/components/AchievementCard.tsx +142 -0
  5. package/src/components/AchievementItem.tsx +182 -0
  6. package/src/components/AchievementToast.tsx +122 -0
  7. package/src/components/GamificationScreen.tsx +236 -0
  8. package/src/components/LevelProgress.tsx +129 -0
  9. package/src/components/PointsBadge.tsx +60 -0
  10. package/src/components/StatsCard.tsx +89 -0
  11. package/src/components/StreakDisplay.tsx +119 -0
  12. package/src/components/index.ts +13 -0
  13. package/src/hooks/useGamification.ts +91 -0
  14. package/src/index.ts +41 -111
  15. package/src/store/gamificationStore.ts +167 -0
  16. package/src/types/index.ts +103 -0
  17. package/src/utils/calculations.ts +85 -0
  18. package/src/domain/entities/Achievement.ts +0 -98
  19. package/src/domain/entities/Leaderboard.ts +0 -101
  20. package/src/domain/entities/Level.ts +0 -40
  21. package/src/domain/entities/Point.ts +0 -40
  22. package/src/domain/entities/Progress.ts +0 -43
  23. package/src/domain/entities/Reward.ts +0 -131
  24. package/src/domain/entities/Streak.ts +0 -154
  25. package/src/domain/repositories/IGamificationRepository.ts +0 -235
  26. package/src/infrastructure/repositories/StorageGamificationRepository.ts +0 -734
  27. package/src/infrastructure/storage/GamificationStore.ts +0 -363
  28. package/src/presentation/hooks/useAchievements.ts +0 -37
  29. package/src/presentation/hooks/useGamification.ts +0 -93
  30. package/src/presentation/hooks/useLevel.ts +0 -39
  31. package/src/presentation/hooks/usePoints.ts +0 -36
  32. package/src/presentation/hooks/useProgress.ts +0 -33
  33. package/src/presentation/hooks/useRewards.ts +0 -43
  34. package/src/presentation/hooks/useStreaks.ts +0 -36
package/LICENSE CHANGED
@@ -22,3 +22,8 @@ SOFTWARE.
22
22
 
23
23
 
24
24
 
25
+
26
+
27
+
28
+
29
+
package/README.md CHANGED
@@ -276,3 +276,8 @@ MIT
276
276
 
277
277
 
278
278
 
279
+
280
+
281
+
282
+
283
+
package/package.json CHANGED
@@ -1,14 +1,12 @@
1
1
  {
2
2
  "name": "@umituz/react-native-gamification",
3
- "version": "1.2.1",
4
- "description": "Comprehensive gamification system for React Native apps with achievements, points, levels, streaks, leaderboards, rewards, and progress tracking",
3
+ "version": "1.4.0",
4
+ "description": "Generic gamification system for React Native apps - achievements, points, levels, streaks with customizable UI components",
5
5
  "main": "./src/index.ts",
6
6
  "types": "./src/index.ts",
7
7
  "scripts": {
8
8
  "typecheck": "tsc --noEmit",
9
- "lint": "tsc --noEmit",
10
- "version:minor": "npm version minor -m 'chore: release v%s'",
11
- "version:major": "npm version major -m 'chore: release v%s'"
9
+ "lint": "tsc --noEmit"
12
10
  },
13
11
  "keywords": [
14
12
  "react-native",
@@ -17,10 +15,8 @@
17
15
  "points",
18
16
  "levels",
19
17
  "streaks",
20
- "leaderboards",
21
- "rewards",
22
18
  "progress",
23
- "gameification"
19
+ "rewards"
24
20
  ],
25
21
  "author": "Ümit UZ <umit@umituz.com>",
26
22
  "license": "MIT",
@@ -29,19 +25,19 @@
29
25
  "url": "https://github.com/umituz/react-native-gamification"
30
26
  },
31
27
  "peerDependencies": {
28
+ "@react-native-async-storage/async-storage": ">=1.21.0",
32
29
  "react": ">=18.2.0",
33
30
  "react-native": ">=0.74.0",
34
- "@umituz/react-native-storage": "latest",
35
31
  "zustand": ">=4.0.0"
36
32
  },
37
33
  "devDependencies": {
34
+ "@react-native-async-storage/async-storage": "^1.23.1",
35
+ "@types/node": "^25.0.2",
38
36
  "@types/react": "^18.2.45",
39
37
  "@types/react-native": "^0.73.0",
40
38
  "react": "^18.2.0",
41
39
  "react-native": "^0.74.0",
42
- "typescript": "^5.3.3"
43
- },
44
- "dependencies": {
40
+ "typescript": "^5.3.3",
45
41
  "zustand": "^4.5.0"
46
42
  },
47
43
  "publishConfig": {
@@ -53,5 +49,3 @@
53
49
  "LICENSE"
54
50
  ]
55
51
  }
56
-
57
-
@@ -0,0 +1,142 @@
1
+ /**
2
+ * AchievementCard Component
3
+ * Displays achievement - all text via props
4
+ */
5
+
6
+ import React from "react";
7
+ import { View, Text, StyleSheet, type ViewStyle, type TextStyle } from "react-native";
8
+
9
+ export interface AchievementCardProps {
10
+ title: string;
11
+ description: string;
12
+ icon: React.ReactNode;
13
+ isUnlocked: boolean;
14
+ progress: number;
15
+ // Customization
16
+ containerStyle?: ViewStyle;
17
+ titleStyle?: TextStyle;
18
+ descriptionStyle?: TextStyle;
19
+ progressBarStyle?: ViewStyle;
20
+ // Colors
21
+ unlockedColor?: string;
22
+ lockedColor?: string;
23
+ backgroundColor?: string;
24
+ textColor?: string;
25
+ subtextColor?: string;
26
+ }
27
+
28
+ export const AchievementCard: React.FC<AchievementCardProps> = ({
29
+ title,
30
+ description,
31
+ icon,
32
+ isUnlocked,
33
+ progress,
34
+ containerStyle,
35
+ titleStyle,
36
+ descriptionStyle,
37
+ progressBarStyle,
38
+ unlockedColor = "#4CAF50",
39
+ lockedColor = "#666666",
40
+ backgroundColor = "#1A1A1A",
41
+ textColor = "#FFFFFF",
42
+ subtextColor = "#888888",
43
+ }) => {
44
+ const accentColor = isUnlocked ? unlockedColor : lockedColor;
45
+
46
+ return (
47
+ <View
48
+ style={[
49
+ styles.container,
50
+ { backgroundColor, borderColor: `${accentColor}40` },
51
+ containerStyle,
52
+ ]}
53
+ >
54
+ <View style={[styles.iconContainer, { backgroundColor: `${accentColor}20` }]}>
55
+ {icon}
56
+ </View>
57
+
58
+ <View style={styles.content}>
59
+ <Text
60
+ style={[
61
+ styles.title,
62
+ { color: isUnlocked ? textColor : subtextColor },
63
+ titleStyle,
64
+ ]}
65
+ >
66
+ {title}
67
+ </Text>
68
+ <Text style={[styles.description, { color: subtextColor }, descriptionStyle]}>
69
+ {description}
70
+ </Text>
71
+
72
+ {!isUnlocked && (
73
+ <View style={[styles.progressBar, { backgroundColor: `${lockedColor}40` }, progressBarStyle]}>
74
+ <View
75
+ style={[
76
+ styles.progressFill,
77
+ { width: `${progress}%`, backgroundColor: accentColor },
78
+ ]}
79
+ />
80
+ </View>
81
+ )}
82
+ </View>
83
+
84
+ {isUnlocked && (
85
+ <View style={[styles.checkmark, { backgroundColor: unlockedColor }]}>
86
+ <Text style={styles.checkmarkText}>✓</Text>
87
+ </View>
88
+ )}
89
+ </View>
90
+ );
91
+ };
92
+
93
+ const styles = StyleSheet.create({
94
+ container: {
95
+ flexDirection: "row",
96
+ alignItems: "center",
97
+ padding: 12,
98
+ borderRadius: 12,
99
+ borderWidth: 1,
100
+ gap: 12,
101
+ },
102
+ iconContainer: {
103
+ width: 48,
104
+ height: 48,
105
+ borderRadius: 24,
106
+ justifyContent: "center",
107
+ alignItems: "center",
108
+ },
109
+ content: {
110
+ flex: 1,
111
+ },
112
+ title: {
113
+ fontSize: 16,
114
+ fontWeight: "600",
115
+ },
116
+ description: {
117
+ fontSize: 13,
118
+ marginTop: 2,
119
+ },
120
+ progressBar: {
121
+ height: 4,
122
+ borderRadius: 2,
123
+ marginTop: 8,
124
+ overflow: "hidden",
125
+ },
126
+ progressFill: {
127
+ height: "100%",
128
+ borderRadius: 2,
129
+ },
130
+ checkmark: {
131
+ width: 24,
132
+ height: 24,
133
+ borderRadius: 12,
134
+ justifyContent: "center",
135
+ alignItems: "center",
136
+ },
137
+ checkmarkText: {
138
+ color: "#FFFFFF",
139
+ fontSize: 14,
140
+ fontWeight: "bold",
141
+ },
142
+ });
@@ -0,0 +1,182 @@
1
+ /**
2
+ * AchievementItem Component
3
+ * List item for achievements - all text via props
4
+ */
5
+
6
+ import React from "react";
7
+ import {
8
+ View,
9
+ Text,
10
+ StyleSheet,
11
+ type ViewStyle,
12
+ type TextStyle,
13
+ } from "react-native";
14
+
15
+ export interface AchievementItemProps {
16
+ title: string;
17
+ description: string;
18
+ icon: React.ReactNode;
19
+ isUnlocked: boolean;
20
+ progress: number;
21
+ threshold: number;
22
+ progressLabel?: string;
23
+ // Customization
24
+ containerStyle?: ViewStyle;
25
+ titleStyle?: TextStyle;
26
+ descriptionStyle?: TextStyle;
27
+ // Colors
28
+ accentColor?: string;
29
+ backgroundColor?: string;
30
+ textColor?: string;
31
+ subtextColor?: string;
32
+ lockedOpacity?: number;
33
+ }
34
+
35
+ export const AchievementItem: React.FC<AchievementItemProps> = ({
36
+ title,
37
+ description,
38
+ icon,
39
+ isUnlocked,
40
+ progress,
41
+ threshold,
42
+ progressLabel,
43
+ containerStyle,
44
+ titleStyle,
45
+ descriptionStyle,
46
+ accentColor = "#FFD700",
47
+ backgroundColor = "#1A1A1A",
48
+ textColor = "#FFFFFF",
49
+ subtextColor = "#888888",
50
+ lockedOpacity = 0.5,
51
+ }) => {
52
+ const progressPercent = Math.min((progress / threshold) * 100, 100);
53
+
54
+ return (
55
+ <View
56
+ style={[
57
+ styles.container,
58
+ { backgroundColor, opacity: isUnlocked ? 1 : lockedOpacity },
59
+ containerStyle,
60
+ ]}
61
+ >
62
+ <View
63
+ style={[styles.iconContainer, { backgroundColor: `${accentColor}20` }]}
64
+ >
65
+ {icon}
66
+ </View>
67
+
68
+ <View style={styles.content}>
69
+ <View style={styles.header}>
70
+ <Text style={[styles.title, { color: textColor }, titleStyle]}>
71
+ {title}
72
+ </Text>
73
+ {isUnlocked && (
74
+ <View style={[styles.checkmark, { backgroundColor: accentColor }]}>
75
+ <Text style={styles.checkmarkText}>✓</Text>
76
+ </View>
77
+ )}
78
+ </View>
79
+
80
+ <Text
81
+ style={[styles.description, { color: subtextColor }, descriptionStyle]}
82
+ numberOfLines={2}
83
+ >
84
+ {description}
85
+ </Text>
86
+
87
+ {!isUnlocked && (
88
+ <View style={styles.progressContainer}>
89
+ <View
90
+ style={[styles.progressBar, { backgroundColor: `${accentColor}30` }]}
91
+ >
92
+ <View
93
+ style={[
94
+ styles.progressFill,
95
+ {
96
+ backgroundColor: accentColor,
97
+ width: `${progressPercent}%`,
98
+ },
99
+ ]}
100
+ />
101
+ </View>
102
+ {progressLabel && (
103
+ <Text style={[styles.progressText, { color: subtextColor }]}>
104
+ {progressLabel}
105
+ </Text>
106
+ )}
107
+ </View>
108
+ )}
109
+ </View>
110
+ </View>
111
+ );
112
+ };
113
+
114
+ const styles = StyleSheet.create({
115
+ container: {
116
+ flexDirection: "row",
117
+ alignItems: "center",
118
+ padding: 12,
119
+ borderRadius: 12,
120
+ marginBottom: 8,
121
+ },
122
+ iconContainer: {
123
+ width: 48,
124
+ height: 48,
125
+ borderRadius: 24,
126
+ alignItems: "center",
127
+ justifyContent: "center",
128
+ marginRight: 12,
129
+ },
130
+ content: {
131
+ flex: 1,
132
+ },
133
+ header: {
134
+ flexDirection: "row",
135
+ alignItems: "center",
136
+ justifyContent: "space-between",
137
+ marginBottom: 4,
138
+ },
139
+ title: {
140
+ fontSize: 16,
141
+ fontWeight: "600",
142
+ flex: 1,
143
+ },
144
+ checkmark: {
145
+ width: 20,
146
+ height: 20,
147
+ borderRadius: 10,
148
+ alignItems: "center",
149
+ justifyContent: "center",
150
+ marginLeft: 8,
151
+ },
152
+ checkmarkText: {
153
+ color: "#000",
154
+ fontSize: 12,
155
+ fontWeight: "bold",
156
+ },
157
+ description: {
158
+ fontSize: 13,
159
+ lineHeight: 18,
160
+ },
161
+ progressContainer: {
162
+ marginTop: 8,
163
+ flexDirection: "row",
164
+ alignItems: "center",
165
+ gap: 8,
166
+ },
167
+ progressBar: {
168
+ flex: 1,
169
+ height: 4,
170
+ borderRadius: 2,
171
+ overflow: "hidden",
172
+ },
173
+ progressFill: {
174
+ height: "100%",
175
+ borderRadius: 2,
176
+ },
177
+ progressText: {
178
+ fontSize: 11,
179
+ minWidth: 40,
180
+ textAlign: "right",
181
+ },
182
+ });
@@ -0,0 +1,122 @@
1
+ /**
2
+ * AchievementToast Component
3
+ * Shows achievement unlock notification - all text via props
4
+ */
5
+
6
+ import React, { useEffect, useRef } from "react";
7
+ import { View, Text, StyleSheet, Animated, type ViewStyle, type TextStyle } from "react-native";
8
+
9
+ export interface AchievementToastProps {
10
+ visible: boolean;
11
+ title: string;
12
+ label: string; // e.g., "Achievement Unlocked!" - from app translations
13
+ icon: React.ReactNode;
14
+ onDismiss: () => void;
15
+ duration?: number;
16
+ // Customization
17
+ containerStyle?: ViewStyle;
18
+ labelStyle?: TextStyle;
19
+ titleStyle?: TextStyle;
20
+ // Colors
21
+ backgroundColor?: string;
22
+ textColor?: string;
23
+ labelColor?: string;
24
+ }
25
+
26
+ export const AchievementToast: React.FC<AchievementToastProps> = ({
27
+ visible,
28
+ title,
29
+ label,
30
+ icon,
31
+ onDismiss,
32
+ duration = 3000,
33
+ containerStyle,
34
+ labelStyle,
35
+ titleStyle,
36
+ backgroundColor = "#FFD700",
37
+ textColor = "#000000",
38
+ labelColor = "#00000080",
39
+ }) => {
40
+ const translateY = useRef(new Animated.Value(-100)).current;
41
+
42
+ useEffect(() => {
43
+ if (visible) {
44
+ Animated.sequence([
45
+ Animated.timing(translateY, {
46
+ toValue: 0,
47
+ duration: 400,
48
+ useNativeDriver: true,
49
+ }),
50
+ Animated.delay(duration),
51
+ Animated.timing(translateY, {
52
+ toValue: -100,
53
+ duration: 300,
54
+ useNativeDriver: true,
55
+ }),
56
+ ]).start(() => {
57
+ onDismiss();
58
+ });
59
+ }
60
+ }, [visible, duration, onDismiss, translateY]);
61
+
62
+ if (!visible) return null;
63
+
64
+ return (
65
+ <Animated.View
66
+ style={[
67
+ styles.container,
68
+ { transform: [{ translateY }] },
69
+ containerStyle,
70
+ ]}
71
+ >
72
+ <View style={[styles.toast, { backgroundColor }]}>
73
+ <View style={styles.iconContainer}>{icon}</View>
74
+ <View style={styles.content}>
75
+ <Text style={[styles.label, { color: labelColor }, labelStyle]}>
76
+ {label}
77
+ </Text>
78
+ <Text style={[styles.title, { color: textColor }, titleStyle]}>
79
+ {title}
80
+ </Text>
81
+ </View>
82
+ </View>
83
+ </Animated.View>
84
+ );
85
+ };
86
+
87
+ const styles = StyleSheet.create({
88
+ container: {
89
+ position: "absolute",
90
+ top: 60,
91
+ left: 16,
92
+ right: 16,
93
+ zIndex: 1000,
94
+ },
95
+ toast: {
96
+ flexDirection: "row",
97
+ alignItems: "center",
98
+ padding: 16,
99
+ borderRadius: 16,
100
+ gap: 12,
101
+ },
102
+ iconContainer: {
103
+ width: 40,
104
+ height: 40,
105
+ justifyContent: "center",
106
+ alignItems: "center",
107
+ },
108
+ content: {
109
+ flex: 1,
110
+ },
111
+ label: {
112
+ fontSize: 12,
113
+ fontWeight: "bold",
114
+ textTransform: "uppercase",
115
+ letterSpacing: 1,
116
+ },
117
+ title: {
118
+ fontSize: 16,
119
+ fontWeight: "600",
120
+ marginTop: 2,
121
+ },
122
+ });