reservationLocationPage.tsx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. import Svg, { Path, Rect } from 'react-native-svg';
  2. import * as React from 'react';
  3. import {
  4. View,
  5. Text,
  6. useWindowDimensions,
  7. StyleSheet,
  8. Image,
  9. ImageSourcePropType,
  10. Pressable,
  11. ViewStyle
  12. } from 'react-native';
  13. import { TabView, SceneMap, TabBar } from 'react-native-tab-view';
  14. import { FlashList } from '@shopify/flash-list';
  15. import { SafeAreaView } from 'react-native-safe-area-context';
  16. import NormalInput from '../global/normal_input';
  17. export interface TabItem {
  18. imgURL: ImageSourcePropType;
  19. date: string;
  20. time: string;
  21. chargeStationName: string;
  22. chargeStationAddress: string;
  23. distance: string;
  24. }
  25. interface TabViewComponentProps {
  26. titles: string[];
  27. tabItems: TabItem[];
  28. }
  29. const CheckMarkLogoSvg = () => (
  30. <Svg width="20" height="20" viewBox="0 0 20 20" fill="none">
  31. <Rect width="20" height="20" rx="10" fill="#02677D" />
  32. <Path
  33. d="M7.95837 15L3.20837 10.25L4.39587 9.06251L7.95837 12.625L15.6042 4.97917L16.7917 6.16667L7.95837 15Z"
  34. fill="white"
  35. />
  36. </Svg>
  37. );
  38. const dummyTabItems: TabItem[] = [
  39. {
  40. imgURL: require('../../assets/dummyStationPicture.png'),
  41. date: '今天',
  42. time: '16:30',
  43. chargeStationName: '上環街市充電站',
  44. chargeStationAddress: '香港上環皇后大道中345號',
  45. distance: '400米'
  46. },
  47. {
  48. imgURL: require('../../assets/dummyStationPicture2.png'),
  49. date: '3月15',
  50. time: '17:45',
  51. chargeStationName: '中環IFC充電站',
  52. chargeStationAddress: '香港中環皇后大道中999號',
  53. distance: '680米'
  54. },
  55. {
  56. imgURL: require('../../assets/dummyStationPicture2.png'),
  57. date: '4月20',
  58. time: '12:30',
  59. chargeStationName: '中環IFC充電站',
  60. chargeStationAddress: '香港中環皇后大道中999號',
  61. distance: '680米'
  62. },
  63. {
  64. imgURL: require('../../assets/dummyStationPicture.png'),
  65. date: '今天',
  66. time: '16:30',
  67. chargeStationName: '上環街市充電站',
  68. chargeStationAddress: '香港上環皇后大道中345號',
  69. distance: '400米'
  70. },
  71. {
  72. imgURL: require('../../assets/dummyStationPicture.png'),
  73. date: '今天',
  74. time: '16:30',
  75. chargeStationName: '上環街市充電站',
  76. chargeStationAddress: '香港上環皇后大道中345號',
  77. distance: '400米'
  78. }
  79. ];
  80. const LocationTabComponent: React.FC<TabViewComponentProps> = ({
  81. titles,
  82. tabItems
  83. }) => {
  84. const layout = useWindowDimensions();
  85. //tab 1
  86. const FirstRoute = () => (
  87. <View style={{ flex: 1, backgroundColor: 'white' }}>
  88. <FlashList
  89. data={tabItems}
  90. renderItem={({ item }) => {
  91. return (
  92. <View style={styles.container}>
  93. <Image style={styles.image} source={item.imgURL} />
  94. <View style={styles.textContainer}>
  95. <Text
  96. style={{
  97. fontWeight: 400,
  98. fontSize: 18,
  99. color: '#222222'
  100. }}
  101. >
  102. {item.chargeStationName}
  103. </Text>
  104. <Text
  105. style={{
  106. fontWeight: 400,
  107. fontSize: 14,
  108. color: '#888888'
  109. }}
  110. >
  111. {item.chargeStationAddress}
  112. </Text>
  113. <View className=" flex-row space-x-2 items-center">
  114. <CheckMarkLogoSvg />
  115. <Text
  116. style={{
  117. fontWeight: 400,
  118. fontSize: 14,
  119. color: '#222222'
  120. }}
  121. >
  122. Walk-in
  123. </Text>
  124. </View>
  125. </View>
  126. <Text
  127. style={{
  128. fontWeight: 400,
  129. fontSize: 16,
  130. color: '#888888',
  131. marginTop: 20,
  132. marginLeft: 10
  133. }}
  134. >
  135. {item.distance}
  136. </Text>
  137. </View>
  138. );
  139. }}
  140. estimatedItemSize={10}
  141. />
  142. </View>
  143. );
  144. //tab 2
  145. const SecondRoute = () => (
  146. <View style={{ flex: 1, backgroundColor: 'white' }}>
  147. <FlashList
  148. data={tabItems}
  149. renderItem={({ item }) => {
  150. return (
  151. <View style={styles.container}>
  152. <Image style={styles.image} source={item.imgURL} />
  153. <View style={styles.textContainer}>
  154. <Text
  155. style={{
  156. fontWeight: 400,
  157. fontSize: 18,
  158. color: '#222222'
  159. }}
  160. >
  161. {item.chargeStationName}
  162. </Text>
  163. <Text
  164. style={{
  165. fontWeight: 400,
  166. fontSize: 14,
  167. color: '#888888'
  168. }}
  169. >
  170. {item.chargeStationAddress}
  171. </Text>
  172. <View className=" flex-row space-x-2 items-center">
  173. <CheckMarkLogoSvg />
  174. <Text
  175. style={{
  176. fontWeight: 400,
  177. fontSize: 14,
  178. color: '#222222'
  179. }}
  180. >
  181. Walk-in
  182. </Text>
  183. </View>
  184. </View>
  185. <Text
  186. style={{
  187. fontWeight: 400,
  188. fontSize: 16,
  189. color: '#888888',
  190. marginTop: 20,
  191. marginLeft: 10
  192. }}
  193. >
  194. {item.distance}
  195. </Text>
  196. </View>
  197. );
  198. }}
  199. estimatedItemSize={10}
  200. />
  201. </View>
  202. );
  203. const renderScene = SceneMap({
  204. firstRoute: FirstRoute,
  205. secondRoute: SecondRoute
  206. });
  207. const [routes] = React.useState([
  208. { key: 'firstRoute', title: titles[0] },
  209. { key: 'secondRoute', title: titles[1] }
  210. ]);
  211. const [index, setIndex] = React.useState(0);
  212. const renderTabBar = (props: any) => (
  213. <TabBar
  214. {...props}
  215. renderLabel={({ route, focused }) => (
  216. <Text
  217. style={{
  218. color: focused ? '#025c72' : '#888888',
  219. fontWeight: focused ? '900' : 'thin',
  220. fontSize: 20
  221. }}
  222. >
  223. {route.title}
  224. </Text>
  225. )}
  226. indicatorStyle={{
  227. backgroundColor: '#025c72'
  228. }}
  229. style={{
  230. backgroundColor: 'white',
  231. borderColor: '#DBE4E8',
  232. elevation: 0,
  233. marginHorizontal: 15,
  234. borderBottomWidth: 0.5
  235. }}
  236. />
  237. );
  238. return (
  239. <TabView
  240. navigationState={{ index, routes }}
  241. renderScene={renderScene}
  242. onIndexChange={setIndex}
  243. initialLayout={{ width: layout.width }}
  244. renderTabBar={renderTabBar}
  245. />
  246. );
  247. };
  248. const styles = StyleSheet.create({
  249. container: { flexDirection: 'row' },
  250. image: { width: 100, height: 100, margin: 15, borderRadius: 10 },
  251. textContainer: { flexDirection: 'column', gap: 8, marginTop: 22 }
  252. });
  253. // ***************************************************************
  254. const ReservationLocationPage = () => {
  255. const CrossLogoSvg = () => (
  256. <Svg width="24" height="24" viewBox="0 0 24 24" fill="none">
  257. <Path
  258. d="M2.33333 23.3333L0 21L9.33333 11.6667L0 2.33333L2.33333 0L11.6667 9.33333L21 0L23.3333 2.33333L14 11.6667L23.3333 21L21 23.3333L11.6667 14L2.33333 23.3333Z"
  259. fill="#222222"
  260. />
  261. </Svg>
  262. );
  263. return (
  264. <SafeAreaView className="flex-1 bg-white">
  265. <View className="flex-1 mx-[5%]">
  266. <View className="basis-1/3 flex-column">
  267. <View className="flex-2 justify-center ">
  268. <View className="pt-6 ">
  269. <Pressable onPress={() => console.log('abc')}>
  270. <CrossLogoSvg />
  271. </Pressable>
  272. </View>
  273. </View>
  274. <View className="flex-1 justify-center ">
  275. <Text className="text-[50px] font-normal">
  276. 預約地點
  277. </Text>
  278. </View>
  279. <View className="flex-1 justify-center mb-6 ">
  280. <NormalInput
  281. placeholder="搜尋所有充電站或地區.."
  282. onChangeText={() => console.log('abc')}
  283. extendedStyle={{ padding: 24 }}
  284. />
  285. </View>
  286. </View>
  287. <View className="basis-2/3 ">
  288. <LocationTabComponent
  289. titles={['附近的充電站', '所有的充電站']}
  290. tabItems={dummyTabItems}
  291. />
  292. </View>
  293. </View>
  294. </SafeAreaView>
  295. );
  296. };
  297. export default ReservationLocationPage;