-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
199 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,112 @@ | ||
import React from 'react'; | ||
import { Button, StyleSheet, Text, View } from 'react-native'; | ||
import { getTimeSinceStartup } from 'react-native-startup-time'; | ||
import React, { Fragment } from 'react'; | ||
import { | ||
SafeAreaView, | ||
ScrollView, | ||
StatusBar, | ||
StyleSheet, | ||
Text, | ||
View, | ||
} from 'react-native'; | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
...StyleSheet.absoluteFillObject, | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
}, | ||
label: { | ||
marginTop: 16, | ||
}, | ||
}); | ||
import { | ||
Colors, | ||
DebugInstructions, | ||
Header, | ||
LearnMoreLinks, | ||
ReloadInstructions, | ||
} from 'react-native/Libraries/NewAppScreen'; | ||
import { StartupTime } from 'react-native-startup-time'; | ||
|
||
const App = () => { | ||
const [label, setLabel] = React.useState(''); | ||
const refreshLabel = React.useCallback(() => { | ||
getTimeSinceStartup().then((time) => { | ||
console.log(`Time since startup: ${time} ms`); | ||
setLabel(`Time since startup: ${time} ms`); | ||
}); | ||
}, []); | ||
React.useEffect(() => { | ||
refreshLabel(); | ||
}, [refreshLabel]); | ||
return ( | ||
<View style={styles.container}> | ||
<Button title="Refresh" onPress={refreshLabel} /> | ||
<Text style={styles.label}>{label}</Text> | ||
</View> | ||
<Fragment> | ||
<StatusBar barStyle="dark-content" /> | ||
<SafeAreaView> | ||
<ScrollView | ||
contentInsetAdjustmentBehavior="automatic" | ||
style={styles.scrollView} | ||
> | ||
<Header /> | ||
{global.HermesInternal == null ? null : ( | ||
<View style={styles.engine}> | ||
<Text style={styles.footer}>Engine: Hermes</Text> | ||
</View> | ||
)} | ||
<View style={styles.body}> | ||
<View style={styles.sectionContainer}> | ||
<Text style={styles.sectionTitle}>Step One</Text> | ||
<Text style={styles.sectionDescription}> | ||
Edit <Text style={styles.highlight}>App.js</Text> to change this | ||
screen and then come back to see your edits. | ||
</Text> | ||
</View> | ||
<View style={styles.sectionContainer}> | ||
<Text style={styles.sectionTitle}>See Your Changes</Text> | ||
<Text style={styles.sectionDescription}> | ||
<ReloadInstructions /> | ||
</Text> | ||
</View> | ||
<View style={styles.sectionContainer}> | ||
<Text style={styles.sectionTitle}>Debug</Text> | ||
<Text style={styles.sectionDescription}> | ||
<DebugInstructions /> | ||
</Text> | ||
</View> | ||
<View style={styles.sectionContainer}> | ||
<Text style={styles.sectionTitle}>Learn More</Text> | ||
<Text style={styles.sectionDescription}> | ||
Read the docs to discover what to do next: | ||
</Text> | ||
</View> | ||
<LearnMoreLinks /> | ||
</View> | ||
</ScrollView> | ||
<StartupTime ready={true} style={styles.startupTime} /> | ||
</SafeAreaView> | ||
</Fragment> | ||
); | ||
}; | ||
|
||
App.displayName = 'App'; | ||
const styles = StyleSheet.create({ | ||
scrollView: { | ||
backgroundColor: Colors.lighter, | ||
}, | ||
engine: { | ||
position: 'absolute', | ||
right: 0, | ||
}, | ||
body: { | ||
backgroundColor: Colors.white, | ||
}, | ||
sectionContainer: { | ||
marginTop: 32, | ||
paddingHorizontal: 24, | ||
}, | ||
sectionTitle: { | ||
fontSize: 24, | ||
fontWeight: '600', | ||
color: Colors.black, | ||
}, | ||
sectionDescription: { | ||
marginTop: 8, | ||
fontSize: 18, | ||
fontWeight: '400', | ||
color: Colors.dark, | ||
}, | ||
highlight: { | ||
fontWeight: '700', | ||
}, | ||
footer: { | ||
color: Colors.dark, | ||
fontSize: 12, | ||
fontWeight: '600', | ||
padding: 4, | ||
paddingRight: 12, | ||
textAlign: 'right', | ||
}, | ||
startupTime: { | ||
top: 24, | ||
}, | ||
}); | ||
|
||
export default App; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3047,9 +3047,9 @@ minimist@^1.1.1, minimist@^1.2.0: | |
integrity sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ= | ||
|
||
minipass@^2.2.1, minipass@^2.3.5: | ||
version "2.5.0" | ||
resolved "https://registry.yarnpkg.com/minipass/-/minipass-2.5.0.tgz#dddb1d001976978158a05badfcbef4a771612857" | ||
integrity sha512-9FwMVYhn6ERvMR8XFdOavRz4QK/VJV8elU1x50vYexf9lslDcWe/f4HBRxCPd185ekRSjU6CfYyJCECa/CQy7Q== | ||
version "2.5.1" | ||
resolved "https://registry.yarnpkg.com/minipass/-/minipass-2.5.1.tgz#cf435a9bf9408796ca3a3525a8b851464279c9b8" | ||
integrity sha512-dmpSnLJtNQioZFI5HfQ55Ad0DzzsMAb+HfokwRTNXwEQjepbTkl5mtIlSVxGIkOkxlpX7wIn5ET/oAd9fZ/Y/Q== | ||
dependencies: | ||
safe-buffer "^5.1.2" | ||
yallist "^3.0.0" | ||
|
@@ -3644,7 +3644,7 @@ react-is@^16.8.1, react-is@^16.8.4: | |
integrity sha512-tJBzzzIgnnRfEm046qRcURvwQnZVXmuCbscxUO5RWrGTXpon2d4c8mI0D8WE6ydVIm29JiLB6+RslkIvym9Rjw== | ||
|
||
"react-native-startup-time@file:..": | ||
version "1.0.0-alpha1" | ||
version "1.0.0" | ||
|
||
[email protected]: | ||
version "0.60.5" | ||
|
@@ -3689,9 +3689,9 @@ react-proxy@^1.1.7: | |
react-deep-force-update "^1.0.0" | ||
|
||
react-refresh@^0.4.0: | ||
version "0.4.1" | ||
resolved "https://registry.yarnpkg.com/react-refresh/-/react-refresh-0.4.1.tgz#2b1e4b1fe932de30c32aec25a0ac777e60bc156e" | ||
integrity sha512-My+vtJ3hCT2sOog3g0h9a9J96IaHkIAcencxhe7HtMVQYpNNyJnr+bE9bjcwfwTBi13tkb7oDDCbRtfvK7iiKQ== | ||
version "0.4.2" | ||
resolved "https://registry.yarnpkg.com/react-refresh/-/react-refresh-0.4.2.tgz#54a277a6caaac2803d88f1d6f13c1dcfbd81e334" | ||
integrity sha512-kv5QlFFSZWo7OlJFNYbxRtY66JImuP2LcrFgyJfQaf85gSP+byzG21UbDQEYjU7f//ny8rwiEkO6py2Y+fEgAQ== | ||
|
||
react-transform-hmr@^1.0.4: | ||
version "1.0.4" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,8 @@ | ||
import * as React from 'react'; | ||
import { StyleProp, ViewStyle } from 'react-native'; | ||
|
||
export declare const getTimeSinceStartup: () => Promise<number>; | ||
export declare const StartupTime: React.FC<{ | ||
style?: StyleProp<ViewStyle>; | ||
ready?: boolean; | ||
}>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,34 @@ | ||
import { NativeModules } from 'react-native'; | ||
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> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters