Advertisement
eyalabadi98

test

Jun 27th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.32 KB | None | 0 0
  1. import _ from 'lodash';
  2. import React, { Component } from 'react';
  3. import { AppRegistry, View, Text, Image, ScrollView, TextInput, Switch, KeyboardAvoidingView, LayoutAnimation, TouchableWithoutFeedback, Keyboard, Dimensions } from 'react-native';
  4. import Card from './../Card/Card';
  5. import CardSection from './../CardSection/index';
  6. import CardSection2 from './../CardSection2/index';
  7. import CardSectionInput from './../CardSectionInput/index';
  8. import Input from './../Input/index';
  9. import Button from './../Button/index';
  10. import Header from './../Header/index';
  11. import DatePicker from 'react-native-datepicker';
  12. import SliderCarSeats from './../SliderCarSeats/index';
  13. import CarView from './../CarView/index';
  14. import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view'
  15. //import SegmentedControlTab from 'react-native-segmented-control-tab';
  16. //import Routes from './../config/routes';
  17. import GoogleAutoComplete from './../GoogleAutoComplete/index';
  18. import { connect } from 'react-redux';
  19. import { DriverAddForm, ridesFetch } from './../../actions';
  20.  
  21. const rightNow = new Date();
  22. const currentDate = rightNow.toISOString().slice(0,10).replace(/-/g,"-");
  23. const widthScreen = Dimensions.get('window').width;
  24.  
  25. console.log(currentDate);
  26.  
  27. class MyTrip extends Component {
  28.  
  29. constructor(props) {
  30.  
  31. super(props);
  32. this.RoundTrip = this.RoundTrip.bind(this);
  33. this.props.ridesFetch();
  34. console.log('reg props are', this.props);
  35. }
  36.  
  37. shouldComponentUpdate(nextProps) {
  38. if (this.props !== nextProps) {
  39. console.log('updating with', nextProps);
  40. return true;
  41. }
  42. }
  43. componentWillUpdate() {
  44. LayoutAnimation.spring();
  45.  
  46. }
  47.  
  48. onFromChange(text) {
  49. this.props.fromChanged(text);
  50. }
  51.  
  52. RoundTrip = () => {
  53.  
  54. console.log('value of round trip ' + JSON.stringify(this.props));
  55. var roundTrip = this.props.roundTrip;
  56. if (roundTrip) {
  57. console.log('return is true')
  58.  
  59. return (
  60. <View style={{paddingLeft: 15}}>
  61. <CardSectionInput>
  62.  
  63.  
  64. <Image
  65. source={require('./../../images/dateIcon1.png')}
  66. style={styles.IconStyle}
  67. />
  68. <DatePicker
  69. style={styles.DateStyle}
  70. date={this.props.returnDate}
  71. mode='datetime'
  72. format="LLLL"
  73. minDate={currentDate}
  74. maxDate="2018-06-01"
  75. confirmBtnText="Confirm"
  76. cancelBtnText="Cancel"
  77. showIcon={false}
  78. placeholder='Return'
  79. onDateChange={text => this.props.DriverAddForm({ prop: 'returnDate', value: text })}
  80. customStyles={{
  81. dateInput: {
  82. marginLeft: 2,
  83. backgroundColor: 'white',
  84. borderWidth: 1,
  85. borderRadius: 5,
  86. borderColor: 'white',
  87. flex: 1,
  88. flexDirection: 'row',
  89. },
  90. dateText: {
  91. flexDirection: 'row',
  92. flex: 1,
  93. backgroundColor: 'transparent',
  94. color: 'black',
  95. },
  96. placeholderText: {
  97. color: '#c9c9c9',
  98. alignSelf: 'center',
  99. justifyContent: 'flex-start',
  100. flex: 1,
  101. flexDirection: 'row',
  102. fontSize: 18,
  103. }
  104. }}
  105. />
  106. </CardSectionInput>
  107. </View>
  108. );
  109. };
  110. }
  111. handleIndexChange = (index) => {
  112. this.setState({
  113. ...this.state,
  114. selectedIndex: index,
  115. });
  116. if (index == 1) {
  117. const { navigate } = this.props.navigation;
  118. navigate('DriverExtraInfo')
  119. console.log('navigating to driverinfo');
  120. }
  121. else if (index == 0) {
  122. const { navigate } = this.props.navigation;
  123. navigate('PostARide')
  124. console.log('navigating to PostARide');
  125. }
  126.  
  127. }
  128.  
  129. render() {
  130. console.log('printing pros', this.props);
  131. const { rides } = this.props;
  132.  
  133. if (rides) {
  134. return rides.map((ride, i) => {
  135. if (i === 0 && ride.food) {
  136. return <Text> value of round is {ride.food} </Text>;
  137. }
  138.  
  139. return <Text> rr </Text>;
  140. });
  141. }
  142.  
  143. return (
  144. <KeyboardAwareScrollView>
  145. <TouchableWithoutFeedback onPress={Keyboard.dismiss}>
  146. <View style={{flexDirection: 'column', flex: 1}}>
  147. <View style={{ flexDirection: 'column', paddingTop: 20 }}>
  148. <View style={{justifyContent: 'center',}}>
  149. <CardSectionInput>
  150. <Image
  151. source={require('./../../images/locationIcon.png')}
  152. style={styles.IconStyle}
  153. />
  154.  
  155. <GoogleAutoComplete
  156. placeholder='Start'
  157. placeHol="Start"
  158. minLength={2}
  159. autoFocus={false}
  160. returnKeyType={'default'}
  161. fetchDetails
  162. getDefaultValue={() => this.props.startGoogle}
  163. onPress={(value) => this.props.DriverAddForm({ prop: 'startGoogle', value: value.description })}
  164. styles={{
  165. textInputContainer: {
  166. backgroundColor: 'white',
  167. borderTopWidth: 0,
  168. borderBottomWidth:0,
  169. paddingLeft: 0
  170. },
  171. textInput: {
  172. marginLeft: 0,
  173. marginRight: 0,
  174. height: 38,
  175. color: 'white',
  176. fontSize: 16
  177. },
  178. predefinedPlacesDescription: {
  179. color: '#1faadb'
  180. },
  181.  
  182. }}
  183. currentLocation={false}
  184. />
  185. </CardSectionInput>
  186. <CardSectionInput>
  187.  
  188. <Image
  189. source={require('./../../images/locationIcon2.png')}
  190. style={styles.IconStyle}
  191. />
  192.  
  193. <GoogleAutoComplete
  194. placeholder='Start'
  195. placeHol="Stopover"
  196. minLength={2}
  197. autoFocus={false}
  198. returnKeyType={'default'}
  199. fetchDetails
  200. getDefaultValue={() => this.props.stopOverGoogle}
  201. onPress={(value) => this.props.DriverAddForm({ prop: 'stopOverGoogle', value: value.description })}
  202. styles={{
  203. textInputContainer: {
  204. backgroundColor: 'white',
  205. borderTopWidth: 0,
  206. borderBottomWidth:0
  207. },
  208. textInput: {
  209. marginLeft: 0,
  210. marginRight: 0,
  211. height: 38,
  212. color: 'white',
  213. fontSize: 16
  214. },
  215. predefinedPlacesDescription: {
  216. color: '#1faadb'
  217. },
  218. }}
  219. currentLocation={false}
  220. />
  221. {/*<Button
  222. onPress={() => this.props.carsPost({ prop: 'make', value: 'toyota' })}
  223. > Hello </Button>*/}
  224. </CardSectionInput>
  225. <CardSectionInput>
  226.  
  227. <Image
  228. source={require('./../../images/markerIcon.png')}
  229. style={styles.IconStyle}
  230. />
  231.  
  232. <GoogleAutoComplete
  233. placeHol="End"
  234. minLength={2}
  235. autoFocus={false}
  236. returnKeyType={'default'}
  237. setAddressText="efef"
  238. fetchDetails
  239. text={this.props.endGoogle}
  240. setAddressText={this.props.endGoogle}
  241. getDefaultValue={() => this.props.endGoogle}
  242. onPress={(value) => this.props.DriverAddForm({ prop: 'endGoogle', value: value.description })}
  243. styles={{
  244. textInputContainer: {
  245. backgroundColor: 'white',
  246. borderTopWidth: 0,
  247. borderBottomWidth:0
  248. },
  249. textInput: {
  250. marginLeft: 0,
  251. marginRight: 0,
  252. height: 38,
  253. color: 'white',
  254. fontSize: 16
  255. },
  256. predefinedPlacesDescription: {
  257. color: '#1faadb'
  258. },
  259.  
  260. }}
  261. currentLocation={false}
  262. />
  263.  
  264. </CardSectionInput>
  265.  
  266. <CardSectionInput>
  267. <View style={{flexDirection:'row'}}>
  268. <Image style={styles.IconStyle}/>
  269. <View style={styles.rountripView }>
  270. <Text style={styles.roundTrip}> Round Trip </Text>
  271. <View style={{backgroundColor: 'white', justifyContent: 'center'}}>
  272. <Switch
  273. onValueChange={text => this.props.DriverAddForm({ prop: 'roundTrip', value: text })}
  274. value={this.props.roundTrip}
  275. />
  276.  
  277. </View>
  278. </View>
  279. </View>
  280. </CardSectionInput>
  281. {this.RoundTrip()}
  282. {/*<Text> {this.props.rides && this.props.rides.length > 0 && this.props.rides[0].food ? this.props.rides[0].food ? '' } </Text>*/}
  283. <CardSectionInput>
  284.  
  285.  
  286.  
  287. <Image
  288. source={require('./../../images/dateIcon1.png')}
  289. style={styles.IconStyle}
  290. />
  291. <DatePicker
  292. style={styles.DateStyle}
  293. date={this.props.date}
  294. mode='datetime'
  295. onDateChange={text => this.props.DriverAddForm({ prop: 'date', value: text })}
  296. format="LLLL"
  297. minDate={currentDate}
  298. maxDate="2018-06-01"
  299. confirmBtnText="Confirm"
  300. cancelBtnText="Cancel"
  301. showIcon={false}
  302. placeholder='Departure'
  303. customStyles={{
  304. dateInput: {
  305. marginLeft: 2,
  306. backgroundColor: 'white',
  307. borderWidth: 1,
  308. borderRadius: 5,
  309. borderColor: 'white',
  310. flex: 1,
  311. flexDirection: 'row',
  312. },
  313. dateText: {
  314. flexDirection: 'row',
  315. flex: 1,
  316. backgroundColor: 'transparent',
  317. color: 'black',
  318. },
  319. placeholderText: {
  320. color: '#c9c9c9',
  321. alignSelf: 'center',
  322. justifyContent: 'flex-start',
  323. flex: 1,
  324. flexDirection: 'row',
  325. fontSize: 18,
  326.  
  327. }
  328. }}
  329.  
  330. />
  331.  
  332.  
  333. </CardSectionInput>
  334. {/*<Text> Carseats are {this.props.carSeats} </Text>*/}
  335. <CardSectionInput>
  336.  
  337. <Image style={styles.FakeIconStyle}/>
  338. <SliderCarSeats
  339. ref="sliderParent"
  340. onValueChange={value => this.props.DriverAddForm({prop: 'carSeat', value: value })}
  341. value={2}
  342. />
  343.  
  344. </CardSectionInput>
  345. <CardSectionInput>
  346. <Image
  347. source={require('./../../images/cashIcon.png')}
  348. style={styles.IconStyle}
  349. />
  350. <Input
  351. style={styles.inputStyle}
  352. onChangeText={text => this.props.DriverAddForm({prop: 'costPerSeat', value: text })}
  353. value={this.props.costPerSeat}
  354. autoCorrect={false}
  355. placeholder='Cost per Seat'
  356. keyboardType={'numeric'}
  357.  
  358. />
  359. </CardSectionInput>
  360.  
  361.  
  362.  
  363. {/*<CarView />*/}
  364.  
  365.  
  366.  
  367. </View>
  368. </View>
  369.  
  370. {/*<Text> Value of redux from is {this.props.from} </Text>
  371. <Text> Start Google : {this.props.startGoogle} </Text>
  372. <Text> Seats available: {this.props.carSeat} </Text>
  373. <Text> Seats available: {this.props.seatAvailable} </Text>
  374.  
  375.  
  376. <Text> stopover: {this.props.stopOverGoogle} </Text>
  377.  
  378.  
  379. <Text> roundTrip: {String(this.props.roundTrip)}</Text>
  380. <Text> date: {this.props.date} </Text>
  381. <Text> time: {this.props.time} </Text>
  382. <Text> costPerSeat: {this.props.costPerSeat} </Text>
  383.  
  384. <Text> Selected index: {this.props.selectedIndex} </Text>
  385. <Text> end: {this.props.endGoogle} </Text>*/}
  386.  
  387. </View>
  388. </TouchableWithoutFeedback>
  389. </KeyboardAwareScrollView>
  390. );
  391. }
  392. }
  393. const styles = {
  394. containerNoBackground: {
  395. borderBottomWidth: 10,
  396. padding: 7,
  397. //backgroundColor: '#fff',
  398. //backgroundColor: 'green',
  399. flexDirection: 'row',
  400. justifyContent: 'flex-start',
  401. borderColor: '#e8e8e8',
  402. position: 'relative',
  403. shadowColor: '#fff',
  404. shadowOffset: { width: 0, height: 2 },
  405. shadowOpacity: 0.2,
  406. elevation: 1,
  407. paddingBottom: 10,
  408. backgroundColor: 'red',
  409. },
  410. carInfo: {
  411. justifyContent: 'center',
  412. alignSelf: 'center',
  413. color: '#c9c9c9',
  414. fontSize: 20,
  415. fontWeight: '400',
  416.  
  417. },
  418.  
  419. IconStyle: {
  420. height: 25,
  421. width: 25,
  422. resizeMode: 'contain',
  423. paddingLeft: 50,
  424. flexDirection: 'column',
  425. backgroundColor: 'transparent',
  426. paddingTop: 5,
  427. },
  428. FakeIconStyle: {
  429. height: 25,
  430. width: 25,
  431. resizeMode: 'contain',
  432. paddingLeft: 50,
  433. flexDirection: 'column',
  434. backgroundColor: 'transparent',
  435. paddingTop: 5,
  436. },
  437. inputStyle: {
  438. height: 40,
  439. width: 10,
  440. backgroundColor: 'white',
  441. borderWidth: 1,
  442. borderRadius: 5,
  443. borderColor: 'white',
  444. paddingBottom: 0,
  445. paddingLeft: 20,
  446.  
  447. },
  448. CarInputStyle: {
  449. height: 30,
  450. width: 10,
  451. backgroundColor: 'white',
  452. borderWidth: 1,
  453. borderRadius: 5,
  454. borderColor: 'white',
  455. flex: 1,
  456. },
  457. dateStyle: {
  458.  
  459. paddingTop: 7,
  460. borderWidth: 1,
  461. borderRadius: 5,
  462. borderColor: 'white',
  463.  
  464.  
  465.  
  466. },
  467. roundTrip: {
  468. backgroundColor: 'white',
  469. fontSize: 18,
  470. flex: 1,
  471. color: '#c9c9c9',
  472. //fontWeight: '400',
  473. padding: 10,
  474. paddingLeft: 0,
  475. paddingBottom: 5,
  476. borderWidth: 1,
  477. borderRadius: 5,
  478. borderColor: 'white',
  479.  
  480. flexDirection: 'row',
  481. //alignSelf: 'flex-start',
  482.  
  483. justifyContent: 'center',
  484. //alignContent: 'flex-start',
  485. //backgroundColor: 'red'
  486.  
  487. },
  488. TimeIconStyle: {
  489. height: 25,
  490. width: 25,
  491. resizeMode: 'contain',
  492. paddingLeft: 50,
  493. flexDirection: 'column',
  494. backgroundColor: 'transparent',
  495. marginTop: 10,
  496.  
  497. },
  498. rountripView: {
  499.  
  500. borderWidth: 1,
  501. borderRadius: 5,
  502. borderColor: 'white',
  503. flexDirection: 'row',
  504. flex: 1,
  505. alignSelf: 'center',
  506. justifyContent: 'flex-end',
  507. },
  508. tabsContainerStyle: {
  509. width: widthScreen / 2,
  510. justifyContent: 'center',
  511. alignSelf: 'center',
  512. },
  513. }
  514.  
  515. MyTrip.navigationOptions = {
  516. title: 'MyTrip',
  517. };
  518.  
  519. const mapStateToProps = (state) => {
  520. const {
  521. startGoogle,
  522. stopOverGoogle,
  523. endGoogle,
  524. date,
  525. costPerSeat,
  526. roundTrip,
  527. returnDate,
  528. carSeats,
  529.  
  530.  
  531. } = state.postRide;
  532.  
  533. const {
  534. carSelected,
  535. } = state.cars;
  536.  
  537. const rides = _.map(state.rides, (val, uid) => {
  538. return { ...val, uid };
  539. });
  540. return {
  541.  
  542. startGoogle,
  543. stopOverGoogle,
  544. endGoogle,
  545. date,
  546. costPerSeat,
  547. roundTrip,
  548. returnDate,
  549. carSeats,
  550. carSelected,
  551. rides
  552.  
  553.  
  554.  
  555. };
  556. };
  557.  
  558.  
  559.  
  560. export default connect(mapStateToProps, { DriverAddForm, ridesFetch })(MyTrip);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement