App.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /**
  2. * Sample React Native App
  3. * https://github.com/facebook/react-native
  4. *
  5. * @format
  6. * @flow strict-local
  7. */
  8. import React from 'react';
  9. import type {Node} from 'react';
  10. import {
  11. Alert,
  12. Button,
  13. SafeAreaView,
  14. ScrollView,
  15. StatusBar,
  16. StyleSheet,
  17. Text,
  18. useColorScheme,
  19. View,
  20. } from 'react-native';
  21. import {
  22. Colors,
  23. DebugInstructions,
  24. Header,
  25. LearnMoreLinks,
  26. ReloadInstructions,
  27. } from 'react-native/Libraries/NewAppScreen';
  28. import Toolbar from './app/components/toolbar';
  29. import Dialog from './app/components/Dialog';
  30. const Section = ({children, title}): Node => {
  31. const isDarkMode = useColorScheme() === 'dark';
  32. return (
  33. <View style={styles.sectionContainer}>
  34. <Text
  35. style={[
  36. styles.sectionTitle,
  37. {
  38. color: isDarkMode ? Colors.white : Colors.black,
  39. },
  40. ]}>
  41. {title}
  42. </Text>
  43. <Text
  44. style={[
  45. styles.sectionDescription,
  46. {
  47. color: isDarkMode ? Colors.light : Colors.dark,
  48. },
  49. ]}>
  50. {children}
  51. </Text>
  52. </View>
  53. );
  54. };
  55. const App: () => Node = () => {
  56. const isDarkMode = useColorScheme() === 'dark';
  57. const backgroundStyle = {
  58. backgroundColor: isDarkMode ? Colors.darker : Colors.lighter,
  59. };
  60. return (
  61. <SafeAreaView style={backgroundStyle}>
  62. <Toolbar/>
  63. <ScrollView
  64. contentInsetAdjustmentBehavior="automatic"
  65. style={backgroundStyle}>
  66. <Header />
  67. <View
  68. style={{
  69. backgroundColor: isDarkMode ? Colors.black : Colors.white,
  70. }}>
  71. <Section title="Step One 1">
  72. Edit <Text style={styles.highlight}>App.js</Text> to change this
  73. screen and then come back to see your edits.
  74. </Section>
  75. <Button
  76. style={{
  77. height: 120,
  78. backgroundColor: Colors.black,
  79. }}
  80. onPress={() => {
  81. requestAnimationFrame(() => {
  82. Dialog.showDialog({title:'邠心', message:'Hello World!', callback:() => {
  83. toastShort('试试就试试')
  84. }});
  85. });
  86. }}
  87. title="点我试试"
  88. />
  89. <View style={{padding: 16}}>
  90. <Button onPress={() => {
  91. console.log('navigator', navigator)
  92. console.log('geolocation', navigator.geolocation)
  93. this.navigator.geolocation.getCurrentPosition((location) => {
  94. let latlng = {
  95. latitude: location.coords.latitude,
  96. longitude: location.coords.longitude,
  97. latitudeDelta: 0.0922,
  98. longitudeDelta: 0.0421,
  99. }
  100. Dialog.showDialog({title: 'Geolocation', message: JSON.stringify(latlng)})
  101. })
  102. }} title='定位'/>
  103. </View>
  104. <Section title="See Your Changes">
  105. <ReloadInstructions />
  106. </Section>
  107. <Section title="Debug">
  108. <DebugInstructions />
  109. </Section>
  110. <Section title="Learn More">
  111. Read the docs to discover what to do next:
  112. </Section>
  113. <LearnMoreLinks />
  114. </View>
  115. </ScrollView>
  116. </SafeAreaView>
  117. );
  118. };
  119. const styles = StyleSheet.create({
  120. sectionContainer: {
  121. marginTop: 32,
  122. paddingHorizontal: 24,
  123. },
  124. sectionTitle: {
  125. fontSize: 24,
  126. fontWeight: '600',
  127. },
  128. sectionDescription: {
  129. marginTop: 8,
  130. fontSize: 18,
  131. fontWeight: '400',
  132. },
  133. highlight: {
  134. fontWeight: '700',
  135. },
  136. });
  137. export default App;