/**
* 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 type MemoryInfo from 'react-native/Libraries/WebPerformance/MemoryInfo';
import type ReactNativeStartupTiming from 'react-native/Libraries/WebPerformance/ReactNativeStartupTiming';
import * as React from 'react';
import {StyleSheet, View, Text, Button} from 'react-native';
import RNTesterPage from '../../components/RNTesterPage';
import Performance from 'react-native/Libraries/WebPerformance/Performance';
const {useState, useCallback} = React;
const performance = new Performance();
function MemoryExample(): React.Node {
// Memory API testing
const [memoryInfo, setMemoryInfo] = useState(null);
const onGetMemoryInfo = useCallback(() => {
// 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 (
{`jsHeapSizeLimit: ${String(memoryInfo?.jsHeapSizeLimit)} bytes`}
{`totalJSHeapSize: ${String(memoryInfo?.totalJSHeapSize)} bytes`}
{`usedJSHeapSize: ${String(memoryInfo?.usedJSHeapSize)} bytes`}
);
}
function StartupTimingExample(): React.Node {
// React Startup Timing API testing
const [startUpTiming, setStartUpTiming] =
useState(null);
const onGetStartupTiming = useCallback(() => {
// performance.reactNativeStartupTiming is not included in bom.js yet.
// Once we release the change in flow this can be removed.
// $FlowFixMe[prop-missing]
// $FlowFixMe[incompatible-call]
setStartUpTiming(performance.reactNativeStartupTiming);
}, []);
return (
{`startTime: ${String(startUpTiming?.startTime)} ms`}{`initializeRuntimeStart: ${String(
startUpTiming?.initializeRuntimeStart,
)} ms`}
{`executeJavaScriptBundleEntryPointStart: ${String(
startUpTiming?.executeJavaScriptBundleEntryPointStart,
)} ms`}
{`executeJavaScriptBundleEntryPointEnd: ${String(
startUpTiming?.executeJavaScriptBundleEntryPointEnd,
)} ms`}{`initializeRuntimeEnd: ${String(
startUpTiming?.initializeRuntimeEnd,
)} ms`}{`endTime: ${String(startUpTiming?.endTime)} ms`}
);
}
const styles = StyleSheet.create({
container: {
padding: 10,
},
});
exports.title = 'Performance API Examples';
exports.category = 'Basic';
exports.description = 'Shows the performance API provided in React Native';
exports.examples = [
{
title: 'performance.memory',
render: function (): React.Element {
return ;
},
},
{
title: 'performance.reactNativeStartupTiming',
render: function (): React.Element {
return ;
},
},
];