chargingStationTabView.tsx 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. indicatorStyle={{
  36. backgroundColor: '#000000',
  37. height: 1
  38. }}
  39. style={{
  40. backgroundColor: 'white',
  41. elevation: 0,
  42. marginHorizontal: 15,
  43. borderBottomWidth: 0.5
  44. }}
  45. />
  46. );
  47. return (
  48. <TabView
  49. navigationState={{ index, routes }}
  50. renderScene={renderScene}
  51. onIndexChange={setIndex}
  52. initialLayout={{ width: layout.width }}
  53. renderTabBar={renderTabBar}
  54. commonOptions={{
  55. label: ({ route, focused }) => (
  56. <Text
  57. style={{
  58. color: focused ? '#000000' : '#CCCCCC',
  59. fontWeight: focused ? '300' : 'thin',
  60. fontSize: 17
  61. }}
  62. >
  63. {route.title}
  64. </Text>
  65. ),
  66. }}
  67. />
  68. );
  69. };
  70. const styles = StyleSheet.create({
  71. grayColor: {
  72. color: '#888888'
  73. },
  74. topLeftTriangle: {
  75. width: 0,
  76. height: 0,
  77. borderLeftWidth: 50,
  78. borderBottomWidth: 50,
  79. borderLeftColor: '#02677D',
  80. borderBottomColor: 'transparent',
  81. position: 'absolute',
  82. top: 0,
  83. left: 0
  84. },
  85. text: {
  86. fontWeight: 300,
  87. color: '#000000'
  88. }
  89. });