Files
react-native/packages/rn-tester/js/examples/Performance/PerformanceApiExample.js
T
Nick Gerleman a999f0d2f3 Cleanup RNTesterExampleFilter/RNTesterPage/RNTesterBlock Spacers
Summary:
Right now RNTestePage either adds a large spacer to the end of content, unless `noSpacer` is added. But with `noSpacer`, scrolling content may not be reachable because we are putting padding on the wrong container.

This fixes that and removes a few cases where we had multi hundred px empty space in favor of uniformly taking up the parent, and a 10px padding. This also moves the constant margin at the top of RNTesterBlock to the container, so that in the E2E container we can save the 30px.

Changelog:
[Internal]

Reviewed By: javache

Differential Revision: D44197303

fbshipit-source-id: 8dc67f3588bc28316e2fee8d25a0bc59995f1728
2023-03-20 11:14:16 -07:00

120 lines
3.8 KiB
JavaScript

/**
* 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<?MemoryInfo>(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 (
<RNTesterPage noScroll={true} title="performance.memory">
<View style={styles.container}>
<Button onPress={onGetMemoryInfo} title="Click to update memory info" />
<View>
<Text>
{`jsHeapSizeLimit: ${String(memoryInfo?.jsHeapSizeLimit)} bytes`}
</Text>
<Text>
{`totalJSHeapSize: ${String(memoryInfo?.totalJSHeapSize)} bytes`}
</Text>
<Text>
{`usedJSHeapSize: ${String(memoryInfo?.usedJSHeapSize)} bytes`}
</Text>
</View>
</View>
</RNTesterPage>
);
}
function StartupTimingExample(): React.Node {
// React Startup Timing API testing
const [startUpTiming, setStartUpTiming] =
useState<?ReactNativeStartupTiming>(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 (
<RNTesterPage noScroll={true} title="performance.reactNativeStartupTiming">
<View style={styles.container}>
<Button
onPress={onGetStartupTiming}
title="Click to update React startup timing"
/>
<View>
<Text>{`startTime: ${
startUpTiming == null ? 'N/A' : startUpTiming.startTime
} ms`}</Text>
<Text>
{`executeJavaScriptBundleEntryPointStart: ${
startUpTiming == null
? 'N/A'
: startUpTiming.executeJavaScriptBundleEntryPointStart
} ms`}
</Text>
<Text>{`executeJavaScriptBundleEntryPointEnd: ${
startUpTiming == null
? 'N/A'
: startUpTiming.executeJavaScriptBundleEntryPointEnd
} ms`}</Text>
<Text>{`endTime: ${
startUpTiming == null ? 'N/A' : startUpTiming.endTime
} ms`}</Text>
</View>
</View>
</RNTesterPage>
);
}
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<typeof MemoryExample> {
return <MemoryExample />;
},
},
{
title: 'performance.reactNativeStartupTiming',
render: function (): React.Element<typeof StartupTimingExample> {
return <StartupTimingExample />;
},
},
];