mixpanel-react-native 3.1.2 → 3.2.0-beta.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 (93) hide show
  1. package/.claude/settings.local.json +12 -1
  2. package/.github/dependabot.yml +7 -0
  3. package/.github/workflows/node.js.yml +24 -1
  4. package/.vscode/settings.json +2 -1
  5. package/MixpanelReactNative.podspec +1 -1
  6. package/Samples/MixpanelExample/ios/MixpanelExample.xcworkspace/contents.xcworkspacedata +10 -0
  7. package/Samples/MixpanelExample/ios/Podfile.lock +1996 -0
  8. package/Samples/MixpanelStarter/.bundle/config +2 -0
  9. package/Samples/MixpanelStarter/.env.example +4 -0
  10. package/Samples/MixpanelStarter/.eslintrc.js +4 -0
  11. package/Samples/MixpanelStarter/.prettierrc.js +5 -0
  12. package/Samples/MixpanelStarter/.watchmanconfig +1 -0
  13. package/Samples/MixpanelStarter/App.tsx +10 -0
  14. package/Samples/MixpanelStarter/CLAUDE.md +538 -0
  15. package/Samples/MixpanelStarter/Gemfile +16 -0
  16. package/Samples/MixpanelStarter/INTEGRATION_GUIDE.md +606 -0
  17. package/Samples/MixpanelStarter/README.md +406 -0
  18. package/Samples/MixpanelStarter/__tests__/MixpanelContext.test.tsx +63 -0
  19. package/Samples/MixpanelStarter/android/app/build.gradle +119 -0
  20. package/Samples/MixpanelStarter/android/app/debug.keystore +0 -0
  21. package/Samples/MixpanelStarter/android/app/proguard-rules.pro +10 -0
  22. package/Samples/MixpanelStarter/android/app/src/main/AndroidManifest.xml +27 -0
  23. package/Samples/MixpanelStarter/android/app/src/main/java/com/mixpanelstarter/MainActivity.kt +22 -0
  24. package/Samples/MixpanelStarter/android/app/src/main/java/com/mixpanelstarter/MainApplication.kt +27 -0
  25. package/Samples/MixpanelStarter/android/app/src/main/res/drawable/rn_edit_text_material.xml +37 -0
  26. package/Samples/MixpanelStarter/android/app/src/main/res/mipmap-hdpi/ic_launcher.png +0 -0
  27. package/Samples/MixpanelStarter/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png +0 -0
  28. package/Samples/MixpanelStarter/android/app/src/main/res/mipmap-mdpi/ic_launcher.png +0 -0
  29. package/Samples/MixpanelStarter/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png +0 -0
  30. package/Samples/MixpanelStarter/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png +0 -0
  31. package/Samples/MixpanelStarter/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png +0 -0
  32. package/Samples/MixpanelStarter/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png +0 -0
  33. package/Samples/MixpanelStarter/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png +0 -0
  34. package/Samples/MixpanelStarter/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png +0 -0
  35. package/Samples/MixpanelStarter/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png +0 -0
  36. package/Samples/MixpanelStarter/android/app/src/main/res/values/strings.xml +3 -0
  37. package/Samples/MixpanelStarter/android/app/src/main/res/values/styles.xml +9 -0
  38. package/Samples/MixpanelStarter/android/build.gradle +21 -0
  39. package/Samples/MixpanelStarter/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  40. package/Samples/MixpanelStarter/android/gradle/wrapper/gradle-wrapper.properties +7 -0
  41. package/Samples/MixpanelStarter/android/gradle.properties +44 -0
  42. package/Samples/MixpanelStarter/android/gradlew +251 -0
  43. package/Samples/MixpanelStarter/android/gradlew.bat +99 -0
  44. package/Samples/MixpanelStarter/android/settings.gradle +6 -0
  45. package/Samples/MixpanelStarter/app.json +4 -0
  46. package/Samples/MixpanelStarter/babel.config.js +14 -0
  47. package/Samples/MixpanelStarter/index.js +9 -0
  48. package/Samples/MixpanelStarter/ios/.xcode.env +11 -0
  49. package/Samples/MixpanelStarter/ios/MixpanelStarter/AppDelegate.swift +48 -0
  50. package/Samples/MixpanelStarter/ios/MixpanelStarter/Images.xcassets/AppIcon.appiconset/Contents.json +53 -0
  51. package/Samples/MixpanelStarter/ios/MixpanelStarter/Images.xcassets/Contents.json +6 -0
  52. package/Samples/MixpanelStarter/ios/MixpanelStarter/Info.plist +55 -0
  53. package/Samples/MixpanelStarter/ios/MixpanelStarter/LaunchScreen.storyboard +47 -0
  54. package/Samples/MixpanelStarter/ios/MixpanelStarter/PrivacyInfo.xcprivacy +38 -0
  55. package/Samples/MixpanelStarter/ios/MixpanelStarter.xcodeproj/project.pbxproj +482 -0
  56. package/Samples/MixpanelStarter/ios/MixpanelStarter.xcodeproj/xcshareddata/xcschemes/MixpanelStarter.xcscheme +88 -0
  57. package/Samples/MixpanelStarter/ios/MixpanelStarter.xcworkspace/contents.xcworkspacedata +10 -0
  58. package/Samples/MixpanelStarter/ios/Podfile +34 -0
  59. package/Samples/MixpanelStarter/ios/Podfile.lock +2839 -0
  60. package/Samples/MixpanelStarter/jest.config.js +3 -0
  61. package/Samples/MixpanelStarter/metro.config.js +42 -0
  62. package/Samples/MixpanelStarter/package-lock.json +12141 -0
  63. package/Samples/MixpanelStarter/package.json +51 -0
  64. package/Samples/MixpanelStarter/src/@types/env.d.ts +3 -0
  65. package/Samples/MixpanelStarter/src/App.tsx +83 -0
  66. package/Samples/MixpanelStarter/src/components/ActionButton.tsx +92 -0
  67. package/Samples/MixpanelStarter/src/components/ErrorBoundary.tsx +81 -0
  68. package/Samples/MixpanelStarter/src/components/EventTrackingLog.tsx +163 -0
  69. package/Samples/MixpanelStarter/src/components/FlagCard.tsx +199 -0
  70. package/Samples/MixpanelStarter/src/components/InfoCard.tsx +77 -0
  71. package/Samples/MixpanelStarter/src/components/TestResultDisplay.tsx +181 -0
  72. package/Samples/MixpanelStarter/src/constants/tracking.ts +77 -0
  73. package/Samples/MixpanelStarter/src/contexts/MixpanelContext.tsx +159 -0
  74. package/Samples/MixpanelStarter/src/screens/FeatureFlagsScreen.tsx +1011 -0
  75. package/Samples/MixpanelStarter/src/screens/HomeScreen.tsx +307 -0
  76. package/Samples/MixpanelStarter/src/screens/OnboardingScreen.tsx +253 -0
  77. package/Samples/MixpanelStarter/src/screens/SettingsScreen.tsx +316 -0
  78. package/Samples/MixpanelStarter/src/types/flags.types.ts +42 -0
  79. package/Samples/MixpanelStarter/src/types/mixpanel.types.ts +26 -0
  80. package/Samples/MixpanelStarter/tsconfig.json +13 -0
  81. package/__tests__/flags.test.js +730 -0
  82. package/__tests__/index.test.js +7 -3
  83. package/__tests__/jest_setup.js +18 -0
  84. package/android/build.gradle +1 -1
  85. package/android/src/main/java/com/mixpanel/reactnative/MixpanelReactNativeModule.java +272 -2
  86. package/index.d.ts +64 -1
  87. package/index.js +42 -3
  88. package/ios/MixpanelReactNative.m +19 -1
  89. package/ios/MixpanelReactNative.swift +183 -5
  90. package/javascript/mixpanel-flags-js.js +463 -0
  91. package/javascript/mixpanel-flags.js +290 -0
  92. package/javascript/mixpanel-main.js +13 -1
  93. package/package.json +2 -2
