chargingStationTabView.tsx 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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}>
  21. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do Lorem ipsum dolor sit amet, consectetur
  22. adipiscing elit, sed do Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
  23. </Text>
  24. </ScrollView>
  25. );
  26. const renderScene = SceneMap({
  27. firstRoute: FirstRoute,
  28. secondRoute: SecondRoute
  29. });
  30. const [routes] = React.useState([
  31. { key: 'firstRoute', title: titles[0] },
  32. { key: 'secondRoute', title: titles[1] }
  33. ]);
  34. const [index, setIndex] = React.useState(0);
  35. const renderTabBar = (props: any) => (
  36. <TabBar
  37. {...props}
  38. renderLabel={({ route, focused }) => (
  39. <Text
  40. style={{
  41. color: focused ? '#000000' : '#CCCCCC',
  42. fontWeight: focused ? '300' : 'thin',
  43. fontSize: 17
  44. }}
  45. >
  46. {route.title}
  47. </Text>
  48. )}
  49. indicatorStyle={{
  50. backgroundColor: '#000000',
  51. height: 1
  52. }}
  53. style={{
  54. backgroundColor: 'white',
  55. elevation: 0,
  56. marginHorizontal: 15,
  57. borderBottomWidth: 0.5
  58. }}
  59. />
  60. );
  61. return (
  62. <TabView
  63. navigationState={{ index, routes }}
  64. renderScene={renderScene}
  65. onIndexChange={setIndex}
  66. initialLayout={{ width: layout.width }}
  67. renderTabBar={renderTabBar}
  68. />
  69. );
  70. };
  71. const styles = StyleSheet.create({
  72. grayColor: {
  73. color: '#888888'
  74. },
  75. topLeftTriangle: {
  76. width: 0,
  77. height: 0,
  78. borderLeftWidth: 50,
  79. borderBottomWidth: 50,
  80. borderLeftColor: '#02677D',
  81. borderBottomColor: 'transparent',
  82. position: 'absolute',
  83. top: 0,
  84. left: 0
  85. },
  86. text: {
  87. fontWeight: 300,
  88. color: '#000000'
  89. }
  90. });