Advertisement
Slightom

createShot

Mar 11th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React from 'react';
  2. import {
  3.   Image, Button, View, Text, StyleSheet, TextInput, ScrollView, TouchableOpacity,
  4.   AsyncStorage, Picker, Item
  5. } from 'react-native';
  6. import { StackNavigator } from 'react-navigation'; // Version can be specified in package.json
  7. import DatePicker from 'react-native-datepicker';
  8. import CheckBox from 'react-native-checkbox';
  9.  
  10.  
  11. class CreateShot1Screen extends React.Component {
  12.  
  13.   static navigationOptions = {
  14.     title: 'CreateShot 1/4',
  15.   };
  16.  
  17.   constructor(props) {
  18.     super(props);
  19.     this.state = { name: '' };
  20.   }
  21.  
  22.   render() {
  23.     return (
  24.       <View style={styles.wrapper}>
  25.         <ScrollView>
  26.           <View style={styles.container}>
  27.             <Text style={styles.screenHeader}>Give it a name!</Text>
  28.             <TextInput style={styles.textInput} placeholder='Name'
  29.               onChangeText={(name) => this.setState({ name })}
  30.               value={this.state.name} />
  31.             <Image source={require('./logo.png')} style={styles.logo} />
  32.             <TouchableOpacity
  33.               style={styles.buttonNext}
  34.               onPress={() => {
  35.                 this.props.navigation.navigate('CreateShot2', {
  36.                   name: this.state.name,
  37.                 });
  38.               }}>
  39.               <Text style={styles.buttonText}>Next</Text>
  40.             </TouchableOpacity>
  41.           </View>
  42.         </ScrollView>
  43.       </View>
  44.     );
  45.   }
  46. }
  47.  
  48. class CreateShot2Screen extends React.Component {
  49.  
  50.   static navigationOptions = {
  51.     title: 'CreateShot 2/4',
  52.   };
  53.  
  54.   constructor(props) {
  55.     super(props);
  56.     var date = new Date().getDate();
  57.     var month = new Date().getMonth() + 1;
  58.     var year = new Date().getFullYear();
  59.  
  60.     this.state = {
  61.       premiereDate: (year + '-' + month + '-' + date),
  62.       withIce: true,
  63.     };
  64.   }
  65.  
  66.   render() {
  67.     const { params } = this.props.navigation.state;
  68.     const name = params ? params.name : null;
  69.     return (
  70.       <View style={styles.wrapper}>
  71.         <ScrollView>
  72.           <View style={styles.container}>
  73.             <View style={{ alignItems: 'center', }}>
  74.               <Text style={styles.screenHeader}>Amount of vodka [ml]:</Text>
  75.               <TextInput
  76.                 style={styles.textInput}
  77.                 keyboardType='numeric'
  78.                 placeholder='25'
  79.                 onChangeText={(text) => this.setState({ amountOfVodka: text })}
  80.                 value={this.state.amountOfVodka ? this.state.amountOfVodka : ''}
  81.                 maxLength={3}  //setting limit of input
  82.               />
  83.  
  84.               <Text style={styles.screenHeader}>Amount of juice [ml]:</Text>
  85.               <TextInput
  86.                 style={styles.textInput}
  87.                 keyboardType='numeric'
  88.                 placeholder='10'
  89.                 onChangeText={(text) => this.setState({ amountOfJuice: text })}
  90.                 value={this.state.amountOfJuice ? this.state.amountOfJuice : ''}
  91.                 maxLength={3}  //setting limit of input
  92.               />
  93.  
  94.               <CheckBox
  95.                 style={{ alignItems: 'center', }}
  96.                 label='With ice'
  97.                 checked={this.state.withIce}
  98.                 onChange={(checked) => this.setState({ withIce: !checked })}
  99.               />
  100.  
  101.               <Text style={styles.screenHeader}>Premiere Date:</Text>
  102.               <DatePicker
  103.                 style={{ width: 280, marginBottom: 20, }}
  104.                 date={this.state.premiereDate}
  105.                 mode="date"
  106.                 placeholder="select date"
  107.                 format="YYYY-MM-DD"
  108.                 minDate="2017-05-01"
  109.                 maxDate="2019-06-01"
  110.                 confirmBtnText="Confirm"
  111.                 cancelBtnText="Cancel"
  112.                 customStyles={{
  113.                   dateIcon: {
  114.                     position: 'absolute',
  115.                     left: 0,
  116.                     top: 4,
  117.                     marginLeft: 0
  118.                   },
  119.                   dateInput: {
  120.                     marginLeft: 36
  121.                   }
  122.                 }}
  123.                 onDateChange={(date) => { this.setState({ premiereDate: date }) }}
  124.               />
  125.               <View style={styles.navigationButtonsWrapper}>
  126.                 <TouchableOpacity
  127.                   style={styles.buttonPrevious}
  128.                   onPress={() => {
  129.                     this.props.navigation.goBack();
  130.                   }}>
  131.                   <Text style={styles.buttonText}>Back</Text>
  132.                 </TouchableOpacity>
  133.                 <TouchableOpacity
  134.                   style={styles.buttonNext}
  135.                   onPress={() => {
  136.                     this.props.navigation.navigate('CreateShot3', {
  137.                       name: name,
  138.                       amountOfVodka: this.state.amountOfVodka,
  139.                       amountOfJuice: this.state.amountOfJuice,
  140.                       withIce: this.state.withIce + '',
  141.                       premiereDate: this.state.premiereDate,
  142.                     });
  143.                   }}>
  144.                   <Text style={styles.buttonText}>Next</Text>
  145.                 </TouchableOpacity>
  146.               </View>
  147.             </View>
  148.           </View>
  149.         </ScrollView>
  150.       </View >
  151.     );
  152.   }
  153. }
  154.  
  155. class CreateShot3Screen extends React.Component {
  156.  
  157.   static navigationOptions = {
  158.     title: 'CreateShot 3/4',
  159.   };
  160.  
  161.   constructor(props) {
  162.     super(props);
  163.  
  164.     this.state = {
  165.       vodka: 'żubrówka',
  166.       juice: 'raspberry',
  167.     };
  168.   }
  169.  
  170.   render() {
  171.     /* 2. Read the params from the navigation state */
  172.     const { params } = this.props.navigation.state;
  173.     const name = params ? params.name : null;
  174.     const amountOfVodka = params ? params.amountOfVodka : null;
  175.     const amountOfJuice = params ? params.amountOfJuice : null;
  176.     const withIce = params ? params.withIce : null;
  177.     const premiereDate = params ? params.premiereDate : null;
  178.  
  179.     return (
  180.       <View style={styles.wrapper}>
  181.         <ScrollView>
  182.           <View style={styles.container}>
  183.  
  184.             <Text style={styles.screenHeader}>ice:{withIce}</Text>
  185.             <Text style={styles.screenHeader}>Kind of vodka:</Text>
  186.             <Picker
  187.               style={styles.picker}
  188.               selectedValue={this.state.vodka}
  189.               onValueChange={(itemValue) => this.setState({ vodka: itemValue })}>
  190.               <Picker.Item label={"żubrówka"} value={"żubrówka"} />
  191.               <Picker.Item label={'stock'} value={"stock"} />
  192.               <Picker.Item label={'wyborowa'} value={"wyborowa"} />
  193.               <Picker.Item label={'finlandia'} value={"finlandia"} />
  194.               <Picker.Item label={'soplica'} value={"soplica"} />
  195.             </Picker>
  196.  
  197.             <Text style={styles.screenHeader}>Kind of juice:</Text>
  198.             <Picker
  199.               style={styles.picker}
  200.               selectedValue={this.state.juice}
  201.               onValueChange={(itemValue) => this.setState({ juice: itemValue })}>
  202.               <Picker.Item label={"raspberry"} value={"raspberry"} />
  203.               <Picker.Item label={'banana'} value={"banana"} />
  204.               <Picker.Item label={'orange'} value={"orange"} />
  205.               <Picker.Item label={'strawberry'} value={"strawberry"} />
  206.               <Picker.Item label={'pineapple'} value={"pineapple"} />
  207.             </Picker>
  208.  
  209.             <View style={styles.navigationButtonsWrapper}>
  210.               <TouchableOpacity
  211.                 style={styles.buttonPrevious}
  212.                 onPress={() => {
  213.                   this.props.navigation.goBack();
  214.                 }}>
  215.                 <Text style={styles.buttonText}>Back</Text>
  216.               </TouchableOpacity>
  217.               <TouchableOpacity
  218.                 style={styles.buttonNext}
  219.                 onPress={() => {
  220.                   this.props.navigation.navigate('CreateShot4', {
  221.                     name: name,
  222.                     amountOfVodka: amountOfVodka,
  223.                     amountOfJuice: amountOfJuice,
  224.                     withIce: withIce,
  225.                     premiereDate: premiereDate,
  226.                     vodka: this.state.vodka,
  227.                     juice: this.state.juice,
  228.                   });
  229.                 }}>
  230.                 <Text style={styles.buttonText}>Next</Text>
  231.               </TouchableOpacity>
  232.             </View>
  233.  
  234.           </View>
  235.         </ScrollView>
  236.       </View >
  237.     );
  238.   }
  239. }
  240.  
  241. class CreateShot4Screen extends React.Component {
  242.  
  243.   static navigationOptions = {
  244.     title: 'CreateShot 4/4',
  245.   };
  246.  
  247.   constructor(props) {
  248.     super(props);
  249.  
  250.     this.state = {
  251.  
  252.     };
  253.   }
  254.  
  255.   render() {
  256.     /* 2. Read the params from the navigation state */
  257.     const { params } = this.props.navigation.state;
  258.     const name = params ? params.name : null;
  259.     const amountOfVodka = params ? params.amountOfVodka : null;
  260.     const amountOfJuice = params ? params.amountOfJuice : null;
  261.     const withIce = params ? params.withIce : null;
  262.     const premiereDate = params ? params.premiereDate : null;
  263.     const vodka = params ? params.vodka : null;
  264.     const juice = params ? params.juice : null;
  265.  
  266.     return (
  267.       <View style={styles.wrapper}>
  268.         <ScrollView>
  269.           <View style={styles.container}>
  270.  
  271.               <Text style={styles.header2}>Name: <Text style={styles.header3}>{name}</Text></Text>
  272.               <Text style={styles.header2}>AmountOfVodka: <Text style={styles.header3} ml>{amountOfVodka}</Text></Text>
  273.               <Text style={styles.header2}>AmountOfJuice: <Text style={styles.header3} ml>{amountOfJuice}</Text></Text>
  274.               <Text style={styles.header2}>WithIce: <Text style={styles.header3}>{withIce}</Text></Text>
  275.               <Text style={styles.header2}>PremiereDate: <Text style={styles.header3}>{premiereDate}</Text></Text>
  276.               <Text style={styles.header2}>Vodka: <Text style={styles.header3}>{vodka}</Text></Text>
  277.               <Text style={styles.header2}>Juice: <Text style={styles.header3}>{juice}</Text></Text>
  278.               <View style={styles.navigationButtonsWrapper}>
  279.               </View>
  280.               <TouchableOpacity
  281.                 style={styles.buttonPrevious}
  282.                 onPress={() => {
  283.                   this.props.navigation.goBack();
  284.                 }}>
  285.                 <Text style={styles.buttonText}>Back</Text>
  286.               </TouchableOpacity>
  287.  
  288.           </View>
  289.         </ScrollView>
  290.       </View >
  291.     );
  292.   }
  293. }
  294.  
  295.  
  296. const styles = StyleSheet.create({
  297.   wrapper: {
  298.     flex: 1,
  299.     backgroundColor: 'lightblue',
  300.   },
  301.   navigationButtonsWrapper: {
  302.     flex: 1,
  303.     flexDirection: 'row',
  304.     alignSelf: 'stretch',
  305.     marginBottom: 20,
  306.     marginTop: 40,
  307.   },
  308.   container: {
  309.     alignContent: 'center',
  310.     // alignItems: 'center',
  311.     justifyContent: 'center',
  312.     paddingLeft: 40,
  313.     paddingRight: 40,
  314.  
  315.   },
  316.   screenHeader: {
  317.     fontSize: 26,
  318.     fontWeight: 'bold',
  319.     marginTop: 20,
  320.     marginBottom: 20,
  321.     textAlign: 'center',
  322.   },
  323.   screenHeader: {
  324.     fontSize: 26,
  325.     fontWeight: 'bold',
  326.     marginTop: 20,
  327.     marginBottom: 20,
  328.     textAlign: 'center',
  329.   },
  330.   header2: {
  331.     fontSize: 26,
  332.     fontWeight: 'bold',
  333.     marginTop: 20,
  334.   },
  335.   header3: {
  336.     fontSize: 26,
  337.     fontWeight: 'bold',
  338.     marginTop: 20,
  339.     textAlign: 'center',
  340.     color: 'red'
  341.   },
  342.   logo: {
  343.     height: 280,
  344.     marginBottom: 40,
  345.   },
  346.   textInput: {
  347.     fontSize: 20,
  348.     alignSelf: 'stretch',
  349.     backgroundColor: 'white',
  350.     padding: 16,
  351.     marginBottom: 20,
  352.     textAlign: 'center',
  353.     // borderWidth: 1,
  354.   },
  355.   buttonPrevious: {
  356.     flex: 1,
  357.     alignSelf: 'stretch',
  358.     backgroundColor: '#FF3333',
  359.     alignItems: 'center',
  360.     padding: 10,
  361.     marginRight: 5,
  362.   },
  363.   buttonNext: {
  364.     flex: 1,
  365.     alignSelf: 'stretch',
  366.     backgroundColor: '#33CC00',
  367.     alignItems: 'center',
  368.     padding: 10,
  369.   },
  370.   buttonText: {
  371.     fontSize: 20,
  372.   },
  373.   picker: {
  374.     backgroundColor: 'white',
  375.     marginBottom: 20,
  376.   }
  377. });
  378.  
  379. const RootStack = StackNavigator(
  380.   {
  381.     CreateShot1: {
  382.       screen: CreateShot1Screen,
  383.     },
  384.     CreateShot2: {
  385.       screen: CreateShot2Screen,
  386.     },
  387.     CreateShot3: {
  388.       screen: CreateShot3Screen,
  389.     },
  390.     CreateShot4: {
  391.       screen: CreateShot4Screen,
  392.     },
  393.   },
  394.   {
  395.     initialRouteName: 'CreateShot1',
  396.     navigationOptions: {
  397.       headerStyle: {
  398.         backgroundColor: '#f4511e',
  399.       },
  400.       headerTintColor: '#fff',
  401.       headerTitleStyle: {
  402.         fontWeight: 'bold',
  403.       }
  404.     }
  405.   }
  406. );
  407.  
  408. export default class App extends React.Component {
  409.  
  410.   render() {
  411.     return <RootStack />;
  412.   }
  413. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement