From d528fe28a618f50eb95ef78dbbf2d5ab3b01b36f Mon Sep 17 00:00:00 2001 From: Xin Chen Date: Thu, 23 Feb 2023 09:14:10 -0800 Subject: [PATCH] Add performance.memory API example to RNTester Summary: Add performance API example to RN tester, start with the `performance.memory` API. - Update `RNTesterList` file for both android and ios Changelog: [General][Internal] - Add `performance.memory` API example to RNTester Reviewed By: rshest Differential Revision: D43326565 fbshipit-source-id: adeb18ce9f1f90d9e9ecf66b533307028bc02df8 --- .../Performance/PerformanceApiExample.js | 82 +++++++++++++++++++ .../js/utils/RNTesterList.android.js | 5 ++ .../rn-tester/js/utils/RNTesterList.ios.js | 5 ++ 3 files changed, 92 insertions(+) create mode 100644 packages/rn-tester/js/examples/Performance/PerformanceApiExample.js diff --git a/packages/rn-tester/js/examples/Performance/PerformanceApiExample.js b/packages/rn-tester/js/examples/Performance/PerformanceApiExample.js new file mode 100644 index 00000000000..34ac57f847a --- /dev/null +++ b/packages/rn-tester/js/examples/Performance/PerformanceApiExample.js @@ -0,0 +1,82 @@ +/** + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @format + * @flow strict-local + * @oncall react_native + */ + +'use strict'; + +import * as React from 'react'; +import {StyleSheet, View, Text, Button} from 'react-native'; +import RNTesterPage from '../../components/RNTesterPage'; + +const {useState} = React; + +function MemoryExample(): React.Node { + // Memory API testing + const [memoryInfo, setMemoryInfo] = useState<{ + jsHeapSizeLimit?: ?number, + totalJSHeapSize?: ?number, + usedJSHeapSize?: ?number, + }>({}); + const onGetMemoryInfo = () => { + // performance.memory is not included in bom.js yet. + // Once we release the change in flow this can be removed. + // $FlowFixMe[prop-missing] + // $FlowFixMe[incompatible-call] + setMemoryInfo(performance.memory); + }; + return ( + + +