chargingStationTabView.tsx 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import { Text, ScrollView, useWindowDimensions, StyleSheet } from 'react-native';
  2. import React from 'react';
  3. import { SceneMap, TabBar, TabView } from 'react-native-tab-view';
  4. interface ChargingStationTabViewProps {
  5. titles: string[];
  6. }
  7. export const ChargingStationTabView: React.FC<ChargingStationTabViewProps> = ({ titles }) => {
  8. const layout = useWindowDimensions();
  9. //tab 1
  10. const FirstRoute = () => (
  11. <ScrollView style={{ flex: 1, marginHorizontal: '5%' }}>
  12. <Text className="text-lg" style={styles.text}>
  13. 若客戶逾時超過15分鐘,系統將視作自動放棄預約,客戶需要重新預約一次。 本公司有權保留全數費用,恕不退還。
  14. </Text>
  15. </ScrollView>
  16. );
  17. //tab 2
  18. const SecondRoute = () => (
  19. <ScrollView style={{ flex: 1, marginHorizontal: '5%' }}>
  20. <Text className="text-lg " style={styles.text}></Text>
  21. </ScrollView>
  22. );
  23. const renderScene = SceneMap({
  24. firstRoute: FirstRoute,
  25. secondRoute: SecondRoute
  26. });
  27. const [routes] = React.useState([
  28. { key: 'firstRoute', title: titles[0] },
  29. { key: 'secondRoute', title: titles[1] }
  30. ]);
  31. const [index, setIndex] = React.useState(0);
  32. const renderTabBar = (props: any) => (
  33. <TabBar
  34. {...props}
  35. renderLabel={({ route, focused }) => (
  36. <Text
  37. style={{
  38. color: focused ? '#000000' : '#CCCCCC',
  39. fontWeight: focused ? '300' : 'thin',
  40. fontSize: 17
  41. }}
  42. >
  43. {route.title}
  44. </Text>
  45. )}
  46. indicatorStyle={{
  47. backgroundColor: '#000000',
  48. height: 1
  49. }}
  50. style={{
  51. backgroundColor: 'white',
  52. elevation: 0,
  53. marginHorizontal: 15,
  54. borderBottomWidth: 0.5
  55. }}
  56. />
  57. );
  58. return (
  59. <TabView
  60. navigationState={{ index, routes }}
  61. renderScene={renderScene}
  62. onIndexChange={setIndex}
  63. initialLayout={{ width: layout.width }}
  64. renderTabBar={renderTabBar}
  65. />
  66. );
  67. };
  68. const styles = StyleSheet.create({
  69. grayColor: {
  70. color: '#888888'
  71. },
  72. topLeftTriangle: {
  73. width: 0,
  74. height: 0,
  75. borderLeftWidth: 50,
  76. borderBottomWidth: 50,
  77. borderLeftColor: '#02677D',
  78. borderBottomColor: 'transparent',
  79. position: 'absolute',
  80. top: 0,
  81. left: 0
  82. },
  83. text: {
  84. fontWeight: 300,
  85. color: '#000000'
  86. }
  87. });