-
Notifications
You must be signed in to change notification settings - Fork 14
/
index.js
34 lines (30 loc) · 949 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import React from 'react';
import { NativeModules, StyleSheet, Text, View } from 'react-native';
const { RNStartupTime } = NativeModules;
const styles = StyleSheet.create({
container: {
position: 'absolute',
backgroundColor: '#FFF',
top: 8,
right: 8,
padding: 8,
},
});
export const getTimeSinceStartup = () => RNStartupTime.getTimeSinceStartup();
export const StartupTime = ({ style, ready = true }) => {
const [time, setTime] = React.useState('');
const [layoutComplete, setLayoutComplete] = React.useState('');
const onLayout = React.useCallback(() => setLayoutComplete(true), [
setLayoutComplete,
]);
React.useEffect(() => {
if (ready && layoutComplete) {
getTimeSinceStartup().then((t) => setTime(t));
}
}, [ready, layoutComplete, setTime]);
return (
<View style={[styles.container, style]} onLayout={onLayout}>
<Text>{`startup time: ${time} ms`}</Text>
</View>
);
};