Advertisement
Guest User

React-Navigation

a guest
Oct 18th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * Sample React Native App
  3.  * https://github.com/facebook/react-native
  4.  *
  5.  * @format
  6.  * @flow
  7.  */
  8.  
  9. import React from 'react';
  10. import {
  11.   SafeAreaView,
  12.   StyleSheet,
  13.   ScrollView,
  14.   View,
  15.   Text,
  16.   Button,
  17.   StatusBar,
  18. } from 'react-native';
  19.  
  20. import {
  21.   Header,
  22.   LearnMoreLinks,
  23.   Colors,
  24.   DebugInstructions,
  25.   ReloadInstructions,
  26. } from 'react-native/Libraries/NewAppScreen';
  27.  
  28. import { createStackNavigator, createAppContainer } from 'react-navigation-stack';
  29.  
  30. class HomeScreen extends React.Component {
  31.   render() {
  32.     return (
  33.       <>
  34.         <StatusBar barStyle="dark-content" />
  35.         <SafeAreaView>
  36.           <ScrollView
  37.             contentInsetAdjustmentBehavior="automatic"
  38.             style={styles.scrollView}>
  39.             <Header />
  40.             {global.HermesInternal == null ? null : (
  41.               <View style={styles.engine}>
  42.                 <Text style={styles.footer}>Engine: Hermes</Text>
  43.               </View>
  44.             )}
  45.             <View style={styles.body}>
  46.               <View style={styles.sectionContainer}>
  47.                 <Text style={styles.sectionTitle}>Step One</Text>
  48.                 <Text style={styles.sectionDescription}>
  49.                   Edit <Text style={styles.highlight}>App.js</Text> to change this
  50.                   screen and then come back to see your edits.
  51.               </Text>
  52.               </View>
  53.               <View style={styles.sectionContainer}>
  54.                 <Text style={styles.sectionTitle}>See Your Changes</Text>
  55.                 <Text style={styles.sectionDescription}>
  56.                   <ReloadInstructions />
  57.                 </Text>
  58.               </View>
  59.               <View style={styles.sectionContainer}>
  60.                 <Text style={styles.sectionTitle}>Debug</Text>
  61.                 <Text style={styles.sectionDescription}>
  62.                   <DebugInstructions />
  63.                 </Text>
  64.               </View>
  65.               <View style={styles.sectionContainer}>
  66.                 <Text style={styles.sectionTitle}>Learn More</Text>
  67.                 <Text style={styles.sectionDescription}>
  68.                   Read the docs to discover what to do next:
  69.               </Text>
  70.               </View>
  71.               <View style={styles.sectionContainer}>
  72.                 <Button
  73.                   title="Go to Details... again"
  74.                   onPress={() => this.props.navigation.navigate('Details')}
  75.                 />
  76.               </View>
  77.               <LearnMoreLinks />
  78.             </View>
  79.           </ScrollView>
  80.         </SafeAreaView>
  81.       </>
  82.     );
  83.   }
  84. }
  85.  
  86. class DetailsScreen extends React.Component {
  87.   render() {
  88.     return (
  89.       <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
  90.         <Text>Details Screen</Text>
  91.         <Button
  92.           title="Go to Details... again"
  93.           onPress={() => this.props.navigation.navigate('Details')}
  94.         />
  95.       </View>
  96.     );
  97.   }
  98. }
  99.  
  100. const RootStack = createStackNavigator(
  101.   {
  102.     Home: HomeScreen,
  103.     Details: DetailsScreen,
  104.   },
  105.   {
  106.     initialRouteName: 'Home',
  107.   }
  108. );
  109.  
  110. const AppContainer = createAppContainer(RootStack);
  111.  
  112. const styles = StyleSheet.create({
  113.   scrollView: {
  114.     backgroundColor: Colors.lighter,
  115.   },
  116.   engine: {
  117.     position: 'absolute',
  118.     right: 0,
  119.   },
  120.   body: {
  121.     backgroundColor: Colors.white,
  122.   },
  123.   sectionContainer: {
  124.     marginTop: 32,
  125.     paddingHorizontal: 24,
  126.   },
  127.   sectionTitle: {
  128.     fontSize: 24,
  129.     fontWeight: '600',
  130.     color: Colors.black,
  131.   },
  132.   sectionDescription: {
  133.     marginTop: 8,
  134.     fontSize: 18,
  135.     fontWeight: '400',
  136.     color: Colors.dark,
  137.   },
  138.   highlight: {
  139.     fontWeight: '700',
  140.   },
  141.   footer: {
  142.     color: Colors.dark,
  143.     fontSize: 12,
  144.     fontWeight: '600',
  145.     padding: 4,
  146.     paddingRight: 12,
  147.     textAlign: 'right',
  148.   },
  149. });
  150.  
  151. export default class App extends React.Component {
  152.   render() {
  153.     return <AppContainer />;
  154.   }
  155. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement