ListViewを修正

This commit is contained in:
harukin-expo-dev-env
2025-08-25 19:37:56 +00:00
parent 23cd316213
commit a927a73c29
2 changed files with 32 additions and 9 deletions

View File

@@ -1,18 +1,43 @@
import { FC } from "react";
import { ListViewItem } from "@/components/StationDiagram/ListViewItem";
import { View, Text, ScrollView } from "react-native";
export const ListView: FC<{ data: {
export const ListView: FC<{
data: {
trainNumber: string;
array: string;
name: string;
type: string;
time: string;
}[]; }> = ({ data }) => {
}[];
}> = ({ data }) => {
const groupedData = {};
const groupKeys = [];
data.forEach((item) => {
const hour = item.time.split(":")[0];
if (!groupedData[hour]) {
groupedData[hour] = [];
groupKeys.push(hour);
}
groupedData[hour].push(item);
});
return (
<>
{data.map((d, i) => (
<ListViewItem key={d.trainNumber + i} d={d} />
))}
</>
<ScrollView
style={{ backgroundColor: "white" }}
stickyHeaderIndices={
groupKeys.at(0) ? groupKeys.map((_, i) => i * 2) : []
}
>
{groupKeys.map((hour) => [
<View style={{ backgroundColor: "white", padding: 5, borderBottomWidth: 0.5, borderTopWidth: 0.5, borderBottomColor: "#ccc" }} key={hour}>
<Text style={{ fontSize: 15 }}>{hour}</Text>
</View>,
<View>
{groupedData[hour].map((d, i) => (
<ListViewItem key={d.trainNumber + i} d={d} />
))}
</View>,
])}
</ScrollView>
);
};

View File

@@ -100,9 +100,7 @@ export const StationDiagramView: FC<props> = ({ route }) => {
>
{currentStation[0].Station_JP}
</Text>
<ScrollView style={{ backgroundColor: "white" }}>
<ListView data={currentStationDiagram} />
</ScrollView>
{/* <Text
style={{
backgroundColor: "white",