App.tsx 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /**
  2. * Sample React Native App
  3. * https://github.com/facebook/react-native
  4. *
  5. * @format
  6. */
  7. import React from 'react';
  8. import type {PropsWithChildren} from 'react';
  9. import {
  10. ScrollView,
  11. StatusBar,
  12. StyleSheet,
  13. Text,
  14. useColorScheme,
  15. View,
  16. } from 'react-native';
  17. import {
  18. Colors,
  19. DebugInstructions,
  20. Header,
  21. LearnMoreLinks,
  22. ReloadInstructions,
  23. } from 'react-native/Libraries/NewAppScreen';
  24. type SectionProps = PropsWithChildren<{
  25. title: string;
  26. }>;
  27. function Section({children, title}: SectionProps): React.JSX.Element {
  28. const isDarkMode = useColorScheme() === 'dark';
  29. return (
  30. <View style={styles.sectionContainer}>
  31. <Text
  32. style={[
  33. styles.sectionTitle,
  34. {
  35. color: isDarkMode ? Colors.white : Colors.black,
  36. },
  37. ]}>
  38. {title}
  39. </Text>
  40. <Text
  41. style={[
  42. styles.sectionDescription,
  43. {
  44. color: isDarkMode ? Colors.light : Colors.dark,
  45. },
  46. ]}>
  47. {children}
  48. </Text>
  49. </View>
  50. );
  51. }
  52. function App(): React.JSX.Element {
  53. const isDarkMode = useColorScheme() === 'dark';
  54. const backgroundStyle = {
  55. backgroundColor: isDarkMode ? Colors.darker : Colors.lighter,
  56. };
  57. /*
  58. * To keep the template simple and small we're adding padding to prevent view
  59. * from rendering under the System UI.
  60. * For bigger apps the recommendation is to use `react-native-safe-area-context`:
  61. * https://github.com/AppAndFlow/react-native-safe-area-context
  62. *
  63. * You can read more about it here:
  64. * https://github.com/react-native-community/discussions-and-proposals/discussions/827
  65. */
  66. const safePadding = '5%';
  67. return (
  68. <View style={backgroundStyle}>
  69. <StatusBar
  70. barStyle={isDarkMode ? 'light-content' : 'dark-content'}
  71. backgroundColor={backgroundStyle.backgroundColor}
  72. />
  73. <ScrollView
  74. style={backgroundStyle}>
  75. <View style={{paddingRight: safePadding}}>
  76. <Header/>
  77. </View>
  78. <View
  79. style={{
  80. backgroundColor: isDarkMode ? Colors.black : Colors.white,
  81. paddingHorizontal: safePadding,
  82. paddingBottom: safePadding,
  83. }}>
  84. <Section title="Step One">
  85. Edit <Text style={styles.highlight}>App.tsx</Text> to change this
  86. screen and then come back to see your edits.
  87. </Section>
  88. <Section title="See Your Changes">
  89. <ReloadInstructions />
  90. </Section>
  91. <Section title="Debug">
  92. <DebugInstructions />
  93. </Section>
  94. <Section title="Learn More">
  95. Read the docs to discover what to do next:
  96. </Section>
  97. <LearnMoreLinks />
  98. </View>
  99. </ScrollView>
  100. </View>
  101. );
  102. }
  103. const styles = StyleSheet.create({
  104. sectionContainer: {
  105. marginTop: 32,
  106. paddingHorizontal: 24,
  107. },
  108. sectionTitle: {
  109. fontSize: 24,
  110. fontWeight: '600',
  111. },
  112. sectionDescription: {
  113. marginTop: 8,
  114. fontSize: 18,
  115. fontWeight: '400',
  116. },
  117. highlight: {
  118. fontWeight: '700',
  119. },
  120. });
  121. export default App;