Skip to content

Commit

Permalink
docs: added TimedRender for inline render measurement, picked it from…
Browse files Browse the repository at this point in the history
… Tamagui Sandbox
  • Loading branch information
Efstathios Ntonas committed Jul 29, 2023
1 parent 9c8958e commit fd2d5ec
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
7 changes: 5 additions & 2 deletions App.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ import { Button, StyleSheet, Text, View } from "react-native";
import { useState } from "react";
import { useFonts } from "expo-font";

import Dripsy from "./components/Dripsy";
import EmotionNative from "./components/EmotionNative";
import Native from "./components/ReactNative";
import NativeWind from "./components/NativeWind";
import Restyle from "./components/Restyle";
import StyledComponents from "./components/StyledComponents";
import Tamagui from "./components/Tamagui";
import Dripsy from "./components/Dripsy";
import TimedRender from "./components/TimedRender";
import { Zephyr } from "./components/Zephyr";

export default function App() {
Expand Down Expand Up @@ -68,7 +69,9 @@ export default function App() {
/>
<Button title="Zephyr" onPress={onStyleTypePress("Zephyr")} />
{styleType ? (
<Text style={styles.text}>Rendering with {styleType}</Text>
<TimedRender key={styleType}>
<Text style={styles.text}>Rendering with {styleType}</Text>
</TimedRender>
) : null}
{renderStyleLibrary()}
</View>
Expand Down
27 changes: 27 additions & 0 deletions components/TimedRender.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/* picked from Tamagui Sandbox\
https://github.com/tamagui/tamagui/blob/a4cc57455c71287cc0ef995c4f55e52452504f79/apps/kitchen-sink/src/Sandbox.tsx#L82
*/

import { useLayoutEffect, useState } from "react";
import { StyleSheet, Text } from "react-native";
function TimedRender(props) {
const [start] = useState(Date.now());
const [end, setEnd] = useState(0);

useLayoutEffect(() => {
setEnd(Date.now());
}, []);

return (
<>
{!!end && <Text style={styles.text}>Took {end - start}ms</Text>}
{props.children}
</>
);
}

const styles = StyleSheet.create({
text: { color: "green", marginTop: 12, fontSize: 18 },
});

export default TimedRender;

0 comments on commit fd2d5ec

Please sign in to comment.