chargingStationTabView.tsx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. import {
  2. Text,
  3. ScrollView,
  4. useWindowDimensions,
  5. StyleSheet
  6. } from 'react-native';
  7. import React from 'react';
  8. import { SceneMap, TabBar, TabView } from 'react-native-tab-view';
  9. interface ChargingStationTabViewProps {
  10. titles: string[];
  11. }
  12. export const ChargingStationTabView: React.FC<ChargingStationTabViewProps> = ({
  13. titles
  14. }) => {
  15. const layout = useWindowDimensions();
  16. //tab 1
  17. const FirstRoute = () => (
  18. <ScrollView style={{ flex: 1, marginHorizontal: '5%' }}>
  19. <Text className="text-lg" style={styles.text}>
  20. 這是一段有關充電站的說明
  21. </Text>
  22. </ScrollView>
  23. );
  24. //tab 2
  25. const SecondRoute = () => (
  26. <ScrollView style={{ flex: 1, marginHorizontal: '5%' }}>
  27. <Text className="text-lg " style={styles.text}>
  28. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
  29. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
  30. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
  31. </Text>
  32. </ScrollView>
  33. );
  34. const renderScene = SceneMap({
  35. firstRoute: FirstRoute,
  36. secondRoute: SecondRoute
  37. });
  38. const [routes] = React.useState([
  39. { key: 'firstRoute', title: titles[0] },
  40. { key: 'secondRoute', title: titles[1] }
  41. ]);
  42. const [index, setIndex] = React.useState(0);
  43. const renderTabBar = (props: any) => (
  44. <TabBar
  45. {...props}
  46. renderLabel={({ route, focused }) => (
  47. <Text
  48. style={{
  49. color: focused ? '#000000' : '#CCCCCC',
  50. fontWeight: focused ? '300' : 'thin',
  51. fontSize: 17
  52. }}
  53. >
  54. {route.title}
  55. </Text>
  56. )}
  57. indicatorStyle={{
  58. backgroundColor: '#000000',
  59. height: 1
  60. }}
  61. style={{
  62. backgroundColor: 'white',
  63. elevation: 0,
  64. marginHorizontal: 15,
  65. borderBottomWidth: 0.5
  66. }}
  67. />
  68. );
  69. return (
  70. <TabView
  71. navigationState={{ index, routes }}
  72. renderScene={renderScene}
  73. onIndexChange={setIndex}
  74. initialLayout={{ width: layout.width }}
  75. renderTabBar={renderTabBar}
  76. />
  77. );
  78. };
  79. const styles = StyleSheet.create({
  80. grayColor: {
  81. color: '#888888'
  82. },
  83. topLeftTriangle: {
  84. width: 0,
  85. height: 0,
  86. borderLeftWidth: 50,
  87. borderBottomWidth: 50,
  88. borderLeftColor: '#02677D',
  89. borderBottomColor: 'transparent',
  90. position: 'absolute',
  91. top: 0,
  92. left: 0
  93. },
  94. text: {
  95. fontWeight: 300,
  96. color: '#000000'
  97. }
  98. });