react-native-debug-toolkit 0.6.4 → 2.0.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 (277) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +150 -212
  3. package/lib/commonjs/components/ClipboardTab.js +92 -0
  4. package/lib/commonjs/components/ClipboardTab.js.map +1 -0
  5. package/lib/commonjs/components/ConsoleLogTab.js +295 -0
  6. package/lib/commonjs/components/ConsoleLogTab.js.map +1 -0
  7. package/lib/commonjs/components/EnvironmentTab.js +288 -0
  8. package/lib/commonjs/components/EnvironmentTab.js.map +1 -0
  9. package/lib/commonjs/components/FloatPanelView.js +797 -0
  10. package/lib/commonjs/components/FloatPanelView.js.map +1 -0
  11. package/lib/commonjs/components/NavigationLogTab.js +131 -0
  12. package/lib/commonjs/components/NavigationLogTab.js.map +1 -0
  13. package/lib/commonjs/components/NetworkLogTab.js +575 -0
  14. package/lib/commonjs/components/NetworkLogTab.js.map +1 -0
  15. package/lib/commonjs/components/ThirdPartyLibsTab.js +97 -0
  16. package/lib/commonjs/components/ThirdPartyLibsTab.js.map +1 -0
  17. package/lib/commonjs/components/TrackLogTab.js +372 -0
  18. package/lib/commonjs/components/TrackLogTab.js.map +1 -0
  19. package/lib/commonjs/components/ZustandLogTab.js +451 -0
  20. package/lib/commonjs/components/ZustandLogTab.js.map +1 -0
  21. package/lib/commonjs/components/shared/CollapsibleSection.js +84 -0
  22. package/lib/commonjs/components/shared/CollapsibleSection.js.map +1 -0
  23. package/lib/commonjs/components/shared/CopyButton.js +64 -0
  24. package/lib/commonjs/components/shared/CopyButton.js.map +1 -0
  25. package/lib/commonjs/components/shared/JsonView.js +157 -0
  26. package/lib/commonjs/components/shared/JsonView.js.map +1 -0
  27. package/lib/commonjs/core/DebugToolkit.js +142 -0
  28. package/lib/commonjs/core/DebugToolkit.js.map +1 -0
  29. package/lib/commonjs/core/DebugToolkitProvider.js +64 -0
  30. package/lib/commonjs/core/DebugToolkitProvider.js.map +1 -0
  31. package/lib/commonjs/features/ClipboardFeature.js +17 -0
  32. package/lib/commonjs/features/ClipboardFeature.js.map +1 -0
  33. package/lib/commonjs/features/ConsoleLogFeature.js +98 -0
  34. package/lib/commonjs/features/ConsoleLogFeature.js.map +1 -0
  35. package/lib/commonjs/features/EnvironmentFeature.js +168 -0
  36. package/lib/commonjs/features/EnvironmentFeature.js.map +1 -0
  37. package/lib/commonjs/features/NavigationLogFeature.js +60 -0
  38. package/lib/commonjs/features/NavigationLogFeature.js.map +1 -0
  39. package/lib/commonjs/features/NetworkFeature.js +328 -0
  40. package/lib/commonjs/features/NetworkFeature.js.map +1 -0
  41. package/lib/commonjs/features/ThirdPartyLibsFeature.js +51 -0
  42. package/lib/commonjs/features/ThirdPartyLibsFeature.js.map +1 -0
  43. package/lib/commonjs/features/TrackFeature.js +55 -0
  44. package/lib/commonjs/features/TrackFeature.js.map +1 -0
  45. package/lib/commonjs/features/ZustandLogFeature.js +76 -0
  46. package/lib/commonjs/features/ZustandLogFeature.js.map +1 -0
  47. package/lib/commonjs/hooks/useNavigationLogger.js +78 -0
  48. package/lib/commonjs/hooks/useNavigationLogger.js.map +1 -0
  49. package/lib/commonjs/hooks/useSlideDetailAnimation.js +53 -0
  50. package/lib/commonjs/hooks/useSlideDetailAnimation.js.map +1 -0
  51. package/lib/commonjs/index.js +165 -0
  52. package/lib/commonjs/index.js.map +1 -0
  53. package/lib/commonjs/initialize.js +161 -0
  54. package/lib/commonjs/initialize.js.map +1 -0
  55. package/lib/commonjs/native/NativeDebugLibs.js +58 -0
  56. package/lib/commonjs/native/NativeDebugLibs.js.map +1 -0
  57. package/lib/commonjs/package.json +1 -0
  58. package/lib/commonjs/types/index.js +6 -0
  59. package/lib/commonjs/types/index.js.map +1 -0
  60. package/lib/commonjs/utils/constants.js +135 -0
  61. package/lib/commonjs/utils/constants.js.map +1 -0
  62. package/lib/commonjs/utils/copyToComputer.js +97 -0
  63. package/lib/commonjs/utils/copyToComputer.js.map +1 -0
  64. package/lib/commonjs/utils/createEventChannel.js +21 -0
  65. package/lib/commonjs/utils/createEventChannel.js.map +1 -0
  66. package/lib/commonjs/utils/createObservableStore.js +38 -0
  67. package/lib/commonjs/utils/createObservableStore.js.map +1 -0
  68. package/lib/commonjs/utils/safeStringify.js +27 -0
  69. package/lib/commonjs/utils/safeStringify.js.map +1 -0
  70. package/lib/module/components/ClipboardTab.js +86 -0
  71. package/lib/module/components/ClipboardTab.js.map +1 -0
  72. package/lib/module/components/ConsoleLogTab.js +290 -0
  73. package/lib/module/components/ConsoleLogTab.js.map +1 -0
  74. package/lib/module/components/EnvironmentTab.js +282 -0
  75. package/lib/module/components/EnvironmentTab.js.map +1 -0
  76. package/lib/module/components/FloatPanelView.js +791 -0
  77. package/lib/module/components/FloatPanelView.js.map +1 -0
  78. package/lib/module/components/NavigationLogTab.js +126 -0
  79. package/lib/module/components/NavigationLogTab.js.map +1 -0
  80. package/lib/module/components/NetworkLogTab.js +570 -0
  81. package/lib/module/components/NetworkLogTab.js.map +1 -0
  82. package/lib/module/components/ThirdPartyLibsTab.js +91 -0
  83. package/lib/module/components/ThirdPartyLibsTab.js.map +1 -0
  84. package/lib/module/components/TrackLogTab.js +367 -0
  85. package/lib/module/components/TrackLogTab.js.map +1 -0
  86. package/lib/module/components/ZustandLogTab.js +446 -0
  87. package/lib/module/components/ZustandLogTab.js.map +1 -0
  88. package/lib/module/components/shared/CollapsibleSection.js +78 -0
  89. package/lib/module/components/shared/CollapsibleSection.js.map +1 -0
  90. package/lib/module/components/shared/CopyButton.js +58 -0
  91. package/lib/module/components/shared/CopyButton.js.map +1 -0
  92. package/lib/module/components/shared/JsonView.js +152 -0
  93. package/lib/module/components/shared/JsonView.js.map +1 -0
  94. package/lib/module/core/DebugToolkit.js +137 -0
  95. package/lib/module/core/DebugToolkit.js.map +1 -0
  96. package/lib/module/core/DebugToolkitProvider.js +58 -0
  97. package/lib/module/core/DebugToolkitProvider.js.map +1 -0
  98. package/lib/module/features/ClipboardFeature.js +12 -0
  99. package/lib/module/features/ClipboardFeature.js.map +1 -0
  100. package/lib/module/features/ConsoleLogFeature.js +93 -0
  101. package/lib/module/features/ConsoleLogFeature.js.map +1 -0
  102. package/lib/module/features/EnvironmentFeature.js +164 -0
  103. package/lib/module/features/EnvironmentFeature.js.map +1 -0
  104. package/lib/module/features/NavigationLogFeature.js +54 -0
  105. package/lib/module/features/NavigationLogFeature.js.map +1 -0
  106. package/lib/module/features/NetworkFeature.js +322 -0
  107. package/lib/module/features/NetworkFeature.js.map +1 -0
  108. package/lib/module/features/ThirdPartyLibsFeature.js +46 -0
  109. package/lib/module/features/ThirdPartyLibsFeature.js.map +1 -0
  110. package/lib/module/features/TrackFeature.js +49 -0
  111. package/lib/module/features/TrackFeature.js.map +1 -0
  112. package/lib/module/features/ZustandLogFeature.js +69 -0
  113. package/lib/module/features/ZustandLogFeature.js.map +1 -0
  114. package/lib/module/hooks/useNavigationLogger.js +74 -0
  115. package/lib/module/hooks/useNavigationLogger.js.map +1 -0
  116. package/lib/module/hooks/useSlideDetailAnimation.js +50 -0
  117. package/lib/module/hooks/useSlideDetailAnimation.js.map +1 -0
  118. package/lib/module/index.js +29 -0
  119. package/lib/module/index.js.map +1 -0
  120. package/lib/module/initialize.js +156 -0
  121. package/lib/module/initialize.js.map +1 -0
  122. package/lib/module/native/NativeDebugLibs.js +54 -0
  123. package/lib/module/native/NativeDebugLibs.js.map +1 -0
  124. package/lib/module/package.json +1 -0
  125. package/lib/module/types/index.js +4 -0
  126. package/lib/module/types/index.js.map +1 -0
  127. package/lib/module/utils/constants.js +130 -0
  128. package/lib/module/utils/constants.js.map +1 -0
  129. package/lib/module/utils/copyToComputer.js +91 -0
  130. package/lib/module/utils/copyToComputer.js.map +1 -0
  131. package/lib/module/utils/createEventChannel.js +17 -0
  132. package/lib/module/utils/createEventChannel.js.map +1 -0
  133. package/lib/module/utils/createObservableStore.js +34 -0
  134. package/lib/module/utils/createObservableStore.js.map +1 -0
  135. package/lib/module/utils/safeStringify.js +23 -0
  136. package/lib/module/utils/safeStringify.js.map +1 -0
  137. package/lib/typescript/src/components/ClipboardTab.d.ts +4 -0
  138. package/lib/typescript/src/components/ClipboardTab.d.ts.map +1 -0
  139. package/lib/typescript/src/components/ConsoleLogTab.d.ts +4 -0
  140. package/lib/typescript/src/components/ConsoleLogTab.d.ts.map +1 -0
  141. package/lib/typescript/src/components/EnvironmentTab.d.ts +4 -0
  142. package/lib/typescript/src/components/EnvironmentTab.d.ts.map +1 -0
  143. package/lib/typescript/src/components/FloatPanelView.d.ts +64 -0
  144. package/lib/typescript/src/components/FloatPanelView.d.ts.map +1 -0
  145. package/lib/typescript/src/components/NavigationLogTab.d.ts +4 -0
  146. package/lib/typescript/src/components/NavigationLogTab.d.ts.map +1 -0
  147. package/lib/typescript/src/components/NetworkLogTab.d.ts +4 -0
  148. package/lib/typescript/src/components/NetworkLogTab.d.ts.map +1 -0
  149. package/lib/typescript/src/components/ThirdPartyLibsTab.d.ts +4 -0
  150. package/lib/typescript/src/components/ThirdPartyLibsTab.d.ts.map +1 -0
  151. package/lib/typescript/src/components/TrackLogTab.d.ts +4 -0
  152. package/lib/typescript/src/components/TrackLogTab.d.ts.map +1 -0
  153. package/lib/typescript/src/components/ZustandLogTab.d.ts +4 -0
  154. package/lib/typescript/src/components/ZustandLogTab.d.ts.map +1 -0
  155. package/lib/typescript/src/components/shared/CollapsibleSection.d.ts +9 -0
  156. package/lib/typescript/src/components/shared/CollapsibleSection.d.ts.map +1 -0
  157. package/lib/typescript/src/components/shared/CopyButton.d.ts +12 -0
  158. package/lib/typescript/src/components/shared/CopyButton.d.ts.map +1 -0
  159. package/lib/typescript/src/components/shared/JsonView.d.ts +6 -0
  160. package/lib/typescript/src/components/shared/JsonView.d.ts.map +1 -0
  161. package/lib/typescript/src/core/DebugToolkit.d.ts +27 -0
  162. package/lib/typescript/src/core/DebugToolkit.d.ts.map +1 -0
  163. package/lib/typescript/src/core/DebugToolkitProvider.d.ts +18 -0
  164. package/lib/typescript/src/core/DebugToolkitProvider.d.ts.map +1 -0
  165. package/lib/typescript/src/features/ClipboardFeature.d.ts +3 -0
  166. package/lib/typescript/src/features/ClipboardFeature.d.ts.map +1 -0
  167. package/lib/typescript/src/features/ConsoleLogFeature.d.ts +7 -0
  168. package/lib/typescript/src/features/ConsoleLogFeature.d.ts.map +1 -0
  169. package/lib/typescript/src/features/EnvironmentFeature.d.ts +8 -0
  170. package/lib/typescript/src/features/EnvironmentFeature.d.ts.map +1 -0
  171. package/lib/typescript/src/features/NavigationLogFeature.d.ts +8 -0
  172. package/lib/typescript/src/features/NavigationLogFeature.d.ts.map +1 -0
  173. package/lib/typescript/src/features/NetworkFeature.d.ts +28 -0
  174. package/lib/typescript/src/features/NetworkFeature.d.ts.map +1 -0
  175. package/lib/typescript/src/features/ThirdPartyLibsFeature.d.ts +3 -0
  176. package/lib/typescript/src/features/ThirdPartyLibsFeature.d.ts.map +1 -0
  177. package/lib/typescript/src/features/TrackFeature.d.ts +12 -0
  178. package/lib/typescript/src/features/TrackFeature.d.ts.map +1 -0
  179. package/lib/typescript/src/features/ZustandLogFeature.d.ts +29 -0
  180. package/lib/typescript/src/features/ZustandLogFeature.d.ts.map +1 -0
  181. package/lib/typescript/src/hooks/useNavigationLogger.d.ts +20 -0
  182. package/lib/typescript/src/hooks/useNavigationLogger.d.ts.map +1 -0
  183. package/lib/typescript/src/hooks/useSlideDetailAnimation.d.ts +11 -0
  184. package/lib/typescript/src/hooks/useSlideDetailAnimation.d.ts.map +1 -0
  185. package/lib/typescript/src/index.d.ts +26 -0
  186. package/lib/typescript/src/index.d.ts.map +1 -0
  187. package/lib/typescript/src/initialize.d.ts +51 -0
  188. package/lib/typescript/src/initialize.d.ts.map +1 -0
  189. package/lib/typescript/src/native/NativeDebugLibs.d.ts +11 -0
  190. package/lib/typescript/src/native/NativeDebugLibs.d.ts.map +1 -0
  191. package/lib/typescript/src/types/index.d.ts +112 -0
  192. package/lib/typescript/src/types/index.d.ts.map +1 -0
  193. package/lib/typescript/src/utils/constants.d.ts +96 -0
  194. package/lib/typescript/src/utils/constants.d.ts.map +1 -0
  195. package/lib/typescript/src/utils/copyToComputer.d.ts +30 -0
  196. package/lib/typescript/src/utils/copyToComputer.d.ts.map +1 -0
  197. package/lib/typescript/src/utils/createEventChannel.d.ts +7 -0
  198. package/lib/typescript/src/utils/createEventChannel.d.ts.map +1 -0
  199. package/lib/typescript/src/utils/createObservableStore.d.ts +9 -0
  200. package/lib/typescript/src/utils/createObservableStore.d.ts.map +1 -0
  201. package/lib/typescript/src/utils/safeStringify.d.ts +6 -0
  202. package/lib/typescript/src/utils/safeStringify.d.ts.map +1 -0
  203. package/package.json +63 -24
  204. package/src/components/ClipboardTab.tsx +81 -0
  205. package/src/components/ConsoleLogTab.tsx +209 -0
  206. package/src/components/EnvironmentTab.tsx +276 -0
  207. package/src/components/FloatPanelView.tsx +714 -0
  208. package/src/components/NavigationLogTab.tsx +66 -0
  209. package/src/components/NetworkLogTab.tsx +411 -0
  210. package/src/components/ThirdPartyLibsTab.tsx +63 -0
  211. package/src/components/TrackLogTab.tsx +245 -0
  212. package/src/components/ZustandLogTab.tsx +305 -0
  213. package/src/components/shared/CollapsibleSection.tsx +78 -0
  214. package/src/components/shared/CopyButton.tsx +68 -0
  215. package/src/components/shared/JsonView.tsx +125 -0
  216. package/src/core/DebugToolkit.tsx +174 -0
  217. package/src/core/DebugToolkitProvider.tsx +89 -0
  218. package/src/features/ClipboardFeature.ts +11 -0
  219. package/src/features/ConsoleLogFeature.ts +118 -0
  220. package/src/features/EnvironmentFeature.ts +194 -0
  221. package/src/features/NavigationLogFeature.ts +74 -0
  222. package/src/features/NetworkFeature.ts +488 -0
  223. package/src/features/ThirdPartyLibsFeature.ts +42 -0
  224. package/src/features/TrackFeature.ts +69 -0
  225. package/src/features/ZustandLogFeature.ts +127 -0
  226. package/src/hooks/useNavigationLogger.ts +107 -0
  227. package/src/hooks/useSlideDetailAnimation.ts +45 -0
  228. package/src/index.ts +52 -0
  229. package/src/initialize.ts +214 -0
  230. package/src/native/NativeDebugLibs.ts +74 -0
  231. package/src/types/index.ts +138 -0
  232. package/src/utils/constants.ts +91 -0
  233. package/src/utils/copyToComputer.ts +104 -0
  234. package/src/utils/createEventChannel.ts +22 -0
  235. package/src/utils/createObservableStore.ts +42 -0
  236. package/src/utils/safeStringify.ts +25 -0
  237. package/.cursor/rules/react-native.mdc +0 -41
  238. package/README.zh-CN.md +0 -230
  239. package/index.js +0 -41
  240. package/ios/BuildTypeModule.h +0 -9
  241. package/ios/BuildTypeModule.m +0 -42
  242. package/ios/RNDebugLibs.h +0 -10
  243. package/ios/RNDebugLibs.m +0 -79
  244. package/lib/DebugToolKit.js +0 -126
  245. package/lib/EnvironmentManager.ts +0 -80
  246. package/lib/NativeDebugLibs.js +0 -67
  247. package/lib/features/ConsoleLogFeature.js +0 -70
  248. package/lib/features/NavigationLogFeature.js +0 -45
  249. package/lib/features/NetworkFeature.js +0 -389
  250. package/lib/features/PerformanceFeature.js +0 -390
  251. package/lib/features/ThirdPartyLibsFeature.js +0 -63
  252. package/lib/features/TrackFeature.js +0 -94
  253. package/lib/features/ZustandLogFeature.js +0 -44
  254. package/lib/hooks/useNavigationLogger.js +0 -92
  255. package/lib/index.js +0 -114
  256. package/lib/navigation/NavigationLogger.js +0 -1
  257. package/lib/types/TrackTypes.ts +0 -92
  258. package/lib/utils/DebugConst.js +0 -67
  259. package/lib/utils/StorageUtils.js +0 -80
  260. package/lib/views/ConsoleLogDetails.js +0 -314
  261. package/lib/views/FloatPanelView.js +0 -697
  262. package/lib/views/HttpLogDetails.js +0 -648
  263. package/lib/views/NavigationLogDetails.js +0 -302
  264. package/lib/views/RestartModal.js +0 -75
  265. package/lib/views/SubViewConsoleLogs.js +0 -209
  266. package/lib/views/SubViewEnvironment.js +0 -73
  267. package/lib/views/SubViewHTTPLogs.js +0 -235
  268. package/lib/views/SubViewNavigationLogs.js +0 -199
  269. package/lib/views/SubViewPerformance.js +0 -515
  270. package/lib/views/SubViewThirdPartyLibs.js +0 -239
  271. package/lib/views/SubViewTrackLogs.js +0 -318
  272. package/lib/views/SubViewZustandLogs.js +0 -279
  273. package/lib/views/TabView.js +0 -66
  274. package/lib/views/TrackLogDetails.js +0 -481
  275. package/lib/views/ZustandLogDetails.js +0 -355
  276. package/react-native-debug-toolkit.podspec +0 -25
  277. package/react-native.config.js +0 -18
@@ -1,515 +0,0 @@
1
- // lib/views/SubViewPerformance.js
2
- import React, { useState, useEffect } from 'react';
3
- import { View, Text, StyleSheet, Clipboard, Dimensions, ScrollView, Pressable, Platform } from 'react-native';
4
- import performance, { PerformanceObserver, setResourceLoggingEnabled } from 'react-native-performance';
5
- import JSONTree from 'react-native-json-tree';
6
-
7
- const { width: SCREEN_WIDTH } = Dimensions.get('window');
8
-
9
- // Make sure resource logging is enabled for this view to capture network data
10
- // It might be enabled in the feature setup, but ensure it here too if needed
11
- // setResourceLoggingEnabled(true);
12
-
13
- const theme = {
14
- scheme: 'monokai',
15
- author: 'wimer hazenberg (http://www.monokai.nl)',
16
- base00: '#272822', // Background for JSONTree
17
- base01: '#383830',
18
- base02: '#49483e',
19
- base03: '#75715e',
20
- base04: '#a59f85',
21
- base05: '#f8f8f2', // Default text color
22
- base06: '#f5f4f1',
23
- base07: '#f9f8f5',
24
- base08: '#f92672', // Red
25
- base09: '#fd971f', // Orange
26
- base0A: '#f4bf75', // Yellow
27
- base0B: '#a6e22e', // Green
28
- base0C: '#a1efe4', // Cyan
29
- base0D: '#66d9ef', // Blue
30
- base0E: '#ae81ff', // Purple
31
- base0F: '#cc6633' // Brown
32
- };
33
-
34
- const CopyButton = ({ text, style }) => {
35
- const [copied, setCopied] = useState(false);
36
-
37
- const handleCopy = async () => {
38
- try {
39
- await Clipboard.setString(text || ''); // Ensure text is not null/undefined
40
- setCopied(true);
41
- setTimeout(() => setCopied(false), 2000);
42
- } catch (error) {
43
- console.error("Failed to copy text: ", error);
44
- }
45
- };
46
-
47
- return (
48
- <Pressable style={[styles.copyButton, style]} onPress={handleCopy}>
49
- <Text style={styles.copyButtonText}>{copied ? 'Copied!' : 'Copy'}</Text>
50
- </Pressable>
51
- );
52
- };
53
-
54
- const CollapsibleSection = ({ title, children, initiallyExpanded = false }) => {
55
- const [expanded, setExpanded] = useState(initiallyExpanded);
56
-
57
- return (
58
- <View style={styles.collapsibleSection}>
59
- <Pressable
60
- style={styles.sectionHeader}
61
- onPress={() => setExpanded(!expanded)}>
62
- <Text style={styles.sectionTitle}>{title}</Text>
63
- <Text style={styles.expandIcon}>{expanded ? '▼' : '▶'}</Text>
64
- </Pressable>
65
- {expanded && children}
66
- </View>
67
- );
68
- };
69
-
70
- const SubViewPerformance = () => {
71
- const [appLaunchMetrics, setAppLaunchMetrics] = useState(null);
72
- const [markEntries, setMarkEntries] = useState([]);
73
- const [measureEntries, setMeasureEntries] = useState([]);
74
- const [resourceEntries, setResourceEntries] = useState([]);
75
- const [metricEntries, setMetricEntries] = useState([]);
76
- const [nativeMarkEntries, setNativeMarkEntries] = useState([]);
77
-
78
- useEffect(() => {
79
- // Function to calculate and create app launch metrics from available marks
80
- const calculateAppLaunchMetrics = () => {
81
- try {
82
- // Attempt to get necessary marks. May throw if performance object not fully ready.
83
- const nativeLaunchStartMark = performance.getEntriesByName('nativeLaunchStart', 'mark')[0];
84
- const nativeLaunchEndMark = performance.getEntriesByName('nativeLaunchEnd', 'mark')[0];
85
- const runJsBundleStartMark = performance.getEntriesByName('runJsBundleStart', 'mark')[0];
86
- const runJsBundleEndMark = performance.getEntriesByName('runJsBundleEnd', 'mark')[0];
87
- const contentAppearedMark = performance.getEntriesByName('contentAppeared', 'mark')[0];
88
-
89
- // Only create measure if both start and end marks exist
90
- if (nativeLaunchStartMark && nativeLaunchEndMark) {
91
- performance.measure('nativeLaunch', 'nativeLaunchStart', 'nativeLaunchEnd');
92
- }
93
- if (runJsBundleStartMark && runJsBundleEndMark) {
94
- performance.measure('runJsBundle', 'runJsBundleStart', 'runJsBundleEnd');
95
- }
96
-
97
- // Update state with calculated metrics - use helper functions for safety
98
- setAppLaunchMetrics({
99
- appStartTime: performance.timeOrigin, // Time origin is relatively stable
100
- nativeLaunch: getMeasureValue('nativeLaunch'),
101
- jsBundle: getMeasureValue('runJsBundle'),
102
- timeToContentAppeared: contentAppearedMark ? contentAppearedMark.startTime - performance.timeOrigin : null,
103
- });
104
-
105
- } catch (e) {
106
- // Log politely, as marks might appear later or not at all (e.g., in debug)
107
- // console.log('Could not calculate all launch metrics, some marks might be missing or performance API not ready:', e?.message);
108
- // Set partial or null metrics if calculation fails or marks aren't ready
109
- setAppLaunchMetrics(prev => ({
110
- ...prev, // Keep any previously calculated metrics
111
- appStartTime: performance.timeOrigin,
112
- nativeLaunch: prev?.nativeLaunch ?? getMeasureValue('nativeLaunch'), // Try getting again
113
- jsBundle: prev?.jsBundle ?? getMeasureValue('runJsBundle'),
114
- timeToContentAppeared: prev?.timeToContentAppeared ?? (getMarkTime('contentAppeared') ? getMarkTime('contentAppeared') - performance.timeOrigin : null),
115
- }));
116
- }
117
- };
118
-
119
- // Add a custom metric for demonstration when the component mounts
120
- performance.metric('SubViewPerformance.Mounted', Date.now());
121
-
122
- // Set up observers for different entry types
123
- const observers = []; // Keep track of observers for cleanup
124
-
125
- const setupObserver = (type, setter) => {
126
- try {
127
- const observer = new PerformanceObserver((list) => {
128
- // Use functional update to avoid stale state issues
129
- setter(prevEntries => {
130
- // Basic deduplication based on name and startTime
131
- const existingEntries = new Map(prevEntries.map(e => [`${e.name}-${e.startTime}`, e]));
132
- list.getEntries().forEach(entry => {
133
- existingEntries.set(`${entry.name}-${entry.startTime}`, entry);
134
- });
135
- return Array.from(existingEntries.values()).sort((a, b) => a.startTime - b.startTime);
136
- });
137
- // If native marks arrive, try recalculating launch metrics
138
- if (type === 'react-native-mark') {
139
- calculateAppLaunchMetrics();
140
- }
141
- });
142
- observer.observe({ type, buffered: true });
143
- observers.push(observer);
144
- } catch (e) {
145
- console.error(`Failed to setup PerformanceObserver for type "${type}":`, e);
146
- }
147
- };
148
-
149
- setupObserver('mark', setMarkEntries);
150
- setupObserver('measure', setMeasureEntries);
151
- setupObserver('resource', setResourceEntries);
152
- setupObserver('metric', setMetricEntries);
153
- setupObserver('react-native-mark', setNativeMarkEntries);
154
-
155
-
156
- // Add a mark when this specific view opens
157
- performance.mark('PerformanceViewOpened');
158
-
159
- // Initial attempt to calculate metrics in case marks are already present when component mounts
160
- calculateAppLaunchMetrics();
161
-
162
- // Clean up observers when component unmounts
163
- return () => {
164
- observers.forEach(observer => observer.disconnect());
165
- };
166
- }, []); // Empty dependency array ensures this runs only once on mount
167
-
168
- // Helper function to safely get measure value
169
- const getMeasureValue = (name) => {
170
- try {
171
- const entries = performance.getEntriesByName(name, 'measure');
172
- return entries.length > 0 ? entries[0].duration : null;
173
- } catch (e) {
174
- // This can happen if performance API is accessed too early
175
- // console.log(`Could not get measure "${name}": ${e.message}`);
176
- return null;
177
- }
178
- };
179
-
180
- // Helper function to safely get mark time
181
- const getMarkTime = (name) => {
182
- try {
183
- const entries = performance.getEntriesByName(name, 'mark');
184
- return entries.length > 0 ? entries[0].startTime : null;
185
- } catch (e) {
186
- // console.log(`Could not get mark "${name}": ${e.message}`);
187
- return null;
188
- }
189
- };
190
-
191
- // Format timestamps for display (show 1 decimal place)
192
- const formatDuration = (duration) => {
193
- if (duration == null || isNaN(duration)) return 'N/A';
194
- return `${duration.toFixed(1)} ms`;
195
- };
196
-
197
- // Format start time (relative to timeOrigin)
198
- const formatTime = (startTime) => {
199
- if (startTime == null || isNaN(startTime)) return 'N/A';
200
- return `${startTime.toFixed(1)} ms`;
201
- };
202
-
203
- // Helper to create a JSON summary for the Copy button
204
- const createEntriesSummary = (entries) => {
205
- if (!entries || entries.length === 0) {
206
- return JSON.stringify({ message: 'No entries recorded for this type.' });
207
- }
208
- try {
209
- // Stringify the current state of entries
210
- return JSON.stringify(entries, null, 2); // Pretty print JSON
211
- } catch (e) {
212
- console.error("Error stringifying performance entries: ", e);
213
- return 'Error creating summary';
214
- }
215
- };
216
-
217
- // --- Render Logic ---
218
-
219
- // Render JSON tree for various entry types
220
- const renderEntryList = (entries, type) => (
221
- <View style={styles.dataSection}>
222
- <View style={styles.dataSectionHeader}>
223
- <Text style={styles.dataSectionTitle}>Entries</Text>
224
- <CopyButton text={createEntriesSummary(entries)} />
225
- </View>
226
- <View style={styles.dataContentWrapper}>
227
- <ScrollView
228
- style={styles.dataContent}
229
- nestedScrollEnabled={true}
230
- bounces={false}
231
- showsVerticalScrollIndicator={true}>
232
- {entries.length === 0 ? (
233
- <Text style={styles.noEntriesText}>No entries recorded yet.</Text>
234
- ) : (
235
- <JSONTree
236
- data={entries}
237
- theme={theme}
238
- invertTheme={false} // Use the theme as is
239
- hideRoot={true}
240
- shouldExpandNode={(keyPath, data, level) => level < 1} // Expand only top level by default
241
- valueRenderer={(raw, value) => {
242
- // Shorten long strings in preview
243
- if (typeof value === 'string' && value.length > 100) {
244
- return <Text style={{ color: theme.base0B }}>{`"${value.substring(0, 100)}..."`}</Text>;
245
- }
246
- return <Text style={{ color: theme.base0B }}>{raw}</Text>
247
- }}
248
- labelRenderer={([key]) => <Text style={{ color: theme.base0D }}>{key}:</Text>}
249
- getItemString={(itemType, data) => {
250
- // Provide a concise summary string for collapsed items
251
- let summary = `${itemType} ${data.name || '(anonymous)'}`;
252
- if (data.entryType === 'measure' || data.entryType === 'resource') {
253
- summary += ` (${formatDuration(data.duration)})`;
254
- } else if (data.entryType === 'mark') {
255
- summary += ` @ ${formatTime(data.startTime)}`;
256
- } else if (data.entryType === 'metric') {
257
- summary += `: ${data.value}`;
258
- }
259
- return <Text style={{color: theme.base05}}>{summary}</Text>;
260
- }}
261
- />
262
- )}
263
- </ScrollView>
264
- </View>
265
- </View>
266
- );
267
-
268
- return (
269
- <ScrollView
270
- style={styles.container}
271
- contentContainerStyle={styles.contentContainer}
272
- showsVerticalScrollIndicator={true}>
273
-
274
- <CollapsibleSection title='App Launch Performance' initiallyExpanded={true}>
275
- <View style={styles.content}>
276
- <Text style={styles.sectionDescription}>
277
- Key metrics for app startup. Relative to JS context creation (`timeOrigin`).
278
- </Text>
279
- <View style={styles.metricsGrid}>
280
- <View style={styles.metricItem}>
281
- <Text style={styles.metricValue} selectable={true}>
282
- {formatDuration(appLaunchMetrics?.nativeLaunch)}
283
- </Text>
284
- <Text style={styles.metricLabel}>Native Init</Text>
285
- </View>
286
- <View style={styles.metricItem}>
287
- <Text style={styles.metricValue} selectable={true}>
288
- {formatDuration(appLaunchMetrics?.jsBundle)}
289
- </Text>
290
- <Text style={styles.metricLabel}>JS Load</Text>
291
- </View>
292
- <View style={styles.metricItem}>
293
- <Text style={styles.metricValue} selectable={true}>
294
- {formatDuration(appLaunchMetrics?.timeToContentAppeared)}
295
- </Text>
296
- <Text style={styles.metricLabel}>Content Ready</Text>
297
- </View>
298
- </View>
299
- <Text style={styles.footnote}>Note: Values depend on native marks being available. 'N/A' indicates missing marks or calculation pending.</Text>
300
- </View>
301
- </CollapsibleSection>
302
-
303
- <CollapsibleSection title={`Native Marks (${nativeMarkEntries.length})`} initiallyExpanded={false}>
304
- <View style={styles.content}>
305
- <Text style={styles.sectionDescription}>
306
- Native events recorded during the app lifecycle. Times relative to `timeOrigin`.
307
- </Text>
308
- {renderEntryList(nativeMarkEntries, 'react-native-mark')}
309
- </View>
310
- </CollapsibleSection>
311
-
312
- <CollapsibleSection title={`Network Resources (${resourceEntries.length})`} initiallyExpanded={false}>
313
- <View style={styles.content}>
314
- <Text style={styles.sectionDescription}>
315
- Performance of network requests (fetch/XHR). Requires `setResourceLoggingEnabled(true)`.
316
- </Text>
317
- {renderEntryList(resourceEntries, 'resource')}
318
- </View>
319
- </CollapsibleSection>
320
-
321
- <CollapsibleSection title={`Marks (${markEntries.length})`} initiallyExpanded={false}>
322
- <View style={styles.content}>
323
- <Text style={styles.sectionDescription}>
324
- Custom points in time recorded via `performance.mark()`. Times relative to `timeOrigin`.
325
- </Text>
326
- {renderEntryList(markEntries, 'mark')}
327
- </View>
328
- </CollapsibleSection>
329
-
330
- <CollapsibleSection title={`Measures (${measureEntries.length})`} initiallyExpanded={false}>
331
- <View style={styles.content}>
332
- <Text style={styles.sectionDescription}>
333
- Durations recorded via `performance.measure()`.
334
- </Text>
335
- {renderEntryList(measureEntries, 'measure')}
336
- </View>
337
- </CollapsibleSection>
338
-
339
- <CollapsibleSection title={`Custom Metrics (${metricEntries.length})`} initiallyExpanded={false}>
340
- <View style={styles.content}>
341
- <Text style={styles.sectionDescription}>
342
- Custom values recorded via `performance.metric()`.
343
- </Text>
344
- {renderEntryList(metricEntries, 'metric')}
345
- </View>
346
- </CollapsibleSection>
347
-
348
- <CollapsibleSection title='Usage Info'>
349
- <View style={styles.content}>
350
- <Text style={styles.sectionDescription}>
351
- Add custom marks/measures/metrics in your code using the `react-native-performance` API:
352
- </Text>
353
- <View style={styles.codeBlockContainer}>
354
- <Text style={styles.codeText} selectable={true}>
355
- import performance from 'react-native-performance';
356
- {`\n\n// --- Marks (points in time) ---`}
357
- {`\nperformance.mark('myFeatureStart');`}
358
- {`\nperformance.mark('complexCalcDone', {`}
359
- {`\n detail: { inputSize: 1000 }`}
360
- {`\n});`}
361
- {`\n\n// --- Measures (durations) ---`}
362
- {`\nperformance.measure('myFeature', 'myFeatureStart', 'myFeatureEnd');`}
363
- {`\nperformance.measure('complexCalc', { start: 'calcStart', end: 'complexCalcDone' });`}
364
- {`\n\n// --- Metrics (custom values) ---`}
365
- {`\nperformance.metric('cacheHitRate', 0.95);`}
366
- {`\nperformance.metric('itemsProcessed', 500);`}
367
- </Text>
368
- </View>
369
- </View>
370
- </CollapsibleSection>
371
-
372
- </ScrollView>
373
- );
374
- };
375
-
376
- const styles = StyleSheet.create({
377
- container: {
378
- flex: 1,
379
- backgroundColor: '#f0f0f0', // Slightly off-white background for the whole view
380
- },
381
- contentContainer: {
382
- paddingBottom: 20,
383
- },
384
- content: {
385
- paddingHorizontal: 15,
386
- paddingVertical: 10, // Reduced vertical padding within content sections
387
- backgroundColor: '#ffffff', // White background for content areas
388
- },
389
- sectionDescription: {
390
- fontSize: 13,
391
- color: '#444', // Darker grey for descriptions
392
- marginBottom: 12,
393
- lineHeight: 18,
394
- },
395
- footnote: {
396
- fontSize: 11,
397
- color: '#777', // Lighter grey for footnotes
398
- marginTop: 8,
399
- fontStyle: 'italic',
400
- },
401
- collapsibleSection: {
402
- marginBottom: 1, // Thinner separator
403
- backgroundColor: '#fff',
404
- borderBottomWidth: 1,
405
- borderBottomColor: '#e5e5e5',
406
- },
407
- sectionHeader: {
408
- flexDirection: 'row',
409
- justifyContent: 'space-between',
410
- alignItems: 'center',
411
- paddingVertical: 12, // Adjusted padding
412
- paddingHorizontal: 15,
413
- backgroundColor: '#f8f8f8', // Slightly lighter header background
414
- },
415
- sectionTitle: {
416
- fontSize: 15,
417
- fontWeight: '600', // Semi-bold title
418
- color: '#333',
419
- },
420
- expandIcon: {
421
- fontSize: 16, // Slightly larger icon
422
- color: '#555',
423
- },
424
- metricsGrid: {
425
- flexDirection: 'row',
426
- flexWrap: 'wrap',
427
- justifyContent: 'space-between', // Space between items
428
- marginBottom: 5,
429
- },
430
- metricItem: {
431
- width: '31%', // Adjusted for spacing
432
- backgroundColor: '#f5f9ff', // Lighter blue background
433
- borderRadius: 6,
434
- paddingVertical: 10,
435
- paddingHorizontal: 5,
436
- marginBottom: 10,
437
- alignItems: 'center',
438
- minHeight: 65, // Ensure consistent height
439
- justifyContent: 'center',
440
- borderWidth: 1,
441
- borderColor: '#e0e8f0',
442
- },
443
- metricValue: {
444
- fontSize: 15,
445
- fontWeight: '600',
446
- color: '#0052cc', // Darker blue for value
447
- marginBottom: 4,
448
- textAlign: 'center',
449
- },
450
- metricLabel: {
451
- fontSize: 11,
452
- color: '#505050', // Darker grey label
453
- textAlign: 'center',
454
- fontWeight: '500',
455
- },
456
- dataSection: {
457
- // Removed marginBottom, handled by collapsibleSection border
458
- },
459
- dataSectionHeader: {
460
- flexDirection: 'row',
461
- justifyContent: 'space-between',
462
- alignItems: 'center',
463
- marginBottom: 8,
464
- paddingBottom: 6,
465
- borderBottomWidth: 1,
466
- borderBottomColor: '#eee',
467
- },
468
- dataSectionTitle: {
469
- fontSize: 14,
470
- fontWeight: '600',
471
- color: '#444',
472
- },
473
- dataContentWrapper: {
474
- flex: 1,
475
- maxHeight: 350, // Limit height of scrollable area
476
- },
477
- dataContent: {
478
- flexGrow: 1,
479
- backgroundColor: theme.base00, // Use theme background
480
- padding: 10,
481
- borderRadius: 4,
482
- },
483
- noEntriesText: {
484
- color: theme.base04, // Use a theme color for placeholder text
485
- fontStyle: 'italic',
486
- textAlign: 'center',
487
- paddingVertical: 20,
488
- },
489
- copyButton: {
490
- backgroundColor: '#e8e8e8', // Lighter grey button
491
- paddingHorizontal: 12, // More padding
492
- paddingVertical: 6,
493
- borderRadius: 4,
494
- },
495
- copyButtonText: {
496
- fontSize: 12,
497
- color: '#444', // Darker text
498
- fontWeight: '500',
499
- },
500
- codeBlockContainer: {
501
- backgroundColor: '#f7f7f7',
502
- padding: 15,
503
- borderRadius: 4,
504
- borderWidth: 1,
505
- borderColor: '#e0e0e0',
506
- },
507
- codeText: {
508
- fontSize: 12.5, // Slightly smaller code font
509
- color: '#333',
510
- fontFamily: Platform.OS === 'ios' ? 'Courier New' : 'monospace',
511
- lineHeight: 17,
512
- },
513
- });
514
-
515
- export default SubViewPerformance;