@@ -0,0 +1,51 @@
1
+ {
2
+ "name": "MixpanelStarter",
3
+ "version": "0.0.1",
4
+ "private": true,
5
+ "scripts": {
6
+ "android": "react-native run-android",
7
+ "ios": "react-native run-ios",
8
+ "lint": "eslint .",
9
+ "start": "react-native start",
10
+ "test": "jest"
11
+ },
12
+ "dependencies": {
13
+ "react": "19.1.1",
14
+ "react-native": "0.82.1",
15
+ "@react-native/new-app-screen": "0.82.1",
16
+ "react-native-safe-area-context": "^5.5.2",
17
+ "mixpanel-react-native": "file:../..",
18
+ "@react-native-async-storage/async-storage": "^2.1.0",
19
+ "@react-navigation/native": "^7.0.20",
20
+ "@react-navigation/bottom-tabs": "^7.2.8",
21
+ "react-native-screens": "^4.5.0",
22
+ "react-native-dotenv": "^3.4.11",
23
+ "react-native-get-random-values": "^1.9.0",
24
+ "uuid": "^9.0.0"
25
+ },
26
+ "devDependencies": {
27
+ "@babel/core": "^7.25.2",
28
+ "@babel/preset-env": "^7.25.3",
29
+ "@babel/runtime": "^7.25.0",
30
+ "@react-native-community/cli": "20.0.0",
31
+ "@react-native-community/cli-platform-android": "20.0.0",
32
+ "@react-native-community/cli-platform-ios": "20.0.0",
33
+ "@react-native/babel-preset": "0.82.1",
34
+ "@react-native/eslint-config": "0.82.1",
35
+ "@react-native/metro-config": "0.82.1",
36
+ "@react-native/typescript-config": "0.82.1",
37
+ "@types/jest": "^29.5.13",
38
+ "@types/react": "^19.1.1",
39
+ "@types/react-test-renderer": "^19.1.0",
40
+ "@testing-library/react-native": "^12.8.1",
41
+ "@testing-library/jest-native": "^5.4.3",
42
+ "eslint": "^8.19.0",
43
+ "jest": "^29.6.3",
44
+ "prettier": "2.8.8",
45
+ "react-test-renderer": "19.1.1",
46
+ "typescript": "^5.8.3"
47
+ },
48
+ "engines": {
49
+ "node": ">=20"
50
+ }
51
+ }
@@ -0,0 +1,3 @@
1
+ declare module '@env' {
2
+ export const MIXPANEL_TOKEN: string;
3
+ }
@@ -0,0 +1,83 @@
1
+ import React from 'react';
2
+ import {NavigationContainer} from '@react-navigation/native';
3
+ import {createBottomTabNavigator} from '@react-navigation/bottom-tabs';
4
+ import {Text} from 'react-native';
5
+ import {MixpanelProvider} from './contexts/MixpanelContext';
6
+ import {ErrorBoundary} from './components/ErrorBoundary';
7
+ import {OnboardingScreen} from './screens/OnboardingScreen';
8
+ import {HomeScreen} from './screens/HomeScreen';
9
+ import {FeatureFlagsScreen} from './screens/FeatureFlagsScreen';
10
+ import {SettingsScreen} from './screens/SettingsScreen';
11
+ import {MIXPANEL_TOKEN} from '@env';
12
+
13
+ const Tab = createBottomTabNavigator();
14
+
15
+ // Fallback token for demo purposes (use your own from Mixpanel dashboard)
16
+ const DEMO_TOKEN = 'YOUR_TOKEN_HERE';
17
+ const token = MIXPANEL_TOKEN || DEMO_TOKEN;
18
+
19
+ function App(): React.JSX.Element {
20
+ return (
21
+ <ErrorBoundary>
22
+ <MixpanelProvider token={token} trackAutomaticEvents={true} useNative={true}>
23
+ <NavigationContainer>
24
+ <Tab.Navigator
25
+ screenOptions={{
26
+ tabBarActiveTintColor: '#007AFF',
27
+ tabBarInactiveTintColor: '#8E8E93',
28
+ headerStyle: {
29
+ backgroundColor: '#F2F2F7',
30
+ },
31
+ headerTintColor: '#000',
32
+ headerTitleStyle: {
33
+ fontWeight: '600',
34
+ },
35
+ }}>
36
+ <Tab.Screen
37
+ name="Onboarding"
38
+ component={OnboardingScreen}
39
+ options={{
40
+ tabBarLabel: 'User ID',
41
+ tabBarIcon: ({color}) => (
42
+ <Text style={{fontSize: 20, color}}>👤</Text>
43
+ ),
44
+ }}
45
+ />
46
+ <Tab.Screen
47
+ name="Home"
48
+ component={HomeScreen}
49
+ options={{
50
+ tabBarLabel: 'Events',
51
+ tabBarIcon: ({color}) => (
52
+ <Text style={{fontSize: 20, color}}>📊</Text>
53
+ ),
54
+ }}
55
+ />
56
+ <Tab.Screen
57
+ name="FeatureFlags"
58
+ component={FeatureFlagsScreen}
59
+ options={{
60
+ tabBarLabel: 'Flags',
61
+ tabBarIcon: ({color}) => (
62
+ <Text style={{fontSize: 20, color}}>🚩</Text>
63
+ ),
64
+ }}
65
+ />
66
+ <Tab.Screen
67
+ name="Settings"
68
+ component={SettingsScreen}
69
+ options={{
70
+ tabBarLabel: 'Settings',
71
+ tabBarIcon: ({color}) => (
72
+ <Text style={{fontSize: 20, color}}>⚙️</Text>
73
+ ),
74
+ }}
75
+ />
76
+ </Tab.Navigator>
77
+ </NavigationContainer>
78
+ </MixpanelProvider>
79
+ </ErrorBoundary>
80
+ );
81
+ }
82
+
83
+ export default App;
@@ -0,0 +1,92 @@
1
+ import React from 'react';
2
+ import {
3
+ TouchableOpacity,
4
+ Text,
5
+ StyleSheet,
6
+ ActivityIndicator,
7
+ ViewStyle,
8
+ TextStyle,
9
+ } from 'react-native';
10
+
11
+ interface ActionButtonProps {
12
+ title: string;
13
+ onPress: () => void;
14
+ variant?: 'primary' | 'secondary' | 'danger';
15
+ disabled?: boolean;
16
+ loading?: boolean;
17
+ style?: ViewStyle;
18
+ textStyle?: TextStyle;
19
+ }
20
+
21
+ export const ActionButton: React.FC<ActionButtonProps> = ({
22
+ title,
23
+ onPress,
24
+ variant = 'primary',
25
+ disabled = false,
26
+ loading = false,
27
+ style,
28
+ textStyle,
29
+ }) => {
30
+ const isDisabled = disabled || loading;
31
+
32
+ return (
33
+ <TouchableOpacity
34
+ style={[
35
+ styles.button,
36
+ styles[variant],
37
+ isDisabled && styles.disabled,
38
+ style,
39
+ ]}
40
+ onPress={onPress}
41
+ disabled={isDisabled}
42
+ activeOpacity={0.7}>
43
+ {loading ? (
44
+ <ActivityIndicator
45
+ color={variant === 'secondary' ? '#007AFF' : '#fff'}
46
+ />
47
+ ) : (
48
+ <Text style={[styles.text, styles[`${variant}Text`], textStyle]}>
49
+ {title}
50
+ </Text>
51
+ )}
52
+ </TouchableOpacity>
53
+ );
54
+ };
55
+
56
+ const styles = StyleSheet.create({
57
+ button: {
58
+ paddingHorizontal: 20,
59
+ paddingVertical: 12,
60
+ borderRadius: 8,
61
+ alignItems: 'center',
62
+ justifyContent: 'center',
63
+ minHeight: 44,
64
+ },
65
+ primary: {
66
+ backgroundColor: '#007AFF',
67
+ },
68
+ secondary: {
69
+ backgroundColor: '#f0f0f0',
70
+ borderWidth: 1,
71
+ borderColor: '#ccc',
72
+ },
73
+ danger: {
74
+ backgroundColor: '#FF3B30',
75
+ },
76
+ disabled: {
77
+ opacity: 0.5,
78
+ },
79
+ text: {
80
+ fontSize: 16,
81
+ fontWeight: '600',
82
+ },
83
+ primaryText: {
84
+ color: '#fff',
85
+ },
86
+ secondaryText: {
87
+ color: '#007AFF',
88
+ },
89
+ dangerText: {
90
+ color: '#fff',
91
+ },
92
+ });
@@ -0,0 +1,81 @@
1
+ import React, {Component, ErrorInfo, ReactNode} from 'react';
2
+ import {View, Text, StyleSheet, TouchableOpacity} from 'react-native';
3
+
4
+ interface Props {
5
+ children: ReactNode;
6
+ }
7
+
8
+ interface State {
9
+ hasError: boolean;
10
+ error: Error | null;
11
+ }
12
+
13
+ export class ErrorBoundary extends Component<Props, State> {
14
+ constructor(props: Props) {
15
+ super(props);
16
+ this.state = {hasError: false, error: null};
17
+ }
18
+
19
+ static getDerivedStateFromError(error: Error): State {
20
+ return {hasError: true, error};
21
+ }
22
+
23
+ componentDidCatch(error: Error, errorInfo: ErrorInfo) {
24
+ console.error('ErrorBoundary caught an error:', error, errorInfo);
25
+ }
26
+
27
+ handleReset = () => {
28
+ this.setState({hasError: false, error: null});
29
+ };
30
+
31
+ render() {
32
+ if (this.state.hasError) {
33
+ return (
34
+ <View style={styles.container}>
35
+ <Text style={styles.title}>Oops! Something went wrong</Text>
36
+ <Text style={styles.message}>
37
+ {this.state.error?.message || 'Unknown error'}
38
+ </Text>
39
+ <TouchableOpacity style={styles.button} onPress={this.handleReset}>
40
+ <Text style={styles.buttonText}>Try Again</Text>
41
+ </TouchableOpacity>
42
+ </View>
43
+ );
44
+ }
45
+
46
+ return this.props.children;
47
+ }
48
+ }
49
+
50
+ const styles = StyleSheet.create({
51
+ container: {
52
+ flex: 1,
53
+ justifyContent: 'center',
54
+ alignItems: 'center',
55
+ padding: 20,
56
+ backgroundColor: '#fff',
57
+ },
58
+ title: {
59
+ fontSize: 24,
60
+ fontWeight: 'bold',
61
+ marginBottom: 10,
62
+ color: '#333',
63
+ },
64
+ message: {
65
+ fontSize: 16,
66
+ color: '#666',
67
+ textAlign: 'center',
68
+ marginBottom: 20,
69
+ },
70
+ button: {
71
+ backgroundColor: '#007AFF',
72
+ paddingHorizontal: 20,
73
+ paddingVertical: 10,
74
+ borderRadius: 8,
75
+ },
76
+ buttonText: {
77
+ color: '#fff',
78
+ fontSize: 16,
79
+ fontWeight: '600',
80
+ },
81
+ });
@@ -0,0 +1,163 @@
1
+ import React from 'react';
2
+ import {View, Text, StyleSheet, ScrollView} from 'react-native';
3
+ import {TrackedEvent} from '../types/flags.types';
4
+
5
+ interface EventTrackingLogProps {
6
+ events: TrackedEvent[];
7
+ maxEvents?: number;
8
+ }
9
+
10
+ const getEventEmoji = (eventName: string): string => {
11
+ if (eventName === '$experiment_started') return '🧪';
12
+ if (eventName.startsWith('FLAG_')) return '🚩';
13
+ if (eventName.startsWith('$')) return '📊';
14
+ return '✅';
15
+ };
16
+
17
+ const formatEventProperties = (properties: Record<string, any>): string => {
18
+ const relevantProps: Record<string, any> = {};
19
+
20
+ // Extract only the most relevant properties for display
21
+ const keys = ['$experiment_name', '$variant_name', '$variant_value', '$experiment_id',
22
+ 'flag_key', 'flag_enabled', 'flag_value', 'screen_name'];
23
+
24
+ keys.forEach(key => {
25
+ if (properties[key] !== undefined) {
26
+ relevantProps[key] = properties[key];
27
+ }
28
+ });
29
+
30
+ return JSON.stringify(relevantProps, null, 2);
31
+ };
32
+
33
+ const getTimeAgo = (date: Date): string => {
34
+ const seconds = Math.floor((new Date().getTime() - date.getTime()) / 1000);
35
+ if (seconds < 60) return `${seconds}s ago`;
36
+ const minutes = Math.floor(seconds / 60);
37
+ if (minutes < 60) return `${minutes}m ago`;
38
+ const hours = Math.floor(minutes / 60);
39
+ if (hours < 24) return `${hours}h ago`;
40
+ return date.toLocaleTimeString();
41
+ };
42
+
43
+ export const EventTrackingLog: React.FC<EventTrackingLogProps> = ({
44
+ events,
45
+ maxEvents = 10,
46
+ }) => {
47
+ const displayEvents = events.slice(0, maxEvents);
48
+
49
+ if (displayEvents.length === 0) {
50
+ return (
51
+ <View style={styles.container}>
52
+ <Text style={styles.placeholder}>
53
+ No events tracked yet. Interact with flags to see tracking events.
54
+ </Text>
55
+ </View>
56
+ );
57
+ }
58
+
59
+ return (
60
+ <ScrollView style={styles.container} nestedScrollEnabled>
61
+ {displayEvents.map(event => (
62
+ <View
63
+ key={event.id}
64
+ style={[
65
+ styles.eventCard,
66
+ event.eventName === '$experiment_started' && styles.experimentEvent,
67
+ ]}>
68
+ <View style={styles.eventHeader}>
69
+ <View style={styles.eventHeaderLeft}>
70
+ <Text style={styles.emoji}>{getEventEmoji(event.eventName)}</Text>
71
+ <View>
72
+ <Text style={styles.eventName}>{event.eventName}</Text>
73
+ <Text style={styles.timestamp}>{getTimeAgo(event.timestamp)}</Text>
74
+ </View>
75
+ </View>
76
+ </View>
77
+
78
+ {Object.keys(event.properties).length > 0 && (
79
+ <View style={styles.propertiesSection}>
80
+ <Text style={styles.propertiesText}>
81
+ {formatEventProperties(event.properties)}
82
+ </Text>
83
+ </View>
84
+ )}
85
+ </View>
86
+ ))}
87
+
88
+ {events.length > maxEvents && (
89
+ <Text style={styles.moreText}>
90
+ + {events.length - maxEvents} more events
91
+ </Text>
92
+ )}
93
+ </ScrollView>
94
+ );
95
+ };
96
+
97
+ const styles = StyleSheet.create({
98
+ container: {
99
+ maxHeight: 400,
100
+ },
101
+ placeholder: {
102
+ textAlign: 'center',
103
+ color: '#999',
104
+ fontSize: 14,
105
+ padding: 20,
106
+ },
107
+ eventCard: {
108
+ backgroundColor: '#fff',
109
+ borderRadius: 8,
110
+ borderWidth: 1,
111
+ borderColor: '#e0e0e0',
112
+ marginBottom: 12,
113
+ padding: 12,
114
+ },
115
+ experimentEvent: {
116
+ borderColor: '#9c27b0',
117
+ borderWidth: 2,
118
+ backgroundColor: '#f3e5f5',
119
+ },
120
+ eventHeader: {
121
+ flexDirection: 'row',
122
+ justifyContent: 'space-between',
123
+ alignItems: 'flex-start',
124
+ marginBottom: 8,
125
+ },
126
+ eventHeaderLeft: {
127
+ flexDirection: 'row',
128
+ alignItems: 'flex-start',
129
+ flex: 1,
130
+ },
131
+ emoji: {
132
+ fontSize: 20,
133
+ marginRight: 10,
134
+ },
135
+ eventName: {
136
+ fontSize: 15,
137
+ fontWeight: '600',
138
+ color: '#333',
139
+ marginBottom: 2,
140
+ },
141
+ timestamp: {
142
+ fontSize: 12,
143
+ color: '#666',
144
+ },
145
+ propertiesSection: {
146
+ marginTop: 8,
147
+ padding: 10,
148
+ backgroundColor: '#f8f9fa',
149
+ borderRadius: 4,
150
+ },
151
+ propertiesText: {
152
+ fontFamily: 'Courier',
153
+ fontSize: 12,
154
+ color: '#555',
155
+ },
156
+ moreText: {
157
+ textAlign: 'center',
158
+ color: '#666',
159
+ fontSize: 13,
160
+ paddingVertical: 8,
161
+ fontStyle: 'italic',
162
+ },
163
+ });
@@ -0,0 +1,199 @@
1
+ import React, {useState} from 'react';
2
+ import {View, Text, StyleSheet, TouchableOpacity} from 'react-native';
3
+ import {FlagInfo, ValueType} from '../types/flags.types';
4
+
5
+ interface FlagCardProps {
6
+ flag: FlagInfo;
7
+ onTest?: (flagKey: string) => void;
8
+ }
9
+
10
+ const getValueTypeEmoji = (type: ValueType): string => {
11
+ switch (type) {
12
+ case 'string':
13
+ return '📝';
14
+ case 'number':
15
+ return '🔢';
16
+ case 'boolean':
17
+ return '✓';
18
+ case 'object':
19
+ return '📦';
20
+ case 'array':
21
+ return '📋';
22
+ case 'null':
23
+ return '∅';
24
+ default:
25
+ return '❓';
26
+ }
27
+ };
28
+
29
+ const formatValue = (value: any, type: ValueType): string => {
30
+ if (type === 'object' || type === 'array') {
31
+ return JSON.stringify(value, null, 2);
32
+ }
33
+ if (type === 'string') {
34
+ return `"${value}"`;
35
+ }
36
+ if (type === 'null') {
37
+ return 'null';
38
+ }
39
+ return String(value);
40
+ };
41
+
42
+ const getTimeAgo = (date?: Date): string => {
43
+ if (!date) return 'Never';
44
+ const seconds = Math.floor((new Date().getTime() - date.getTime()) / 1000);
45
+ if (seconds < 60) return `${seconds}s ago`;
46
+ const minutes = Math.floor(seconds / 60);
47
+ if (minutes < 60) return `${minutes}m ago`;
48
+ const hours = Math.floor(minutes / 60);
49
+ return `${hours}h ago`;
50
+ };
51
+
52
+ export const FlagCard: React.FC<FlagCardProps> = ({flag, onTest}) => {
53
+ const [expanded, setExpanded] = useState(false);
54
+
55
+ return (
56
+ <View style={styles.card}>
57
+ <TouchableOpacity
58
+ onPress={() => setExpanded(!expanded)}
59
+ style={styles.header}>
60
+ <View style={styles.headerLeft}>
61
+ <Text style={styles.emoji}>{getValueTypeEmoji(flag.valueType)}</Text>
62
+ <View>
63
+ <Text style={styles.flagKey}>{flag.key}</Text>
64
+ <Text style={styles.value} numberOfLines={expanded ? undefined : 1}>
65
+ {formatValue(flag.value, flag.valueType)}
66
+ </Text>
67
+ </View>
68
+ </View>
69
+ <Text style={styles.expandIcon}>{expanded ? '▼' : '▶'}</Text>
70
+ </TouchableOpacity>
71
+
72
+ {expanded && (
73
+ <View style={styles.details}>
74
+ <View style={styles.detailRow}>
75
+ <Text style={styles.label}>Type:</Text>
76
+ <Text style={styles.detailValue}>{flag.valueType}</Text>
77
+ </View>
78
+
79
+ <View style={styles.detailRow}>
80
+ <Text style={styles.label}>Variant Key:</Text>
81
+ <Text style={styles.detailValue}>{flag.variantKey || 'N/A'}</Text>
82
+ </View>
83
+
84
+ {flag.experimentID && (
85
+ <View style={styles.detailRow}>
86
+ <Text style={styles.label}>Experiment ID:</Text>
87
+ <Text style={styles.detailValue}>{flag.experimentID}</Text>
88
+ </View>
89
+ )}
90
+
91
+ {flag.isExperimentActive !== undefined && (
92
+ <View style={styles.detailRow}>
93
+ <Text style={styles.label}>Active:</Text>
94
+ <Text style={styles.detailValue}>
95
+ {flag.isExperimentActive ? '✅ Yes' : '⏸️ No'}
96
+ </Text>
97
+ </View>
98
+ )}
99
+
100
+ {flag.isQATester !== undefined && (
101
+ <View style={styles.detailRow}>
102
+ <Text style={styles.label}>QA Tester:</Text>
103
+ <Text style={styles.detailValue}>
104
+ {flag.isQATester ? '🧪 Yes' : 'No'}
105
+ </Text>
106
+ </View>
107
+ )}
108
+
109
+ <View style={styles.detailRow}>
110
+ <Text style={styles.label}>Last Accessed:</Text>
111
+ <Text style={styles.detailValue}>{getTimeAgo(flag.lastAccessed)}</Text>
112
+ </View>
113
+
114
+ {onTest && (
115
+ <TouchableOpacity
116
+ style={styles.testButton}
117
+ onPress={() => onTest(flag.key)}>
118
+ <Text style={styles.testButtonText}>Test This Flag</Text>
119
+ </TouchableOpacity>
120
+ )}
121
+ </View>
122
+ )}
123
+ </View>
124
+ );
125
+ };
126
+
127
+ const styles = StyleSheet.create({
128
+ card: {
129
+ backgroundColor: '#f8f9fa',
130
+ borderRadius: 8,
131
+ borderWidth: 1,
132
+ borderColor: '#e0e0e0',
133
+ marginBottom: 12,
134
+ overflow: 'hidden',
135
+ },
136
+ header: {
137
+ flexDirection: 'row',
138
+ justifyContent: 'space-between',
139
+ alignItems: 'center',
140
+ padding: 12,
141
+ },
142
+ headerLeft: {
143
+ flexDirection: 'row',
144
+ alignItems: 'center',
145
+ flex: 1,
146
+ },
147
+ emoji: {
148
+ fontSize: 24,
149
+ marginRight: 12,
150
+ },
151
+ flagKey: {
152
+ fontSize: 16,
153
+ fontWeight: '600',
154
+ color: '#333',
155
+ marginBottom: 4,
156
+ },
157
+ value: {
158
+ fontSize: 14,
159
+ color: '#666',
160
+ fontFamily: 'Courier',
161
+ },
162
+ expandIcon: {
163
+ fontSize: 12,
164
+ color: '#999',
165
+ },
166
+ details: {
167
+ padding: 12,
168
+ paddingTop: 0,
169
+ borderTopWidth: 1,
170
+ borderTopColor: '#e0e0e0',
171
+ },
172
+ detailRow: {
173
+ flexDirection: 'row',
174
+ justifyContent: 'space-between',
175
+ marginBottom: 8,
176
+ },
177
+ label: {
178
+ fontSize: 13,
179
+ color: '#666',
180
+ fontWeight: '500',
181
+ },
182
+ detailValue: {
183
+ fontSize: 13,
184
+ color: '#333',
185
+ fontFamily: 'Courier',
186
+ },
187
+ testButton: {
188
+ marginTop: 8,
189
+ backgroundColor: '#007AFF',
190
+ padding: 10,
191
+ borderRadius: 6,
192
+ alignItems: 'center',
193
+ },
194
+ testButtonText: {
195
+ color: '#fff',
196
+ fontSize: 14,
197
+ fontWeight: '600',
198
+ },
199
+ });