From 6b791b16600962aaf0f54267a7a47cc4de4c1ab0 Mon Sep 17 00:00:00 2001 From: Taras Perun Date: Tue, 13 Feb 2024 15:19:16 +0100 Subject: [PATCH 01/18] install react-native-release-profiler --- .../NewExpensifyDebugDevelopment.entitlements | 16 +++++++++++ ios/Podfile.lock | 16 ++++++++--- package-lock.json | 28 +++++++++++++++++++ package.json | 1 + 4 files changed, 57 insertions(+), 4 deletions(-) create mode 100644 ios/NewExpensify/NewExpensifyDebugDevelopment.entitlements diff --git a/ios/NewExpensify/NewExpensifyDebugDevelopment.entitlements b/ios/NewExpensify/NewExpensifyDebugDevelopment.entitlements new file mode 100644 index 000000000000..1d9bc86a21de --- /dev/null +++ b/ios/NewExpensify/NewExpensifyDebugDevelopment.entitlements @@ -0,0 +1,16 @@ + + + + + aps-environment + development + com.apple.developer.associated-domains + + applinks:new.expensify.com + applinks:staging.new.expensify.com + webcredentials:new.expensify.com + + com.apple.developer.usernotifications.communication + + + diff --git a/ios/Podfile.lock b/ios/Podfile.lock index 19a579b846e8..a6b61dc6f1ff 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -1193,6 +1193,10 @@ PODS: - React - React-callinvoker - React-Core + - react-native-release-profiler (0.1.6): + - glog + - RCT-Folly (= 2022.05.16.00) + - React-Core - react-native-render-html (6.3.1): - React-Core - react-native-safe-area-context (4.7.4): @@ -1443,7 +1447,7 @@ PODS: - RNSound/Core (= 0.11.2) - RNSound/Core (0.11.2): - React-Core - - RNSVG (14.0.0): + - RNSVG (14.1.0): - React-Core - SDWebImage (5.17.0): - SDWebImage/Core (= 5.17.0) @@ -1458,7 +1462,7 @@ PODS: - SDWebImage/Core (~> 5.17) - SocketRocket (0.6.1) - Turf (2.7.0) - - VisionCamera (2.16.5): + - VisionCamera (2.16.8): - React - React-callinvoker - React-Core @@ -1540,6 +1544,7 @@ DEPENDENCIES: - react-native-performance (from `../node_modules/react-native-performance`) - react-native-plaid-link-sdk (from `../node_modules/react-native-plaid-link-sdk`) - react-native-quick-sqlite (from `../node_modules/react-native-quick-sqlite`) + - react-native-release-profiler (from `../node_modules/react-native-release-profiler`) - react-native-render-html (from `../node_modules/react-native-render-html`) - react-native-safe-area-context (from `../node_modules/react-native-safe-area-context`) - react-native-view-shot (from `../node_modules/react-native-view-shot`) @@ -1743,6 +1748,8 @@ EXTERNAL SOURCES: :path: "../node_modules/react-native-plaid-link-sdk" react-native-quick-sqlite: :path: "../node_modules/react-native-quick-sqlite" + react-native-release-profiler: + :path: "../node_modules/react-native-release-profiler" react-native-render-html: :path: "../node_modules/react-native-render-html" react-native-safe-area-context: @@ -1936,6 +1943,7 @@ SPEC CHECKSUMS: react-native-performance: cef2b618d47b277fb5c3280b81a3aad1e72f2886 react-native-plaid-link-sdk: df1618a85a615d62ff34e34b76abb7a56497fbc1 react-native-quick-sqlite: bcc7a7a250a40222f18913a97cd356bf82d0a6c4 + react-native-release-profiler: 86f2004d5f8c4fff17d90a5580513519a685d7ae react-native-render-html: 96c979fe7452a0a41559685d2f83b12b93edac8c react-native-safe-area-context: 2cd91d532de12acdb0a9cbc8d43ac72a8e4c897c react-native-view-shot: 6b7ed61d77d88580fed10954d45fad0eb2d47688 @@ -1982,14 +1990,14 @@ SPEC CHECKSUMS: RNReanimated: 57f436e7aa3d277fbfed05e003230b43428157c0 RNScreens: b582cb834dc4133307562e930e8fa914b8c04ef2 RNSound: 6c156f925295bdc83e8e422e7d8b38d33bc71852 - RNSVG: 255767813dac22db1ec2062c8b7e7b856d4e5ae6 + RNSVG: ba3e7232f45e34b7b47e74472386cf4e1a676d0a SDWebImage: 750adf017a315a280c60fde706ab1e552a3ae4e9 SDWebImageAVIFCoder: 8348fef6d0ec69e129c66c9fe4d74fbfbf366112 SDWebImageSVGCoder: 15a300a97ec1c8ac958f009c02220ac0402e936c SDWebImageWebPCoder: af09429398d99d524cae2fe00f6f0f6e491ed102 SocketRocket: f32cd54efbe0f095c4d7594881e52619cfe80b17 Turf: 13d1a92d969ca0311bbc26e8356cca178ce95da2 - VisionCamera: fda554d8751e395effcc87749f8b7c198c1031be + VisionCamera: 0a6794d1974aed5d653d0d0cb900493e2583e35a Yoga: 13c8ef87792450193e117976337b8527b49e8c03 PODFILE CHECKSUM: 0ccbb4f2406893c6e9f266dc1e7470dcd72885d2 diff --git a/package-lock.json b/package-lock.json index d499a59df097..7b99e43e4d2c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -106,6 +106,7 @@ "react-native-qrcode-svg": "^6.2.0", "react-native-quick-sqlite": "^8.0.0-beta.2", "react-native-reanimated": "^3.6.1", + "react-native-release-profiler": "^0.1.6", "react-native-render-html": "6.3.1", "react-native-safe-area-context": "4.7.4", "react-native-screens": "3.29.0", @@ -45281,6 +45282,33 @@ "integrity": "sha512-Kvp459HrV2FEJ1CAsi1Ku+MY3kasH19TFykTz2xWmMeq6bk2NU3XXvfJ+Q61m0xktWwt+1HSYf3JZsTms3aRJg==", "license": "MIT" }, + "node_modules/react-native-release-profiler": { + "version": "0.1.6", + "resolved": "https://registry.npmjs.org/react-native-release-profiler/-/react-native-release-profiler-0.1.6.tgz", + "integrity": "sha512-kSAPYjO3PDzV4xbjgj2NoiHtL7EaXmBira/WOcyz6S7mz1MVBoF0Bj74z5jAZo6BoBJRKqmQWI4ep+m0xvoF+g==", + "dependencies": { + "@react-native-community/cli": "^12.2.1", + "commander": "^11.1.0" + }, + "bin": { + "react-native-release-profiler": "lib/commonjs/cli.js" + }, + "engines": { + "node": ">= 18.0.0" + }, + "peerDependencies": { + "react": "*", + "react-native": "*" + } + }, + "node_modules/react-native-release-profiler/node_modules/commander": { + "version": "11.1.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-11.1.0.tgz", + "integrity": "sha512-yPVavfyCcRhmorC7rWlkHn15b4wDVgVmBA7kV4QVBsF7kv/9TKJAbAXVTxvTnwP8HHKjRCJDClKbciiYS7p0DQ==", + "engines": { + "node": ">=16" + } + }, "node_modules/react-native-render-html": { "version": "6.3.1", "resolved": "https://registry.npmjs.org/react-native-render-html/-/react-native-render-html-6.3.1.tgz", diff --git a/package.json b/package.json index 7157b28faf4b..ebbb3c58a944 100644 --- a/package.json +++ b/package.json @@ -154,6 +154,7 @@ "react-native-qrcode-svg": "^6.2.0", "react-native-quick-sqlite": "^8.0.0-beta.2", "react-native-reanimated": "^3.6.1", + "react-native-release-profiler": "^0.1.6", "react-native-render-html": "6.3.1", "react-native-safe-area-context": "4.7.4", "react-native-screens": "3.29.0", From 9c189c3a85de452f06fe9fb7a85d1f3df9a50473 Mon Sep 17 00:00:00 2001 From: Taras Perun Date: Tue, 13 Feb 2024 15:22:13 +0100 Subject: [PATCH 02/18] ProfilingToolMenu --- src/ONYXKEYS.ts | 2 + src/components/ProfilingToolMenu.tsx | 76 ++++++++++++++++++++++++++++ src/components/ScreenWrapper.tsx | 4 +- src/components/TestToolsModal.tsx | 6 ++- src/libs/actions/ProfilingTool.ts | 22 ++++++++ 5 files changed, 107 insertions(+), 3 deletions(-) create mode 100644 src/components/ProfilingToolMenu.tsx create mode 100644 src/libs/actions/ProfilingTool.ts diff --git a/src/ONYXKEYS.ts b/src/ONYXKEYS.ts index 4a9c809485e5..0d93f1b88d70 100755 --- a/src/ONYXKEYS.ts +++ b/src/ONYXKEYS.ts @@ -201,6 +201,7 @@ const ONYXKEYS = { /** Is the test tools modal open? */ IS_TEST_TOOLS_MODAL_OPEN: 'isTestToolsModalOpen', + IS_APP_PROFILING: 'isAppProfiling', /** Stores information about active wallet transfer amount, selectedAccountID, status, etc */ WALLET_TRANSFER: 'walletTransfer', @@ -443,6 +444,7 @@ type OnyxValues = { [ONYXKEYS.IS_LOADING_PAYMENT_METHODS]: boolean; [ONYXKEYS.IS_LOADING_REPORT_DATA]: boolean; [ONYXKEYS.IS_TEST_TOOLS_MODAL_OPEN]: boolean; + [ONYXKEYS.IS_APP_PROFILING]: boolean; [ONYXKEYS.IS_LOADING_APP]: boolean; [ONYXKEYS.WALLET_TRANSFER]: OnyxTypes.WalletTransfer; [ONYXKEYS.LAST_ACCESSED_WORKSPACE_POLICY_ID]: string; diff --git a/src/components/ProfilingToolMenu.tsx b/src/components/ProfilingToolMenu.tsx new file mode 100644 index 000000000000..26e92ee327a2 --- /dev/null +++ b/src/components/ProfilingToolMenu.tsx @@ -0,0 +1,76 @@ +import React, {useCallback, useState} from 'react'; +import {withOnyx} from 'react-native-onyx'; +import type {OnyxEntry} from 'react-native-onyx'; +import {startProfiling, stopProfiling} from 'react-native-release-profiler'; +import useThemeStyles from '@hooks/useThemeStyles'; +import toggleProfileToolsModal from '@libs/actions/ProfilingTool'; +import ONYXKEYS from '@src/ONYXKEYS'; +import Switch from './Switch'; +import TestToolRow from './TestToolRow'; +import Text from './Text'; + +type ProfilingToolMenuOnyxProps = { + isAppProfiling: OnyxEntry; +}; + +type ProfilingToolMenuProps = ProfilingToolMenuOnyxProps; + +function ProfilingToolMenu({isAppProfiling = false}: ProfilingToolMenuProps) { + const styles = useThemeStyles(); + const [pathIOS, setPathIOS] = useState(''); + + // eslint-disable-next-line @lwc/lwc/no-async-await + const stop = useCallback(async () => { + const path = await stopProfiling(true); + if (path) { + setPathIOS(path); + } + return path; + }, []); + + const onToggleProfiling = useCallback(() => { + const shouldProfiling = !isAppProfiling; + if (shouldProfiling) { + startProfiling(); + } else { + stop(); + } + toggleProfileToolsModal(); + return () => { + stop(); + }; + }, [isAppProfiling, stop]); + + return ( + <> + + Release options + + + + + + + {!!pathIOS && `path: ${pathIOS}`} + + + ); +} + +ProfilingToolMenu.displayName = 'ProfilingToolMenu'; + +export default withOnyx({ + isAppProfiling: { + key: ONYXKEYS.IS_APP_PROFILING, + }, +})(ProfilingToolMenu); diff --git a/src/components/ScreenWrapper.tsx b/src/components/ScreenWrapper.tsx index 8b6a894cdd51..687ab68160c6 100644 --- a/src/components/ScreenWrapper.tsx +++ b/src/components/ScreenWrapper.tsx @@ -218,7 +218,7 @@ function ScreenWrapper( ref={ref} style={[styles.flex1, {minHeight}]} // eslint-disable-next-line react/jsx-props-no-spreading - {...(isDevelopment ? panResponder.panHandlers : {})} + {...panResponder.panHandlers} testID={testID} > - {isDevelopment && } + {isDevelopment && } { // If props.children is a function, call it to provide the insets to the children. diff --git a/src/components/TestToolsModal.tsx b/src/components/TestToolsModal.tsx index 2b1ec1e84c5b..5f469e750882 100644 --- a/src/components/TestToolsModal.tsx +++ b/src/components/TestToolsModal.tsx @@ -2,11 +2,13 @@ import React from 'react'; import {View} from 'react-native'; import type {OnyxEntry} from 'react-native-onyx'; import {withOnyx} from 'react-native-onyx'; +import useEnvironment from '@hooks/useEnvironment'; import useThemeStyles from '@hooks/useThemeStyles'; import toggleTestToolsModal from '@userActions/TestTool'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import Modal from './Modal'; +import ProfilingToolMenu from './ProfilingToolMenu'; import TestToolMenu from './TestToolMenu'; type TestToolsModalOnyxProps = { @@ -17,6 +19,7 @@ type TestToolsModalOnyxProps = { type TestToolsModalProps = TestToolsModalOnyxProps; function TestToolsModal({isTestToolsModalOpen = false}: TestToolsModalProps) { + const {isDevelopment} = useEnvironment(); const styles = useThemeStyles(); return ( @@ -26,7 +29,8 @@ function TestToolsModal({isTestToolsModalOpen = false}: TestToolsModalProps) { onClose={toggleTestToolsModal} > - + {isDevelopment && } + ); diff --git a/src/libs/actions/ProfilingTool.ts b/src/libs/actions/ProfilingTool.ts new file mode 100644 index 000000000000..9c820c673866 --- /dev/null +++ b/src/libs/actions/ProfilingTool.ts @@ -0,0 +1,22 @@ +import throttle from 'lodash/throttle'; +import Onyx from 'react-native-onyx'; +import CONST from '@src/CONST'; +import ONYXKEYS from '@src/ONYXKEYS'; + +let isAppProfiling = false; +Onyx.connect({ + key: ONYXKEYS.IS_APP_PROFILING, + callback: (val) => (isAppProfiling = val ?? false), +}); + +/** + * Toggle the test tools modal open or closed. + * Throttle the toggle to make the modal stay open if you accidentally tap an extra time, which is easy to do. + */ +function toggleProfileToolsModal() { + const toggle = () => Onyx.set(ONYXKEYS.IS_APP_PROFILING, !isAppProfiling); + const throttledToggle = throttle(toggle, CONST.TIMING.TEST_TOOLS_MODAL_THROTTLE_TIME); + throttledToggle(); +} + +export default toggleProfileToolsModal; From ce7179460a34f6bf4665df9578f6e394e8126a28 Mon Sep 17 00:00:00 2001 From: Taras Perun Date: Tue, 13 Feb 2024 15:27:40 +0100 Subject: [PATCH 03/18] set width for TestToolsModal --- src/components/TestToolsModal.tsx | 8 +++++--- src/styles/utils/index.ts | 5 +++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/components/TestToolsModal.tsx b/src/components/TestToolsModal.tsx index 5f469e750882..824162e63c51 100644 --- a/src/components/TestToolsModal.tsx +++ b/src/components/TestToolsModal.tsx @@ -3,7 +3,8 @@ import {View} from 'react-native'; import type {OnyxEntry} from 'react-native-onyx'; import {withOnyx} from 'react-native-onyx'; import useEnvironment from '@hooks/useEnvironment'; -import useThemeStyles from '@hooks/useThemeStyles'; +import useStyleUtils from '@hooks/useStyleUtils'; +import useWindowDimensions from '@hooks/useWindowDimensions'; import toggleTestToolsModal from '@userActions/TestTool'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; @@ -20,7 +21,8 @@ type TestToolsModalProps = TestToolsModalOnyxProps; function TestToolsModal({isTestToolsModalOpen = false}: TestToolsModalProps) { const {isDevelopment} = useEnvironment(); - const styles = useThemeStyles(); + const {windowWidth} = useWindowDimensions(); + const StyleUtils = useStyleUtils(); return ( - + {isDevelopment && } diff --git a/src/styles/utils/index.ts b/src/styles/utils/index.ts index d4d2b427cbe8..14222ede67ba 100644 --- a/src/styles/utils/index.ts +++ b/src/styles/utils/index.ts @@ -1474,6 +1474,11 @@ const createStyleUtils = (theme: ThemeColors, styles: ThemeStyles) => ({ }, getFullscreenCenteredContentStyles: () => [StyleSheet.absoluteFill, styles.justifyContentCenter, styles.alignItemsCenter], + + /** + * Returns the styles for the Tools modal + */ + getTestToolsModalStyle: (windowWidth: number): ViewStyle[] => [styles.settingsPageBody, styles.p5, {width: windowWidth * 0.9}], }); type StyleUtilsType = ReturnType; From fc0c2dd9dbcba618a6ef228288420614dd371c46 Mon Sep 17 00:00:00 2001 From: Taras Perun Date: Tue, 13 Feb 2024 15:30:45 +0100 Subject: [PATCH 04/18] clean up --- .../NewExpensifyDebugDevelopment.entitlements | 16 ---------------- src/components/ProfilingToolMenu.tsx | 7 +------ 2 files changed, 1 insertion(+), 22 deletions(-) delete mode 100644 ios/NewExpensify/NewExpensifyDebugDevelopment.entitlements diff --git a/ios/NewExpensify/NewExpensifyDebugDevelopment.entitlements b/ios/NewExpensify/NewExpensifyDebugDevelopment.entitlements deleted file mode 100644 index 1d9bc86a21de..000000000000 --- a/ios/NewExpensify/NewExpensifyDebugDevelopment.entitlements +++ /dev/null @@ -1,16 +0,0 @@ - - - - - aps-environment - development - com.apple.developer.associated-domains - - applinks:new.expensify.com - applinks:staging.new.expensify.com - webcredentials:new.expensify.com - - com.apple.developer.usernotifications.communication - - - diff --git a/src/components/ProfilingToolMenu.tsx b/src/components/ProfilingToolMenu.tsx index 26e92ee327a2..e9bcb661cf61 100644 --- a/src/components/ProfilingToolMenu.tsx +++ b/src/components/ProfilingToolMenu.tsx @@ -57,12 +57,7 @@ function ProfilingToolMenu({isAppProfiling = false}: ProfilingToolMenuProps) { onToggle={onToggleProfiling} /> - - {!!pathIOS && `path: ${pathIOS}`} - + {!!pathIOS && `path: ${pathIOS}`} ); } From fda4e961db2c5bd81013f7d91444daae3a36f065 Mon Sep 17 00:00:00 2001 From: Taras Perun Date: Tue, 13 Feb 2024 16:12:51 +0100 Subject: [PATCH 05/18] remove ProfilingToolMenu from web --- .../index.native.tsx} | 6 +++--- src/components/ProfilingToolMenu/index.tsx | 7 +++++++ 2 files changed, 10 insertions(+), 3 deletions(-) rename src/components/{ProfilingToolMenu.tsx => ProfilingToolMenu/index.native.tsx} (94%) create mode 100644 src/components/ProfilingToolMenu/index.tsx diff --git a/src/components/ProfilingToolMenu.tsx b/src/components/ProfilingToolMenu/index.native.tsx similarity index 94% rename from src/components/ProfilingToolMenu.tsx rename to src/components/ProfilingToolMenu/index.native.tsx index e9bcb661cf61..a14263d9a89b 100644 --- a/src/components/ProfilingToolMenu.tsx +++ b/src/components/ProfilingToolMenu/index.native.tsx @@ -5,9 +5,9 @@ import {startProfiling, stopProfiling} from 'react-native-release-profiler'; import useThemeStyles from '@hooks/useThemeStyles'; import toggleProfileToolsModal from '@libs/actions/ProfilingTool'; import ONYXKEYS from '@src/ONYXKEYS'; -import Switch from './Switch'; -import TestToolRow from './TestToolRow'; -import Text from './Text'; +import Switch from '@components/Switch'; +import Text from '@components/Text'; +import TestToolRow from '@components/TestToolRow'; type ProfilingToolMenuOnyxProps = { isAppProfiling: OnyxEntry; diff --git a/src/components/ProfilingToolMenu/index.tsx b/src/components/ProfilingToolMenu/index.tsx new file mode 100644 index 000000000000..71eef72b7c25 --- /dev/null +++ b/src/components/ProfilingToolMenu/index.tsx @@ -0,0 +1,7 @@ +function ProfilingToolMenu() { + return null; +} + +ProfilingToolMenu.displayName = 'ProfilingToolMenu'; + +export default ProfilingToolMenu; From 2597243b07872df7a630d6efb60375881b1e0b72 Mon Sep 17 00:00:00 2001 From: Taras Perun Date: Tue, 13 Feb 2024 16:43:01 +0100 Subject: [PATCH 06/18] rename --- src/ONYXKEYS.ts | 6 ++-- .../ProfilingToolMenu/index.native.tsx | 28 +++++++++---------- src/components/ProfilingToolMenu/index.tsx | 2 +- src/libs/actions/ProfilingTool.ts | 12 ++++---- 4 files changed, 25 insertions(+), 23 deletions(-) diff --git a/src/ONYXKEYS.ts b/src/ONYXKEYS.ts index 0d93f1b88d70..04e26d776d12 100755 --- a/src/ONYXKEYS.ts +++ b/src/ONYXKEYS.ts @@ -201,7 +201,9 @@ const ONYXKEYS = { /** Is the test tools modal open? */ IS_TEST_TOOLS_MODAL_OPEN: 'isTestToolsModalOpen', - IS_APP_PROFILING: 'isAppProfiling', + + /** Is app in profiling mode */ + APP_PROFILING_IN_PROGRESS: 'isProfilingInProgress', /** Stores information about active wallet transfer amount, selectedAccountID, status, etc */ WALLET_TRANSFER: 'walletTransfer', @@ -444,7 +446,7 @@ type OnyxValues = { [ONYXKEYS.IS_LOADING_PAYMENT_METHODS]: boolean; [ONYXKEYS.IS_LOADING_REPORT_DATA]: boolean; [ONYXKEYS.IS_TEST_TOOLS_MODAL_OPEN]: boolean; - [ONYXKEYS.IS_APP_PROFILING]: boolean; + [ONYXKEYS.APP_PROFILING_IN_PROGRESS]: boolean; [ONYXKEYS.IS_LOADING_APP]: boolean; [ONYXKEYS.WALLET_TRANSFER]: OnyxTypes.WalletTransfer; [ONYXKEYS.LAST_ACCESSED_WORKSPACE_POLICY_ID]: string; diff --git a/src/components/ProfilingToolMenu/index.native.tsx b/src/components/ProfilingToolMenu/index.native.tsx index a14263d9a89b..affbcfab3c6e 100644 --- a/src/components/ProfilingToolMenu/index.native.tsx +++ b/src/components/ProfilingToolMenu/index.native.tsx @@ -2,20 +2,20 @@ import React, {useCallback, useState} from 'react'; import {withOnyx} from 'react-native-onyx'; import type {OnyxEntry} from 'react-native-onyx'; import {startProfiling, stopProfiling} from 'react-native-release-profiler'; -import useThemeStyles from '@hooks/useThemeStyles'; -import toggleProfileToolsModal from '@libs/actions/ProfilingTool'; -import ONYXKEYS from '@src/ONYXKEYS'; import Switch from '@components/Switch'; -import Text from '@components/Text'; import TestToolRow from '@components/TestToolRow'; +import Text from '@components/Text'; +import useThemeStyles from '@hooks/useThemeStyles'; +import toggleProfileTool from '@libs/actions/ProfilingTool'; +import ONYXKEYS from '@src/ONYXKEYS'; type ProfilingToolMenuOnyxProps = { - isAppProfiling: OnyxEntry; + isProfilingInProgress: OnyxEntry; }; type ProfilingToolMenuProps = ProfilingToolMenuOnyxProps; -function ProfilingToolMenu({isAppProfiling = false}: ProfilingToolMenuProps) { +function ProfilingToolMenu({isProfilingInProgress = false}: ProfilingToolMenuProps) { const styles = useThemeStyles(); const [pathIOS, setPathIOS] = useState(''); @@ -29,17 +29,17 @@ function ProfilingToolMenu({isAppProfiling = false}: ProfilingToolMenuProps) { }, []); const onToggleProfiling = useCallback(() => { - const shouldProfiling = !isAppProfiling; + const shouldProfiling = !isProfilingInProgress; if (shouldProfiling) { startProfiling(); } else { stop(); } - toggleProfileToolsModal(); + toggleProfileTool(); return () => { stop(); }; - }, [isAppProfiling, stop]); + }, [isProfilingInProgress, stop]); return ( <> @@ -50,10 +50,10 @@ function ProfilingToolMenu({isAppProfiling = false}: ProfilingToolMenuProps) { Release options - + @@ -65,7 +65,7 @@ function ProfilingToolMenu({isAppProfiling = false}: ProfilingToolMenuProps) { ProfilingToolMenu.displayName = 'ProfilingToolMenu'; export default withOnyx({ - isAppProfiling: { - key: ONYXKEYS.IS_APP_PROFILING, + isProfilingInProgress: { + key: ONYXKEYS.APP_PROFILING_IN_PROGRESS, }, })(ProfilingToolMenu); diff --git a/src/components/ProfilingToolMenu/index.tsx b/src/components/ProfilingToolMenu/index.tsx index 71eef72b7c25..ab12fff27ef8 100644 --- a/src/components/ProfilingToolMenu/index.tsx +++ b/src/components/ProfilingToolMenu/index.tsx @@ -1,5 +1,5 @@ function ProfilingToolMenu() { - return null; + return null; } ProfilingToolMenu.displayName = 'ProfilingToolMenu'; diff --git a/src/libs/actions/ProfilingTool.ts b/src/libs/actions/ProfilingTool.ts index 9c820c673866..ac03eac213c1 100644 --- a/src/libs/actions/ProfilingTool.ts +++ b/src/libs/actions/ProfilingTool.ts @@ -3,20 +3,20 @@ import Onyx from 'react-native-onyx'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; -let isAppProfiling = false; +let isProfilingInProgress = false; Onyx.connect({ - key: ONYXKEYS.IS_APP_PROFILING, - callback: (val) => (isAppProfiling = val ?? false), + key: ONYXKEYS.APP_PROFILING_IN_PROGRESS, + callback: (val) => (isProfilingInProgress = val ?? false), }); /** * Toggle the test tools modal open or closed. * Throttle the toggle to make the modal stay open if you accidentally tap an extra time, which is easy to do. */ -function toggleProfileToolsModal() { - const toggle = () => Onyx.set(ONYXKEYS.IS_APP_PROFILING, !isAppProfiling); +function toggleProfileTool() { + const toggle = () => Onyx.set(ONYXKEYS.APP_PROFILING_IN_PROGRESS, !isProfilingInProgress); const throttledToggle = throttle(toggle, CONST.TIMING.TEST_TOOLS_MODAL_THROTTLE_TIME); throttledToggle(); } -export default toggleProfileToolsModal; +export default toggleProfileTool; From 112e08b76225728611f4e05e8dbe58ca5ae5cc87 Mon Sep 17 00:00:00 2001 From: Taras Perun Date: Wed, 14 Feb 2024 12:41:31 +0100 Subject: [PATCH 07/18] add trace sharing --- package-lock.json | 9 ++++ package.json | 1 + .../ProfilingToolMenu/index.native.tsx | 46 +++++++++++++++++-- 3 files changed, 51 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index 90fe6779b8ab..6246a23dfef0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -110,6 +110,7 @@ "react-native-render-html": "6.3.1", "react-native-safe-area-context": "4.7.4", "react-native-screens": "3.29.0", + "react-native-share": "^10.0.2", "react-native-sound": "^0.11.2", "react-native-svg": "14.1.0", "react-native-tab-view": "^3.5.2", @@ -45378,6 +45379,14 @@ "react-native": "*" } }, + "node_modules/react-native-share": { + "version": "10.0.2", + "resolved": "https://registry.npmjs.org/react-native-share/-/react-native-share-10.0.2.tgz", + "integrity": "sha512-EZs4MtsyauAI1zP8xXT1hIFB/pXOZJNDCKcgCpEfTZFXgCUzz8MDVbI1ocP2hA59XHRSkqAQdbJ0BFTpjxOBlg==", + "engines": { + "node": ">=16" + } + }, "node_modules/react-native-sound": { "version": "0.11.2", "resolved": "https://registry.npmjs.org/react-native-sound/-/react-native-sound-0.11.2.tgz", diff --git a/package.json b/package.json index 25e0042ee60d..e6bc3a77d02e 100644 --- a/package.json +++ b/package.json @@ -158,6 +158,7 @@ "react-native-render-html": "6.3.1", "react-native-safe-area-context": "4.7.4", "react-native-screens": "3.29.0", + "react-native-share": "^10.0.2", "react-native-sound": "^0.11.2", "react-native-svg": "14.1.0", "react-native-tab-view": "^3.5.2", diff --git a/src/components/ProfilingToolMenu/index.native.tsx b/src/components/ProfilingToolMenu/index.native.tsx index affbcfab3c6e..222c2fae482e 100644 --- a/src/components/ProfilingToolMenu/index.native.tsx +++ b/src/components/ProfilingToolMenu/index.native.tsx @@ -1,13 +1,20 @@ import React, {useCallback, useState} from 'react'; +import RNFS from 'react-native-fs'; import {withOnyx} from 'react-native-onyx'; import type {OnyxEntry} from 'react-native-onyx'; import {startProfiling, stopProfiling} from 'react-native-release-profiler'; +import Share from 'react-native-share'; +import Button from '@components/Button'; import Switch from '@components/Switch'; import TestToolRow from '@components/TestToolRow'; import Text from '@components/Text'; import useThemeStyles from '@hooks/useThemeStyles'; import toggleProfileTool from '@libs/actions/ProfilingTool'; +import getPlatform from '@libs/getPlatform'; +import Log from '@libs/Log'; +import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; +import pkg from '../../../package.json'; type ProfilingToolMenuOnyxProps = { isProfilingInProgress: OnyxEntry; @@ -21,11 +28,8 @@ function ProfilingToolMenu({isProfilingInProgress = false}: ProfilingToolMenuPro // eslint-disable-next-line @lwc/lwc/no-async-await const stop = useCallback(async () => { - const path = await stopProfiling(true); - if (path) { - setPathIOS(path); - } - return path; + const path = await stopProfiling(getPlatform() === CONST.PLATFORM.IOS); + setPathIOS(path); }, []); const onToggleProfiling = useCallback(() => { @@ -41,6 +45,29 @@ function ProfilingToolMenu({isProfilingInProgress = false}: ProfilingToolMenuPro }; }, [isProfilingInProgress, stop]); + // eslint-disable-next-line @lwc/lwc/no-async-await + const onDownloadProfiling = useCallback(async () => { + const newFileName = `Profile_trace_for_${pkg.version}.json`; + const newFilePath = `${RNFS.DocumentDirectoryPath}/${newFileName}`; + + // Copy the file to a new location with the desired filename + await RNFS.copyFile(pathIOS, newFilePath) + .then(() => { + Log.hmmm('[ProfilingToolMenu] file copied successfully'); + }) + .catch((error) => { + Log.hmmm('[ProfilingToolMenu] error copying file: ', error); + }); + + const actualPath = `file://${newFilePath}`; + + await Share.open({ + url: actualPath, + title: `Profile_trace_for_${pkg.version}`, + type: 'application/json', + }); + }, [pathIOS]); + return ( <> {!!pathIOS && `path: ${pathIOS}`} + {!!pathIOS && ( + +