Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.57 KB | None | 0 0
  1. import React, { Component } from 'react';
  2. import {
  3. View,
  4. TouchableOpacity,
  5. Platform,
  6. Animated,
  7. PanResponder
  8. } from 'react-native';
  9.  
  10. import { vw, GetDirections, Icon, Label, LocalNumber, AnimateNext, PopulateWithExactDistance } from '../../global';
  11. import Carousel from 'react-native-snap-carousel';
  12. import ApiInterface from '../../config/api-interface'
  13. import moment from 'moment'
  14.  
  15.  
  16. export default class DestinationPanel extends Component {
  17. constructor(props) {
  18. super(props);
  19. this.position = new Animated.ValueXY();
  20. }
  21. state = {
  22. isHidden: false,
  23. closestOffices: []
  24. }
  25.  
  26. calculate = async () => {
  27. const { userCoords, destination } = this.props;
  28. if (!destination.bookedOfficeId) {
  29. const closestOffices = await ApiInterface.getNearestLocations({ latitude: userCoords.latitude, longitude: userCoords.longitude, count: 2 });
  30. await PopulateWithExactDistance(userCoords, closestOffices, 'CLOSEST OFFICES DISTANCE CALCULATE');
  31. this.setState({ closestOffices });
  32. } else {
  33. this.setState({ closestOffices: [] })
  34. }
  35. }
  36.  
  37. componentWillMount() {
  38. this.PanResponder = PanResponder.create({
  39. onStartShouldSetPanResponder: (e, gestureState) => true,
  40. onPanResponderMove: (evt, gestureState) => {
  41. if (gestureState.dx < 15)
  42. this.position.setValue({ x: gestureState.dx });
  43. },
  44. onPanResponderRelease: (evt, gestureState) => {
  45. if (-(gestureState.dx + (gestureState.vx * 50)) > 90) {
  46. Animated.spring(this.position, {
  47. toValue: ({ x: -vw, y: 65 }),
  48. duration: 50
  49. }).start();
  50. setTimeout(() => {
  51. this.setState({ isHidden: true });
  52. }, 0);
  53. } else {
  54. Animated.spring(this.position, {
  55. toValue: ({ x: 0, y: 0 })
  56. }).start();
  57. }
  58. }
  59. })
  60. }
  61.  
  62. onLocationSelect = (location) => {
  63. this.setState({ selectedLocation: location });
  64. this.props.onLocationSelect(location.location);
  65. }
  66. onDestinationClick = () => {
  67. this.setState({ selectedLocation: undefined });
  68. this.props.onDestinationClick(this.props.destination);
  69. }
  70.  
  71. open = () => {
  72. this.setState({ isHidden: false });
  73. Animated.spring(this.position, {
  74. toValue: ({ x: 0, y: 0 })
  75. }).start();
  76. }
  77.  
  78. render() {
  79. const { destination } = this.props;
  80. const { closestOffices } = this.state;
  81.  
  82. if (!destination || !destination.duration) {
  83. return <View />;
  84. }
  85. const duration = destination.duration.value / 60;
  86. const durationHours = Math.floor(duration / 60);
  87. const durationMinutes = Math.floor(duration % 60);
  88.  
  89. const delay = destination.delay;
  90. const delayHours = Math.floor(delay / 60);
  91. const delayMinutes = Math.floor(delay % 60);
  92. return (
  93. <View style={{ top: -115 }}>
  94. {this.state.isHidden &&
  95. <TouchableOpacity onPress={this.open} style={{ position: 'absolute', top: Platform.OS == 'ios' ? 72 : 75, left: 7, backgroundColor: 'rgba(26, 35, 47, 0.7)', padding: 11, justifyContent: 'center', alignItems: 'center', paddingHorizontal: 14, paddingRight: 12, borderRadius: 4 }}>
  96. <Icon color="white" name="arrow" size={15} />
  97. </TouchableOpacity>
  98. }
  99. <Animated.View style={[{ position: 'absolute', zIndex: 49, paddingTop: 15, paddingLeft: 0, paddingRight: 35 }, this.position.getLayout()]} {...this.PanResponder.panHandlers}>
  100. <View style={{ backgroundColor: 'rgba(26, 35, 47, 0.8)', marginTop: 60, marginLeft: 7, paddingVertical: 15, borderRadius: 3, paddingRight: 15 }}>
  101. <View style={{ flexDirection: 'row', marginBottom: closestOffices.length && !destination.bookedOfficeId ? -10 : -15, paddingBottom: 5, borderBottomWidth: closestOffices.length && !destination.bookedOfficeId ? 0 : 0, borderBottomColor: "#f0b323" }}>
  102. <TouchableOpacity onPress={() => GetDirections({ destination, params: [{ key: "dirflg", value: "d" }] })} style={{ width: 50, height: 50, justifyContent: 'center', alignItems: 'center', paddingBottom: 5 }}>
  103. <Icon name="navigate" size={20} color="#f0b323" />
  104. </TouchableOpacity>
  105. <TouchableOpacity onPress={this.onDestinationClick}>
  106. <View style={{ maxWidth: vw - 130, paddingRight: 15 }}>
  107. <Label numberOfLines={1}>
  108. {destination.name}
  109. </Label>
  110. <Label style={{ marginTop: Platform.OS == 'ios' ? 10 : 2, lineHeight: 18 }}>
  111. {!!durationHours && <Label weight={500}>{durationHours}</Label>}
  112. {!!durationHours && 'h'}
  113. <Label weight={500}>{durationMinutes}</Label>
  114. {!!durationMinutes && 'min'}{' drive'}
  115. {(!!delayHours || !!delayMinutes) &&
  116. <Label>
  117. {' + '}
  118. {!!delayHours && <Label weight={500}>{delayHours}</Label>}
  119. {!!delayHours && 'h'}
  120. <Label weight={500}>{delayMinutes}</Label>
  121. {!!delayMinutes && 'min'}{' delay'}
  122. </Label>
  123. }
  124. </Label>
  125. </View>
  126. </TouchableOpacity>
  127. </View>
  128. <View style={{ position: 'absolute', justifyContent: 'center', paddingHorizontal: 10, paddingLeft: 80, right: 0, height: !destination.bookedOfficeId ? '130%' : '170%', paddingTop: 5, zIndex: 100 }}>
  129. <View>
  130. <Icon name="grid" color="#7c878ebb" size={8} />
  131. <Icon name="grid" style={{ marginTop: 1.2 }} color="#7c878ebb" size={8} />
  132. </View>
  133. </View>
  134. {this.state.closestOffices.map(x =>
  135. (
  136. <TouchableOpacity onPress={() => this.onLocationSelect(x)} style={{ flexDirection: 'row', alignItems: 'center', flex: 1, paddingTop: 5 }} key={x.id}>
  137. <View style={{ width: 50, height: '100%', alignItems: 'center', justifyContent: 'center' }} >
  138. <Icon name="menu-booking" size={20} color="#f0b323" />
  139. </View>
  140. <View pointerEvents="none">
  141. <Label weight={(this.state.selectedLocation || {}).id == x.id ? 500 : 100} style={{ width: 0.6 * vw }}>
  142. {x.name} ({LocalNumber(x.distance)} km)
  143. </Label>
  144. </View>
  145. </TouchableOpacity>
  146. ))}
  147. </View>
  148. </Animated.View>
  149. </View>
  150.  
  151. );
  152. }
  153. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement