react-native-debug-toolkit 0.6.4 → 2.1.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/LICENSE +21 -0
- package/README.md +149 -211
- package/README.zh-CN.md +150 -171
- package/lib/commonjs/components/ClipboardTab.js +91 -0
- package/lib/commonjs/components/ClipboardTab.js.map +1 -0
- package/lib/commonjs/components/ConsoleLogTab.js +162 -0
- package/lib/commonjs/components/ConsoleLogTab.js.map +1 -0
- package/lib/commonjs/components/DebugPanel.js +230 -0
- package/lib/commonjs/components/DebugPanel.js.map +1 -0
- package/lib/commonjs/components/DebugView.js +66 -0
- package/lib/commonjs/components/DebugView.js.map +1 -0
- package/lib/commonjs/components/EnvironmentTab.js +287 -0
- package/lib/commonjs/components/EnvironmentTab.js.map +1 -0
- package/lib/commonjs/components/FeatureTabBar.js +182 -0
- package/lib/commonjs/components/FeatureTabBar.js.map +1 -0
- package/lib/commonjs/components/FloatIcon.js +187 -0
- package/lib/commonjs/components/FloatIcon.js.map +1 -0
- package/lib/commonjs/components/FloatPanelView.js +214 -0
- package/lib/commonjs/components/FloatPanelView.js.map +1 -0
- package/lib/commonjs/components/NavigationLogTab.js +131 -0
- package/lib/commonjs/components/NavigationLogTab.js.map +1 -0
- package/lib/commonjs/components/NetworkLogTab.js +404 -0
- package/lib/commonjs/components/NetworkLogTab.js.map +1 -0
- package/lib/commonjs/components/ThirdPartyLibsTab.js +97 -0
- package/lib/commonjs/components/ThirdPartyLibsTab.js.map +1 -0
- package/lib/commonjs/components/TrackLogTab.js +230 -0
- package/lib/commonjs/components/TrackLogTab.js.map +1 -0
- package/lib/commonjs/components/ZustandLogTab.js +311 -0
- package/lib/commonjs/components/ZustandLogTab.js.map +1 -0
- package/lib/commonjs/components/shared/CollapsibleSection.js +84 -0
- package/lib/commonjs/components/shared/CollapsibleSection.js.map +1 -0
- package/lib/commonjs/components/shared/CopyButton.js +64 -0
- package/lib/commonjs/components/shared/CopyButton.js.map +1 -0
- package/lib/commonjs/components/shared/JsonView.js +157 -0
- package/lib/commonjs/components/shared/JsonView.js.map +1 -0
- package/lib/commonjs/components/shared/LogListScreen.js +174 -0
- package/lib/commonjs/components/shared/LogListScreen.js.map +1 -0
- package/lib/commonjs/core/DebugToolkit.js +122 -0
- package/lib/commonjs/core/DebugToolkit.js.map +1 -0
- package/lib/commonjs/core/DebugToolkitProvider.js +66 -0
- package/lib/commonjs/core/DebugToolkitProvider.js.map +1 -0
- package/lib/commonjs/features/ClipboardFeature.js +21 -0
- package/lib/commonjs/features/ClipboardFeature.js.map +1 -0
- package/lib/commonjs/features/ConsoleLogFeature.js +115 -0
- package/lib/commonjs/features/ConsoleLogFeature.js.map +1 -0
- package/lib/commonjs/features/EnvironmentFeature.js +160 -0
- package/lib/commonjs/features/EnvironmentFeature.js.map +1 -0
- package/lib/commonjs/features/NavigationLogFeature.js +39 -0
- package/lib/commonjs/features/NavigationLogFeature.js.map +1 -0
- package/lib/commonjs/features/NetworkFeature.js +107 -0
- package/lib/commonjs/features/NetworkFeature.js.map +1 -0
- package/lib/commonjs/features/ThirdPartyLibsFeature.js +51 -0
- package/lib/commonjs/features/ThirdPartyLibsFeature.js.map +1 -0
- package/lib/commonjs/features/TrackFeature.js +34 -0
- package/lib/commonjs/features/TrackFeature.js.map +1 -0
- package/lib/commonjs/features/ZustandLogFeature.js +59 -0
- package/lib/commonjs/features/ZustandLogFeature.js.map +1 -0
- package/lib/commonjs/hooks/useNavigationLogger.js +78 -0
- package/lib/commonjs/hooks/useNavigationLogger.js.map +1 -0
- package/lib/commonjs/hooks/useSlideDetailAnimation.js +53 -0
- package/lib/commonjs/hooks/useSlideDetailAnimation.js.map +1 -0
- package/lib/commonjs/index.js +152 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/initialize.js +84 -0
- package/lib/commonjs/initialize.js.map +1 -0
- package/lib/commonjs/interceptors/networkInterceptor.js +466 -0
- package/lib/commonjs/interceptors/networkInterceptor.js.map +1 -0
- package/lib/commonjs/native/NativeDebugLibs.js +58 -0
- package/lib/commonjs/native/NativeDebugLibs.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/types/index.js +6 -0
- package/lib/commonjs/types/index.js.map +1 -0
- package/lib/commonjs/utils/colors.js +48 -0
- package/lib/commonjs/utils/colors.js.map +1 -0
- package/lib/commonjs/utils/copyToComputer.js +97 -0
- package/lib/commonjs/utils/copyToComputer.js.map +1 -0
- package/lib/commonjs/utils/createChannelFeature.js +48 -0
- package/lib/commonjs/utils/createChannelFeature.js.map +1 -0
- package/lib/commonjs/utils/createEventChannel.js +21 -0
- package/lib/commonjs/utils/createEventChannel.js.map +1 -0
- package/lib/commonjs/utils/createObservableStore.js +38 -0
- package/lib/commonjs/utils/createObservableStore.js.map +1 -0
- package/lib/commonjs/utils/layout.js +8 -0
- package/lib/commonjs/utils/layout.js.map +1 -0
- package/lib/commonjs/utils/safeStringify.js +27 -0
- package/lib/commonjs/utils/safeStringify.js.map +1 -0
- package/lib/commonjs/utils/urlRewriterRegistry.js +14 -0
- package/lib/commonjs/utils/urlRewriterRegistry.js.map +1 -0
- package/lib/module/components/ClipboardTab.js +86 -0
- package/lib/module/components/ClipboardTab.js.map +1 -0
- package/lib/module/components/ConsoleLogTab.js +157 -0
- package/lib/module/components/ConsoleLogTab.js.map +1 -0
- package/lib/module/components/DebugPanel.js +225 -0
- package/lib/module/components/DebugPanel.js.map +1 -0
- package/lib/module/components/DebugView.js +61 -0
- package/lib/module/components/DebugView.js.map +1 -0
- package/lib/module/components/EnvironmentTab.js +282 -0
- package/lib/module/components/EnvironmentTab.js.map +1 -0
- package/lib/module/components/FeatureTabBar.js +177 -0
- package/lib/module/components/FeatureTabBar.js.map +1 -0
- package/lib/module/components/FloatIcon.js +182 -0
- package/lib/module/components/FloatIcon.js.map +1 -0
- package/lib/module/components/FloatPanelView.js +209 -0
- package/lib/module/components/FloatPanelView.js.map +1 -0
- package/lib/module/components/NavigationLogTab.js +126 -0
- package/lib/module/components/NavigationLogTab.js.map +1 -0
- package/lib/module/components/NetworkLogTab.js +399 -0
- package/lib/module/components/NetworkLogTab.js.map +1 -0
- package/lib/module/components/ThirdPartyLibsTab.js +91 -0
- package/lib/module/components/ThirdPartyLibsTab.js.map +1 -0
- package/lib/module/components/TrackLogTab.js +225 -0
- package/lib/module/components/TrackLogTab.js.map +1 -0
- package/lib/module/components/ZustandLogTab.js +306 -0
- package/lib/module/components/ZustandLogTab.js.map +1 -0
- package/lib/module/components/shared/CollapsibleSection.js +78 -0
- package/lib/module/components/shared/CollapsibleSection.js.map +1 -0
- package/lib/module/components/shared/CopyButton.js +58 -0
- package/lib/module/components/shared/CopyButton.js.map +1 -0
- package/lib/module/components/shared/JsonView.js +152 -0
- package/lib/module/components/shared/JsonView.js.map +1 -0
- package/lib/module/components/shared/LogListScreen.js +169 -0
- package/lib/module/components/shared/LogListScreen.js.map +1 -0
- package/lib/module/core/DebugToolkit.js +118 -0
- package/lib/module/core/DebugToolkit.js.map +1 -0
- package/lib/module/core/DebugToolkitProvider.js +60 -0
- package/lib/module/core/DebugToolkitProvider.js.map +1 -0
- package/lib/module/features/ClipboardFeature.js +16 -0
- package/lib/module/features/ClipboardFeature.js.map +1 -0
- package/lib/module/features/ConsoleLogFeature.js +109 -0
- package/lib/module/features/ConsoleLogFeature.js.map +1 -0
- package/lib/module/features/EnvironmentFeature.js +156 -0
- package/lib/module/features/EnvironmentFeature.js.map +1 -0
- package/lib/module/features/NavigationLogFeature.js +32 -0
- package/lib/module/features/NavigationLogFeature.js.map +1 -0
- package/lib/module/features/NetworkFeature.js +101 -0
- package/lib/module/features/NetworkFeature.js.map +1 -0
- package/lib/module/features/ThirdPartyLibsFeature.js +46 -0
- package/lib/module/features/ThirdPartyLibsFeature.js.map +1 -0
- package/lib/module/features/TrackFeature.js +27 -0
- package/lib/module/features/TrackFeature.js.map +1 -0
- package/lib/module/features/ZustandLogFeature.js +53 -0
- package/lib/module/features/ZustandLogFeature.js.map +1 -0
- package/lib/module/hooks/useNavigationLogger.js +74 -0
- package/lib/module/hooks/useNavigationLogger.js.map +1 -0
- package/lib/module/hooks/useSlideDetailAnimation.js +50 -0
- package/lib/module/hooks/useSlideDetailAnimation.js.map +1 -0
- package/lib/module/index.js +28 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/initialize.js +80 -0
- package/lib/module/initialize.js.map +1 -0
- package/lib/module/interceptors/networkInterceptor.js +460 -0
- package/lib/module/interceptors/networkInterceptor.js.map +1 -0
- package/lib/module/native/NativeDebugLibs.js +54 -0
- package/lib/module/native/NativeDebugLibs.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/types/index.js +4 -0
- package/lib/module/types/index.js.map +1 -0
- package/lib/module/utils/colors.js +43 -0
- package/lib/module/utils/colors.js.map +1 -0
- package/lib/module/utils/copyToComputer.js +91 -0
- package/lib/module/utils/copyToComputer.js.map +1 -0
- package/lib/module/utils/createChannelFeature.js +44 -0
- package/lib/module/utils/createChannelFeature.js.map +1 -0
- package/lib/module/utils/createEventChannel.js +17 -0
- package/lib/module/utils/createEventChannel.js.map +1 -0
- package/lib/module/utils/createObservableStore.js +34 -0
- package/lib/module/utils/createObservableStore.js.map +1 -0
- package/lib/module/utils/layout.js +4 -0
- package/lib/module/utils/layout.js.map +1 -0
- package/lib/module/utils/safeStringify.js +23 -0
- package/lib/module/utils/safeStringify.js.map +1 -0
- package/lib/module/utils/urlRewriterRegistry.js +10 -0
- package/lib/module/utils/urlRewriterRegistry.js.map +1 -0
- package/lib/typescript/src/components/ClipboardTab.d.ts +4 -0
- package/lib/typescript/src/components/ClipboardTab.d.ts.map +1 -0
- package/lib/typescript/src/components/ConsoleLogTab.d.ts +4 -0
- package/lib/typescript/src/components/ConsoleLogTab.d.ts.map +1 -0
- package/lib/typescript/src/components/DebugPanel.d.ts +9 -0
- package/lib/typescript/src/components/DebugPanel.d.ts.map +1 -0
- package/lib/typescript/src/components/DebugView.d.ts +19 -0
- package/lib/typescript/src/components/DebugView.d.ts.map +1 -0
- package/lib/typescript/src/components/EnvironmentTab.d.ts +4 -0
- package/lib/typescript/src/components/EnvironmentTab.d.ts.map +1 -0
- package/lib/typescript/src/components/FeatureTabBar.d.ts +13 -0
- package/lib/typescript/src/components/FeatureTabBar.d.ts.map +1 -0
- package/lib/typescript/src/components/FloatIcon.d.ts +12 -0
- package/lib/typescript/src/components/FloatIcon.d.ts.map +1 -0
- package/lib/typescript/src/components/FloatPanelView.d.ts +9 -0
- package/lib/typescript/src/components/FloatPanelView.d.ts.map +1 -0
- package/lib/typescript/src/components/NavigationLogTab.d.ts +4 -0
- package/lib/typescript/src/components/NavigationLogTab.d.ts.map +1 -0
- package/lib/typescript/src/components/NetworkLogTab.d.ts +4 -0
- package/lib/typescript/src/components/NetworkLogTab.d.ts.map +1 -0
- package/lib/typescript/src/components/ThirdPartyLibsTab.d.ts +4 -0
- package/lib/typescript/src/components/ThirdPartyLibsTab.d.ts.map +1 -0
- package/lib/typescript/src/components/TrackLogTab.d.ts +4 -0
- package/lib/typescript/src/components/TrackLogTab.d.ts.map +1 -0
- package/lib/typescript/src/components/ZustandLogTab.d.ts +4 -0
- package/lib/typescript/src/components/ZustandLogTab.d.ts.map +1 -0
- package/lib/typescript/src/components/shared/CollapsibleSection.d.ts +9 -0
- package/lib/typescript/src/components/shared/CollapsibleSection.d.ts.map +1 -0
- package/lib/typescript/src/components/shared/CopyButton.d.ts +12 -0
- package/lib/typescript/src/components/shared/CopyButton.d.ts.map +1 -0
- package/lib/typescript/src/components/shared/JsonView.d.ts +6 -0
- package/lib/typescript/src/components/shared/JsonView.d.ts.map +1 -0
- package/lib/typescript/src/components/shared/LogListScreen.d.ts +21 -0
- package/lib/typescript/src/components/shared/LogListScreen.d.ts.map +1 -0
- package/lib/typescript/src/core/DebugToolkit.d.ts +20 -0
- package/lib/typescript/src/core/DebugToolkit.d.ts.map +1 -0
- package/lib/typescript/src/core/DebugToolkitProvider.d.ts +15 -0
- package/lib/typescript/src/core/DebugToolkitProvider.d.ts.map +1 -0
- package/lib/typescript/src/features/ClipboardFeature.d.ts +7 -0
- package/lib/typescript/src/features/ClipboardFeature.d.ts.map +1 -0
- package/lib/typescript/src/features/ConsoleLogFeature.d.ts +9 -0
- package/lib/typescript/src/features/ConsoleLogFeature.d.ts.map +1 -0
- package/lib/typescript/src/features/EnvironmentFeature.d.ts +8 -0
- package/lib/typescript/src/features/EnvironmentFeature.d.ts.map +1 -0
- package/lib/typescript/src/features/NavigationLogFeature.d.ts +10 -0
- package/lib/typescript/src/features/NavigationLogFeature.d.ts.map +1 -0
- package/lib/typescript/src/features/NetworkFeature.d.ts +15 -0
- package/lib/typescript/src/features/NetworkFeature.d.ts.map +1 -0
- package/lib/typescript/src/features/ThirdPartyLibsFeature.d.ts +3 -0
- package/lib/typescript/src/features/ThirdPartyLibsFeature.d.ts.map +1 -0
- package/lib/typescript/src/features/TrackFeature.d.ts +14 -0
- package/lib/typescript/src/features/TrackFeature.d.ts.map +1 -0
- package/lib/typescript/src/features/ZustandLogFeature.d.ts +31 -0
- package/lib/typescript/src/features/ZustandLogFeature.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useNavigationLogger.d.ts +13 -0
- package/lib/typescript/src/hooks/useNavigationLogger.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useSlideDetailAnimation.d.ts +11 -0
- package/lib/typescript/src/hooks/useSlideDetailAnimation.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +26 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/initialize.d.ts +32 -0
- package/lib/typescript/src/initialize.d.ts.map +1 -0
- package/lib/typescript/src/interceptors/networkInterceptor.d.ts +18 -0
- package/lib/typescript/src/interceptors/networkInterceptor.d.ts.map +1 -0
- package/lib/typescript/src/native/NativeDebugLibs.d.ts +11 -0
- package/lib/typescript/src/native/NativeDebugLibs.d.ts.map +1 -0
- package/lib/typescript/src/types/index.d.ts +109 -0
- package/lib/typescript/src/types/index.d.ts.map +1 -0
- package/lib/typescript/src/utils/colors.d.ts +21 -0
- package/lib/typescript/src/utils/colors.d.ts.map +1 -0
- package/lib/typescript/src/utils/copyToComputer.d.ts +30 -0
- package/lib/typescript/src/utils/copyToComputer.d.ts.map +1 -0
- package/lib/typescript/src/utils/createChannelFeature.d.ts +18 -0
- package/lib/typescript/src/utils/createChannelFeature.d.ts.map +1 -0
- package/lib/typescript/src/utils/createEventChannel.d.ts +7 -0
- package/lib/typescript/src/utils/createEventChannel.d.ts.map +1 -0
- package/lib/typescript/src/utils/createObservableStore.d.ts +9 -0
- package/lib/typescript/src/utils/createObservableStore.d.ts.map +1 -0
- package/lib/typescript/src/utils/layout.d.ts +2 -0
- package/lib/typescript/src/utils/layout.d.ts.map +1 -0
- package/lib/typescript/src/utils/safeStringify.d.ts +6 -0
- package/lib/typescript/src/utils/safeStringify.d.ts.map +1 -0
- package/lib/typescript/src/utils/urlRewriterRegistry.d.ts +7 -0
- package/lib/typescript/src/utils/urlRewriterRegistry.d.ts.map +1 -0
- package/package.json +67 -24
- package/src/components/ClipboardTab.tsx +81 -0
- package/src/components/ConsoleLogTab.tsx +95 -0
- package/src/components/DebugPanel.tsx +215 -0
- package/src/components/DebugView.tsx +80 -0
- package/src/components/EnvironmentTab.tsx +276 -0
- package/src/components/FeatureTabBar.tsx +204 -0
- package/src/components/FloatIcon.tsx +171 -0
- package/src/components/FloatPanelView.tsx +202 -0
- package/src/components/NavigationLogTab.tsx +66 -0
- package/src/components/NetworkLogTab.tsx +270 -0
- package/src/components/ThirdPartyLibsTab.tsx +63 -0
- package/src/components/TrackLogTab.tsx +110 -0
- package/src/components/ZustandLogTab.tsx +203 -0
- package/src/components/shared/CollapsibleSection.tsx +78 -0
- package/src/components/shared/CopyButton.tsx +68 -0
- package/src/components/shared/JsonView.tsx +125 -0
- package/src/components/shared/LogListScreen.tsx +164 -0
- package/src/core/DebugToolkit.tsx +150 -0
- package/src/core/DebugToolkitProvider.tsx +83 -0
- package/src/features/ClipboardFeature.ts +15 -0
- package/src/features/ConsoleLogFeature.ts +116 -0
- package/src/features/EnvironmentFeature.ts +186 -0
- package/src/features/NavigationLogFeature.ts +44 -0
- package/src/features/NetworkFeature.ts +126 -0
- package/src/features/ThirdPartyLibsFeature.ts +42 -0
- package/src/features/TrackFeature.ts +34 -0
- package/src/features/ZustandLogFeature.ts +101 -0
- package/src/hooks/useNavigationLogger.ts +102 -0
- package/src/hooks/useSlideDetailAnimation.ts +45 -0
- package/src/index.ts +48 -0
- package/src/initialize.ts +122 -0
- package/src/interceptors/networkInterceptor.ts +646 -0
- package/src/native/NativeDebugLibs.ts +74 -0
- package/src/types/index.ts +127 -0
- package/src/utils/colors.ts +38 -0
- package/src/utils/copyToComputer.ts +104 -0
- package/src/utils/createChannelFeature.ts +55 -0
- package/src/utils/createEventChannel.ts +22 -0
- package/src/utils/createObservableStore.ts +42 -0
- package/src/utils/layout.ts +1 -0
- package/src/utils/safeStringify.ts +25 -0
- package/src/utils/urlRewriterRegistry.ts +10 -0
- package/.cursor/rules/react-native.mdc +0 -41
- package/index.js +0 -41
- package/ios/BuildTypeModule.h +0 -9
- package/ios/BuildTypeModule.m +0 -42
- package/ios/RNDebugLibs.h +0 -10
- package/ios/RNDebugLibs.m +0 -79
- package/lib/DebugToolKit.js +0 -126
- package/lib/EnvironmentManager.ts +0 -80
- package/lib/NativeDebugLibs.js +0 -67
- package/lib/features/ConsoleLogFeature.js +0 -70
- package/lib/features/NavigationLogFeature.js +0 -45
- package/lib/features/NetworkFeature.js +0 -389
- package/lib/features/PerformanceFeature.js +0 -390
- package/lib/features/ThirdPartyLibsFeature.js +0 -63
- package/lib/features/TrackFeature.js +0 -94
- package/lib/features/ZustandLogFeature.js +0 -44
- package/lib/hooks/useNavigationLogger.js +0 -92
- package/lib/index.js +0 -114
- package/lib/navigation/NavigationLogger.js +0 -1
- package/lib/types/TrackTypes.ts +0 -92
- package/lib/utils/DebugConst.js +0 -67
- package/lib/utils/StorageUtils.js +0 -80
- package/lib/views/ConsoleLogDetails.js +0 -314
- package/lib/views/FloatPanelView.js +0 -697
- package/lib/views/HttpLogDetails.js +0 -648
- package/lib/views/NavigationLogDetails.js +0 -302
- package/lib/views/RestartModal.js +0 -75
- package/lib/views/SubViewConsoleLogs.js +0 -209
- package/lib/views/SubViewEnvironment.js +0 -73
- package/lib/views/SubViewHTTPLogs.js +0 -235
- package/lib/views/SubViewNavigationLogs.js +0 -199
- package/lib/views/SubViewPerformance.js +0 -515
- package/lib/views/SubViewThirdPartyLibs.js +0 -239
- package/lib/views/SubViewTrackLogs.js +0 -318
- package/lib/views/SubViewZustandLogs.js +0 -279
- package/lib/views/TabView.js +0 -66
- package/lib/views/TrackLogDetails.js +0 -481
- package/lib/views/ZustandLogDetails.js +0 -355
- package/react-native-debug-toolkit.podspec +0 -25
- package/react-native.config.js +0 -18
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {
|
|
3
|
+
View,
|
|
4
|
+
Text,
|
|
5
|
+
TouchableOpacity,
|
|
6
|
+
StyleSheet,
|
|
7
|
+
ScrollView,
|
|
8
|
+
} from 'react-native';
|
|
9
|
+
import { Colors } from '../utils/colors';
|
|
10
|
+
import type { DebugFeatureRenderProps, EnvironmentState } from '../types';
|
|
11
|
+
import type { EnvironmentFeatureAPI } from '../features/EnvironmentFeature';
|
|
12
|
+
|
|
13
|
+
const DEFAULT_COLORS: Record<string, string> = {
|
|
14
|
+
dev: '#34C759',
|
|
15
|
+
development: '#34C759',
|
|
16
|
+
staging: '#FF9500',
|
|
17
|
+
stage: '#FF9500',
|
|
18
|
+
production: '#FF3B30',
|
|
19
|
+
prod: '#FF3B30',
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export const EnvironmentTab: React.FC<DebugFeatureRenderProps<EnvironmentState>> = React.memo(({
|
|
23
|
+
data,
|
|
24
|
+
feature,
|
|
25
|
+
}) => {
|
|
26
|
+
const state = data[0];
|
|
27
|
+
if (!state || state.environments.length === 0) {
|
|
28
|
+
return (
|
|
29
|
+
<View style={styles.container}>
|
|
30
|
+
<View style={styles.emptyContainer}>
|
|
31
|
+
<Text style={styles.emptyIcon}>⚙</Text>
|
|
32
|
+
<Text style={styles.emptyTitle}>No Environments</Text>
|
|
33
|
+
<Text style={styles.emptyDesc}>
|
|
34
|
+
Call{'\n'}
|
|
35
|
+
<Text style={styles.code}>registerEnvironments([...])</Text>{'\n'}
|
|
36
|
+
to configure environments.
|
|
37
|
+
</Text>
|
|
38
|
+
</View>
|
|
39
|
+
</View>
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const { environments, currentEnvironmentId } = state;
|
|
44
|
+
const envFeature = feature as unknown as EnvironmentFeatureAPI;
|
|
45
|
+
|
|
46
|
+
const handleSelect = (envId: string) => {
|
|
47
|
+
const nextId = currentEnvironmentId === envId ? null : envId;
|
|
48
|
+
envFeature.switchEnvironment?.(nextId);
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const activeEnv = environments.find((e) => e.id === currentEnvironmentId);
|
|
52
|
+
|
|
53
|
+
return (
|
|
54
|
+
<View style={styles.container}>
|
|
55
|
+
<View style={styles.headerSection}>
|
|
56
|
+
<Text style={styles.sectionTitle}>Switch Environment</Text>
|
|
57
|
+
<Text style={styles.sectionDesc}>
|
|
58
|
+
Rewrite API host in outgoing requests. Only registered hosts are affected.
|
|
59
|
+
</Text>
|
|
60
|
+
</View>
|
|
61
|
+
|
|
62
|
+
<ScrollView style={styles.list} contentContainerStyle={styles.listContent}>
|
|
63
|
+
<View style={styles.groupedCard}>
|
|
64
|
+
{environments.map((env, index) => {
|
|
65
|
+
const isActive = currentEnvironmentId === env.id;
|
|
66
|
+
const color = env.color || DEFAULT_COLORS[env.id.toLowerCase()] || Colors.primary;
|
|
67
|
+
|
|
68
|
+
return (
|
|
69
|
+
<TouchableOpacity
|
|
70
|
+
key={env.id}
|
|
71
|
+
style={[
|
|
72
|
+
styles.envItem,
|
|
73
|
+
isActive && styles.envItemActive,
|
|
74
|
+
index < environments.length - 1 && styles.envItemSeparator,
|
|
75
|
+
]}
|
|
76
|
+
onPress={() => handleSelect(env.id)}
|
|
77
|
+
activeOpacity={0.5}
|
|
78
|
+
>
|
|
79
|
+
<View style={styles.envRow}>
|
|
80
|
+
<View style={[styles.colorDot, { backgroundColor: color }]} />
|
|
81
|
+
<View style={styles.envInfo}>
|
|
82
|
+
<Text style={styles.envLabel}>{env.label}</Text>
|
|
83
|
+
<Text style={styles.envHost} numberOfLines={1}>
|
|
84
|
+
{env.host}
|
|
85
|
+
</Text>
|
|
86
|
+
</View>
|
|
87
|
+
{isActive && (
|
|
88
|
+
<Text style={styles.checkmark}>✓</Text>
|
|
89
|
+
)}
|
|
90
|
+
</View>
|
|
91
|
+
</TouchableOpacity>
|
|
92
|
+
);
|
|
93
|
+
})}
|
|
94
|
+
</View>
|
|
95
|
+
</ScrollView>
|
|
96
|
+
|
|
97
|
+
{activeEnv ? (
|
|
98
|
+
<View style={styles.footer}>
|
|
99
|
+
<View style={styles.footerInfo}>
|
|
100
|
+
<View style={styles.footerActiveIndicator}>
|
|
101
|
+
<View style={[styles.footerDot, { backgroundColor: activeEnv.color || DEFAULT_COLORS[activeEnv.id.toLowerCase()] || Colors.primary }]} />
|
|
102
|
+
<Text style={styles.footerLabel}>Active</Text>
|
|
103
|
+
</View>
|
|
104
|
+
<Text style={styles.footerValue}>{activeEnv.label}</Text>
|
|
105
|
+
</View>
|
|
106
|
+
<TouchableOpacity
|
|
107
|
+
style={styles.resetButton}
|
|
108
|
+
onPress={() => envFeature.switchEnvironment?.(null)}
|
|
109
|
+
activeOpacity={0.7}
|
|
110
|
+
>
|
|
111
|
+
<Text style={styles.resetButtonText}>Reset</Text>
|
|
112
|
+
</TouchableOpacity>
|
|
113
|
+
</View>
|
|
114
|
+
) : null}
|
|
115
|
+
</View>
|
|
116
|
+
);
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
const styles = StyleSheet.create({
|
|
120
|
+
container: {
|
|
121
|
+
flex: 1,
|
|
122
|
+
backgroundColor: Colors.background,
|
|
123
|
+
},
|
|
124
|
+
|
|
125
|
+
// Empty state
|
|
126
|
+
emptyContainer: {
|
|
127
|
+
flex: 1,
|
|
128
|
+
alignItems: 'center',
|
|
129
|
+
justifyContent: 'center',
|
|
130
|
+
paddingHorizontal: 30,
|
|
131
|
+
},
|
|
132
|
+
emptyIcon: {
|
|
133
|
+
fontSize: 36,
|
|
134
|
+
color: Colors.textLight,
|
|
135
|
+
marginBottom: 8,
|
|
136
|
+
},
|
|
137
|
+
emptyTitle: {
|
|
138
|
+
fontSize: 20,
|
|
139
|
+
fontWeight: '700',
|
|
140
|
+
color: Colors.text,
|
|
141
|
+
marginBottom: 8,
|
|
142
|
+
},
|
|
143
|
+
emptyDesc: {
|
|
144
|
+
fontSize: 14,
|
|
145
|
+
color: Colors.textSecondary,
|
|
146
|
+
textAlign: 'center',
|
|
147
|
+
lineHeight: 22,
|
|
148
|
+
},
|
|
149
|
+
code: {
|
|
150
|
+
fontFamily: 'monospace',
|
|
151
|
+
fontWeight: '600',
|
|
152
|
+
color: Colors.primary,
|
|
153
|
+
},
|
|
154
|
+
|
|
155
|
+
// Header
|
|
156
|
+
headerSection: {
|
|
157
|
+
paddingHorizontal: 16,
|
|
158
|
+
paddingTop: 20,
|
|
159
|
+
paddingBottom: 14,
|
|
160
|
+
},
|
|
161
|
+
sectionTitle: {
|
|
162
|
+
fontSize: 13,
|
|
163
|
+
fontWeight: '600',
|
|
164
|
+
color: Colors.textSecondary,
|
|
165
|
+
textTransform: 'uppercase',
|
|
166
|
+
marginBottom: 6,
|
|
167
|
+
},
|
|
168
|
+
sectionDesc: {
|
|
169
|
+
fontSize: 14,
|
|
170
|
+
color: Colors.textSecondary,
|
|
171
|
+
lineHeight: 20,
|
|
172
|
+
},
|
|
173
|
+
|
|
174
|
+
// Grouped list (iOS Settings style)
|
|
175
|
+
list: {
|
|
176
|
+
flex: 1,
|
|
177
|
+
},
|
|
178
|
+
listContent: {
|
|
179
|
+
paddingHorizontal: 16,
|
|
180
|
+
paddingBottom: 16,
|
|
181
|
+
},
|
|
182
|
+
groupedCard: {
|
|
183
|
+
backgroundColor: Colors.surface,
|
|
184
|
+
borderRadius: 12,
|
|
185
|
+
overflow: 'hidden',
|
|
186
|
+
},
|
|
187
|
+
envItem: {
|
|
188
|
+
paddingHorizontal: 16,
|
|
189
|
+
paddingVertical: 14,
|
|
190
|
+
},
|
|
191
|
+
envItemActive: {
|
|
192
|
+
backgroundColor: 'rgba(0,122,255,0.03)',
|
|
193
|
+
},
|
|
194
|
+
envItemSeparator: {
|
|
195
|
+
borderBottomWidth: StyleSheet.hairlineWidth,
|
|
196
|
+
borderBottomColor: Colors.border,
|
|
197
|
+
marginLeft: 48,
|
|
198
|
+
},
|
|
199
|
+
envRow: {
|
|
200
|
+
flexDirection: 'row',
|
|
201
|
+
alignItems: 'center',
|
|
202
|
+
},
|
|
203
|
+
colorDot: {
|
|
204
|
+
width: 10,
|
|
205
|
+
height: 10,
|
|
206
|
+
borderRadius: 5,
|
|
207
|
+
marginRight: 14,
|
|
208
|
+
},
|
|
209
|
+
envInfo: {
|
|
210
|
+
flex: 1,
|
|
211
|
+
},
|
|
212
|
+
envLabel: {
|
|
213
|
+
fontSize: 16,
|
|
214
|
+
fontWeight: '500',
|
|
215
|
+
color: Colors.text,
|
|
216
|
+
},
|
|
217
|
+
envHost: {
|
|
218
|
+
fontSize: 13,
|
|
219
|
+
color: Colors.textSecondary,
|
|
220
|
+
marginTop: 2,
|
|
221
|
+
},
|
|
222
|
+
checkmark: {
|
|
223
|
+
fontSize: 18,
|
|
224
|
+
fontWeight: '600',
|
|
225
|
+
color: Colors.primary,
|
|
226
|
+
marginLeft: 8,
|
|
227
|
+
},
|
|
228
|
+
|
|
229
|
+
// Footer
|
|
230
|
+
footer: {
|
|
231
|
+
flexDirection: 'row',
|
|
232
|
+
alignItems: 'center',
|
|
233
|
+
justifyContent: 'space-between',
|
|
234
|
+
paddingHorizontal: 16,
|
|
235
|
+
paddingVertical: 14,
|
|
236
|
+
backgroundColor: Colors.surface,
|
|
237
|
+
borderTopWidth: StyleSheet.hairlineWidth,
|
|
238
|
+
borderTopColor: Colors.border,
|
|
239
|
+
},
|
|
240
|
+
footerInfo: {
|
|
241
|
+
flex: 1,
|
|
242
|
+
},
|
|
243
|
+
footerActiveIndicator: {
|
|
244
|
+
flexDirection: 'row',
|
|
245
|
+
alignItems: 'center',
|
|
246
|
+
gap: 6,
|
|
247
|
+
marginBottom: 2,
|
|
248
|
+
},
|
|
249
|
+
footerDot: {
|
|
250
|
+
width: 8,
|
|
251
|
+
height: 8,
|
|
252
|
+
borderRadius: 4,
|
|
253
|
+
},
|
|
254
|
+
footerLabel: {
|
|
255
|
+
fontSize: 11,
|
|
256
|
+
color: Colors.textSecondary,
|
|
257
|
+
fontWeight: '600',
|
|
258
|
+
textTransform: 'uppercase',
|
|
259
|
+
},
|
|
260
|
+
footerValue: {
|
|
261
|
+
fontSize: 17,
|
|
262
|
+
fontWeight: '600',
|
|
263
|
+
color: Colors.text,
|
|
264
|
+
},
|
|
265
|
+
resetButton: {
|
|
266
|
+
backgroundColor: 'rgba(255,59,48,0.08)',
|
|
267
|
+
paddingHorizontal: 20,
|
|
268
|
+
paddingVertical: 10,
|
|
269
|
+
borderRadius: 10,
|
|
270
|
+
},
|
|
271
|
+
resetButtonText: {
|
|
272
|
+
color: Colors.error,
|
|
273
|
+
fontSize: 15,
|
|
274
|
+
fontWeight: '600',
|
|
275
|
+
},
|
|
276
|
+
});
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import React, { useCallback, useEffect, useRef, useState } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
View,
|
|
4
|
+
Text,
|
|
5
|
+
StyleSheet,
|
|
6
|
+
Animated,
|
|
7
|
+
ScrollView,
|
|
8
|
+
TouchableOpacity,
|
|
9
|
+
} from 'react-native';
|
|
10
|
+
import { Colors } from '../utils/colors';
|
|
11
|
+
|
|
12
|
+
export interface TabItem {
|
|
13
|
+
id: string;
|
|
14
|
+
label: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
interface FeatureTabBarProps {
|
|
18
|
+
tabs: TabItem[];
|
|
19
|
+
activeIndex: number;
|
|
20
|
+
onSelectTab: (index: number) => void;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function FeatureTabBar({ tabs, activeIndex, onSelectTab }: FeatureTabBarProps) {
|
|
24
|
+
const [underlineWidth, setUnderlineWidth] = useState(0);
|
|
25
|
+
const underlineTranslateX = useRef(new Animated.Value(0)).current;
|
|
26
|
+
const tabScrollViewRef = useRef<ScrollView>(null);
|
|
27
|
+
const tabLayouts = useRef<Array<{ x: number; width: number }>>([]);
|
|
28
|
+
const tabScrollOffset = useRef(0);
|
|
29
|
+
const tabViewportWidth = useRef(0);
|
|
30
|
+
const tabContentWidth = useRef(0);
|
|
31
|
+
const underlineInit = useRef(false);
|
|
32
|
+
const isSwitching = useRef(false);
|
|
33
|
+
|
|
34
|
+
const maxTabScroll = useCallback(
|
|
35
|
+
() => Math.max(0, tabContentWidth.current - tabViewportWidth.current),
|
|
36
|
+
[],
|
|
37
|
+
);
|
|
38
|
+
const clampScroll = useCallback(
|
|
39
|
+
(offset: number) => Math.min(Math.max(0, offset), maxTabScroll()),
|
|
40
|
+
[maxTabScroll],
|
|
41
|
+
);
|
|
42
|
+
const getTabScrollTarget = useCallback(
|
|
43
|
+
(index: number) => {
|
|
44
|
+
const layout = tabLayouts.current[index];
|
|
45
|
+
return layout ? clampScroll(layout.x - 60) : clampScroll(tabScrollOffset.current);
|
|
46
|
+
},
|
|
47
|
+
[clampScroll],
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
const animateUnderline = useCallback(
|
|
51
|
+
(index: number, scrollOffset?: number) => {
|
|
52
|
+
const layout = tabLayouts.current[index];
|
|
53
|
+
if (!layout) return;
|
|
54
|
+
const offsetX = clampScroll(scrollOffset ?? tabScrollOffset.current);
|
|
55
|
+
setUnderlineWidth(layout.width);
|
|
56
|
+
Animated.spring(underlineTranslateX, {
|
|
57
|
+
toValue: layout.x - offsetX,
|
|
58
|
+
friction: 7,
|
|
59
|
+
tension: 50,
|
|
60
|
+
useNativeDriver: true,
|
|
61
|
+
}).start();
|
|
62
|
+
},
|
|
63
|
+
[clampScroll, underlineTranslateX],
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
const syncUnderlineToActiveTab = useCallback(() => {
|
|
67
|
+
const layout = tabLayouts.current[activeIndex];
|
|
68
|
+
if (!layout) return;
|
|
69
|
+
const clamped = clampScroll(tabScrollOffset.current);
|
|
70
|
+
if (clamped !== tabScrollOffset.current) tabScrollOffset.current = clamped;
|
|
71
|
+
underlineTranslateX.setValue(layout.x - clamped);
|
|
72
|
+
setUnderlineWidth(layout.width);
|
|
73
|
+
}, [activeIndex, clampScroll, underlineTranslateX]);
|
|
74
|
+
|
|
75
|
+
const tryInit = useCallback(() => {
|
|
76
|
+
if (underlineInit.current || tabViewportWidth.current <= 0 || tabContentWidth.current <= 0)
|
|
77
|
+
return;
|
|
78
|
+
const layout = tabLayouts.current[activeIndex];
|
|
79
|
+
if (!layout) return;
|
|
80
|
+
const target = getTabScrollTarget(activeIndex);
|
|
81
|
+
tabScrollOffset.current = target;
|
|
82
|
+
tabScrollViewRef.current?.scrollTo({ x: target, animated: false });
|
|
83
|
+
underlineTranslateX.setValue(layout.x - target);
|
|
84
|
+
setUnderlineWidth(layout.width);
|
|
85
|
+
underlineInit.current = true;
|
|
86
|
+
}, [activeIndex, getTabScrollTarget, underlineTranslateX]);
|
|
87
|
+
|
|
88
|
+
const handleSelectTab = useCallback(
|
|
89
|
+
(index: number) => {
|
|
90
|
+
if (isSwitching.current || index === activeIndex) return;
|
|
91
|
+
isSwitching.current = true;
|
|
92
|
+
|
|
93
|
+
const layout = tabLayouts.current[index];
|
|
94
|
+
if (layout) {
|
|
95
|
+
const target = getTabScrollTarget(index);
|
|
96
|
+
tabScrollOffset.current = target;
|
|
97
|
+
tabScrollViewRef.current?.scrollTo({ x: target, animated: true });
|
|
98
|
+
animateUnderline(index, target);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
onSelectTab(index);
|
|
102
|
+
setTimeout(() => {
|
|
103
|
+
isSwitching.current = false;
|
|
104
|
+
}, 350);
|
|
105
|
+
},
|
|
106
|
+
[activeIndex, animateUnderline, getTabScrollTarget, onSelectTab],
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
// React to external activeIndex changes (e.g. swipe-to-switch)
|
|
110
|
+
useEffect(() => {
|
|
111
|
+
if (!underlineInit.current) return;
|
|
112
|
+
const layout = tabLayouts.current[activeIndex];
|
|
113
|
+
if (!layout) return;
|
|
114
|
+
const target = getTabScrollTarget(activeIndex);
|
|
115
|
+
tabScrollOffset.current = target;
|
|
116
|
+
tabScrollViewRef.current?.scrollTo({ x: target, animated: true });
|
|
117
|
+
animateUnderline(activeIndex, target);
|
|
118
|
+
}, [activeIndex, animateUnderline, getTabScrollTarget]);
|
|
119
|
+
|
|
120
|
+
return (
|
|
121
|
+
<View style={styles.container}>
|
|
122
|
+
<ScrollView
|
|
123
|
+
ref={tabScrollViewRef}
|
|
124
|
+
horizontal
|
|
125
|
+
showsHorizontalScrollIndicator={false}
|
|
126
|
+
contentContainerStyle={styles.scrollContent}
|
|
127
|
+
onLayout={(e) => {
|
|
128
|
+
tabViewportWidth.current = e.nativeEvent.layout.width;
|
|
129
|
+
tryInit();
|
|
130
|
+
}}
|
|
131
|
+
onContentSizeChange={(width) => {
|
|
132
|
+
tabContentWidth.current = width;
|
|
133
|
+
tryInit();
|
|
134
|
+
}}
|
|
135
|
+
onScroll={(e) => {
|
|
136
|
+
tabScrollOffset.current = clampScroll(e.nativeEvent.contentOffset.x);
|
|
137
|
+
if (!isSwitching.current) syncUnderlineToActiveTab();
|
|
138
|
+
}}
|
|
139
|
+
scrollEventThrottle={16}
|
|
140
|
+
>
|
|
141
|
+
{tabs.map((tab, index) => (
|
|
142
|
+
<TouchableOpacity
|
|
143
|
+
key={tab.id}
|
|
144
|
+
style={styles.tab}
|
|
145
|
+
onPress={() => handleSelectTab(index)}
|
|
146
|
+
activeOpacity={0.7}
|
|
147
|
+
onLayout={(e) => {
|
|
148
|
+
const { x, width } = e.nativeEvent.layout;
|
|
149
|
+
tabLayouts.current[index] = { x, width };
|
|
150
|
+
if (index === activeIndex) tryInit();
|
|
151
|
+
}}
|
|
152
|
+
>
|
|
153
|
+
<Text
|
|
154
|
+
style={[styles.tabText, activeIndex === index && styles.activeTabText]}
|
|
155
|
+
numberOfLines={1}
|
|
156
|
+
>
|
|
157
|
+
{tab.label}
|
|
158
|
+
</Text>
|
|
159
|
+
</TouchableOpacity>
|
|
160
|
+
))}
|
|
161
|
+
</ScrollView>
|
|
162
|
+
<Animated.View
|
|
163
|
+
style={[
|
|
164
|
+
styles.underline,
|
|
165
|
+
{ width: underlineWidth, transform: [{ translateX: underlineTranslateX }] },
|
|
166
|
+
]}
|
|
167
|
+
/>
|
|
168
|
+
</View>
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const styles = StyleSheet.create({
|
|
173
|
+
container: {
|
|
174
|
+
backgroundColor: Colors.surface,
|
|
175
|
+
borderBottomWidth: StyleSheet.hairlineWidth,
|
|
176
|
+
borderBottomColor: Colors.border,
|
|
177
|
+
},
|
|
178
|
+
scrollContent: {
|
|
179
|
+
paddingHorizontal: 20,
|
|
180
|
+
flexDirection: 'row',
|
|
181
|
+
},
|
|
182
|
+
tab: {
|
|
183
|
+
paddingVertical: 10,
|
|
184
|
+
paddingHorizontal: 14,
|
|
185
|
+
marginRight: 8,
|
|
186
|
+
},
|
|
187
|
+
tabText: {
|
|
188
|
+
fontSize: 14,
|
|
189
|
+
fontWeight: '500',
|
|
190
|
+
color: Colors.textLight,
|
|
191
|
+
},
|
|
192
|
+
activeTabText: {
|
|
193
|
+
color: Colors.primary,
|
|
194
|
+
fontWeight: '600',
|
|
195
|
+
},
|
|
196
|
+
underline: {
|
|
197
|
+
position: 'absolute',
|
|
198
|
+
bottom: 0,
|
|
199
|
+
left: 0,
|
|
200
|
+
height: 2.5,
|
|
201
|
+
borderRadius: 1.25,
|
|
202
|
+
backgroundColor: Colors.primary,
|
|
203
|
+
},
|
|
204
|
+
});
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import React, { useRef } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
View,
|
|
4
|
+
Text,
|
|
5
|
+
StyleSheet,
|
|
6
|
+
Animated,
|
|
7
|
+
PanResponder,
|
|
8
|
+
Pressable,
|
|
9
|
+
useWindowDimensions,
|
|
10
|
+
} from 'react-native';
|
|
11
|
+
import { Colors } from '../utils/colors';
|
|
12
|
+
import { ICON_SIZE } from '../utils/layout';
|
|
13
|
+
|
|
14
|
+
interface FloatIconProps {
|
|
15
|
+
visible: boolean;
|
|
16
|
+
onPress: () => void;
|
|
17
|
+
badge: { label: string; color: string } | null;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function FloatIcon({ visible, onPress, badge }: FloatIconProps) {
|
|
21
|
+
const { width: screenWidth, height: screenHeight } = useWindowDimensions();
|
|
22
|
+
const initialX = screenWidth - ICON_SIZE - 16;
|
|
23
|
+
const initialY = screenHeight / 2 - ICON_SIZE / 2;
|
|
24
|
+
|
|
25
|
+
const pan = useRef(
|
|
26
|
+
new Animated.ValueXY({ x: initialX, y: initialY }),
|
|
27
|
+
).current;
|
|
28
|
+
const scale = useRef(new Animated.Value(1)).current;
|
|
29
|
+
const lastPosition = useRef({ x: initialX, y: initialY });
|
|
30
|
+
|
|
31
|
+
const panResponder = useRef(
|
|
32
|
+
PanResponder.create({
|
|
33
|
+
onStartShouldSetPanResponder: () => true,
|
|
34
|
+
onMoveShouldSetPanResponder: () => true,
|
|
35
|
+
onPanResponderGrant: () => {
|
|
36
|
+
Animated.spring(scale, {
|
|
37
|
+
toValue: 0.9,
|
|
38
|
+
friction: 5,
|
|
39
|
+
useNativeDriver: true,
|
|
40
|
+
}).start();
|
|
41
|
+
},
|
|
42
|
+
onPanResponderMove: (_: unknown, gs: { dx: number; dy: number }) => {
|
|
43
|
+
const x = Math.max(
|
|
44
|
+
0,
|
|
45
|
+
Math.min(lastPosition.current.x + gs.dx, screenWidth - ICON_SIZE),
|
|
46
|
+
);
|
|
47
|
+
const y = Math.max(
|
|
48
|
+
0,
|
|
49
|
+
Math.min(lastPosition.current.y + gs.dy, screenHeight - ICON_SIZE),
|
|
50
|
+
);
|
|
51
|
+
pan.setValue({ x, y });
|
|
52
|
+
},
|
|
53
|
+
onPanResponderRelease: (_: unknown, gs: { dx: number; dy: number }) => {
|
|
54
|
+
if (Math.abs(gs.dx) < 5 && Math.abs(gs.dy) < 5) {
|
|
55
|
+
Animated.spring(scale, { toValue: 1, friction: 5, useNativeDriver: true }).start();
|
|
56
|
+
onPress();
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
Animated.spring(scale, { toValue: 1, friction: 5, useNativeDriver: true }).start();
|
|
60
|
+
lastPosition.current = {
|
|
61
|
+
x: Math.max(
|
|
62
|
+
0,
|
|
63
|
+
Math.min(lastPosition.current.x + gs.dx, screenWidth - ICON_SIZE),
|
|
64
|
+
),
|
|
65
|
+
y: Math.max(
|
|
66
|
+
0,
|
|
67
|
+
Math.min(lastPosition.current.y + gs.dy, screenHeight - ICON_SIZE),
|
|
68
|
+
),
|
|
69
|
+
};
|
|
70
|
+
},
|
|
71
|
+
onPanResponderTerminate: (_: unknown, gs: { dx: number; dy: number }) => {
|
|
72
|
+
lastPosition.current = {
|
|
73
|
+
x: Math.max(
|
|
74
|
+
0,
|
|
75
|
+
Math.min(lastPosition.current.x + gs.dx, screenWidth - ICON_SIZE),
|
|
76
|
+
),
|
|
77
|
+
y: Math.max(
|
|
78
|
+
0,
|
|
79
|
+
Math.min(lastPosition.current.y + gs.dy, screenHeight - ICON_SIZE),
|
|
80
|
+
),
|
|
81
|
+
};
|
|
82
|
+
},
|
|
83
|
+
}),
|
|
84
|
+
).current;
|
|
85
|
+
|
|
86
|
+
return (
|
|
87
|
+
<Animated.View
|
|
88
|
+
pointerEvents={visible ? 'auto' : 'none'}
|
|
89
|
+
style={[
|
|
90
|
+
styles.root,
|
|
91
|
+
{
|
|
92
|
+
transform: [{ translateX: pan.x }, { translateY: pan.y }, { scale }],
|
|
93
|
+
opacity: visible ? 1 : 0,
|
|
94
|
+
},
|
|
95
|
+
]}
|
|
96
|
+
{...panResponder.panHandlers}
|
|
97
|
+
>
|
|
98
|
+
<Pressable onPress={onPress} style={styles.inner}>
|
|
99
|
+
<View style={styles.iconGrid}>
|
|
100
|
+
<View style={styles.iconRow}>
|
|
101
|
+
<View style={[styles.iconCell, { backgroundColor: Colors.primary }]} />
|
|
102
|
+
<View style={[styles.iconCell, { backgroundColor: Colors.success }]} />
|
|
103
|
+
</View>
|
|
104
|
+
<View style={styles.iconRow}>
|
|
105
|
+
<View style={[styles.iconCell, { backgroundColor: Colors.warning }]} />
|
|
106
|
+
<View style={[styles.iconCell, { backgroundColor: Colors.purple }]} />
|
|
107
|
+
</View>
|
|
108
|
+
</View>
|
|
109
|
+
{badge && (
|
|
110
|
+
<View style={[styles.badge, { backgroundColor: badge.color }]}>
|
|
111
|
+
<Text style={styles.badgeText}>{badge.label}</Text>
|
|
112
|
+
</View>
|
|
113
|
+
)}
|
|
114
|
+
</Pressable>
|
|
115
|
+
</Animated.View>
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const styles = StyleSheet.create({
|
|
120
|
+
root: {
|
|
121
|
+
position: 'absolute',
|
|
122
|
+
width: ICON_SIZE,
|
|
123
|
+
height: ICON_SIZE,
|
|
124
|
+
borderRadius: ICON_SIZE / 2,
|
|
125
|
+
backgroundColor: '#FFFFFF',
|
|
126
|
+
elevation: 6,
|
|
127
|
+
shadowColor: '#000',
|
|
128
|
+
shadowOffset: { width: 0, height: 2 },
|
|
129
|
+
shadowOpacity: 0.12,
|
|
130
|
+
shadowRadius: 8,
|
|
131
|
+
},
|
|
132
|
+
inner: {
|
|
133
|
+
width: '100%',
|
|
134
|
+
height: '100%',
|
|
135
|
+
alignItems: 'center',
|
|
136
|
+
justifyContent: 'center',
|
|
137
|
+
},
|
|
138
|
+
iconGrid: {
|
|
139
|
+
width: 22,
|
|
140
|
+
height: 22,
|
|
141
|
+
justifyContent: 'space-between',
|
|
142
|
+
},
|
|
143
|
+
iconRow: {
|
|
144
|
+
flexDirection: 'row',
|
|
145
|
+
justifyContent: 'space-between',
|
|
146
|
+
},
|
|
147
|
+
iconCell: {
|
|
148
|
+
width: 8,
|
|
149
|
+
height: 8,
|
|
150
|
+
borderRadius: 2.5,
|
|
151
|
+
},
|
|
152
|
+
badge: {
|
|
153
|
+
position: 'absolute',
|
|
154
|
+
top: -4,
|
|
155
|
+
right: -4,
|
|
156
|
+
minWidth: 20,
|
|
157
|
+
height: 18,
|
|
158
|
+
borderRadius: 9,
|
|
159
|
+
paddingHorizontal: 5,
|
|
160
|
+
alignItems: 'center',
|
|
161
|
+
justifyContent: 'center',
|
|
162
|
+
borderWidth: 2,
|
|
163
|
+
borderColor: '#FFF',
|
|
164
|
+
elevation: 4,
|
|
165
|
+
},
|
|
166
|
+
badgeText: {
|
|
167
|
+
color: '#FFF',
|
|
168
|
+
fontSize: 9,
|
|
169
|
+
fontWeight: '700',
|
|
170
|
+
},
|
|
171
|
+
});
|