検索モードの追加

This commit is contained in:
harukin-expo-dev-env 2025-07-15 02:56:29 +00:00
parent 3dc5f52333
commit e6adf775bb
5 changed files with 91 additions and 40 deletions

View File

@ -104,7 +104,7 @@ export const CarouselBox = ({
}} }}
> >
<Text style={{ color: "#0099CC", fontSize: 20 }}> <Text style={{ color: "#0099CC", fontSize: 20 }}>
{!!isSearchMode ? "路線検索モードです。上に並んでいる路線を選んでみましょう!" :stationListMode == "position" {!!isSearchMode ? "路線検索モードです。入力欄に駅名やナンバリングを入力したり、上に並んでいる路線を選んでみましょう!" :stationListMode == "position"
? "現在地の近くに駅がありません。" ? "現在地の近くに駅がありません。"
: "お気に入りリストがありません。お気に入りの駅を追加しよう!"} : "お気に入りリストがありません。お気に入りの駅を追加しよう!"}
</Text> </Text>

View File

@ -25,6 +25,10 @@ export const CarouselTypeChanger = ({
setMapMode, setMapMode,
isSearchMode, isSearchMode,
setisSearchMode, setisSearchMode,
listUpStation,
setListUpStation,
input,
setInput
}) => { }) => {
const tabBarHeight = useBottomTabBarHeight(); const tabBarHeight = useBottomTabBarHeight();
const { height, width } = useWindowDimensions(); const { height, width } = useWindowDimensions();
@ -62,6 +66,8 @@ export const CarouselTypeChanger = ({
<SearchUnitBox <SearchUnitBox
isSearchMode={isSearchMode} isSearchMode={isSearchMode}
setisSearchMode={setisSearchMode} setisSearchMode={setisSearchMode}
input={input}
setInput={setInput}
/> />
<TouchableOpacity <TouchableOpacity
style={{ style={{

View File

@ -12,9 +12,13 @@ import Ionicons from "react-native-vector-icons/Ionicons";
import { useWindowDimensions } from "react-native"; import { useWindowDimensions } from "react-native";
import lineColorList from "@/assets/originData/lineColorList"; import lineColorList from "@/assets/originData/lineColorList";
import { lineList_LineWebID, stationIDPair } from "@/lib/getStationList"; import { lineList_LineWebID, stationIDPair } from "@/lib/getStationList";
export const SearchUnitBox = ({ isSearchMode, setisSearchMode, }) => { export const SearchUnitBox = ({
isSearchMode,
setisSearchMode,
input,
setInput,
}) => {
const { height, width } = useWindowDimensions(); const { height, width } = useWindowDimensions();
const [input, setInput] = React.useState("");
return ( return (
<> <>
<TouchableOpacity <TouchableOpacity
@ -40,25 +44,32 @@ export const SearchUnitBox = ({ isSearchMode, setisSearchMode, }) => {
> >
{!isSearchMode && <Ionicons name="search" size={30} color="white" />} {!isSearchMode && <Ionicons name="search" size={30} color="white" />}
{!!isSearchMode && ( {!!isSearchMode && (
<View style={{ backgroundColor: "#0099CC",flexDirection:"column",display:"flex",flex:1 }}> <View
<View style={{
style={{ backgroundColor: "#0099CC",
backgroundColor: "white", flexDirection: "column",
borderRadius: 25, display: "flex",
height: 30, flex: 1,
paddingRight: 10, }}
paddingLeft: 10, >
flex: 1, <View
}} style={{
> backgroundColor: "white",
<TextInput borderRadius: 25,
placeholder="駅名を入力してフィルタリングします。" height: 30,
onEndEditing={() => {}} paddingRight: 10,
onChange={(ret) => setInput(ret.nativeEvent.text)} paddingLeft: 10,
value={input} flex: 1,
style={{ flex: 1 }} }}
/> >
</View> <TextInput
placeholder="駅名や駅ナンバリングを入力してフィルタリングします。"
onEndEditing={() => {}}
onChange={(ret) => setInput(ret.nativeEvent.text)}
value={input}
style={{ flex: 1 }}
/>
</View>
<View style={{ flexDirection: "row", alignItems: "center" }}> <View style={{ flexDirection: "row", alignItems: "center" }}>
<TouchableOpacity <TouchableOpacity
onPress={() => { onPress={() => {

50
menu.js
View File

@ -42,7 +42,7 @@ export default function Menu(props) {
const { scrollRef, mapHeight, MapFullHeight, mapMode, setMapMode } = props; const { scrollRef, mapHeight, MapFullHeight, mapMode, setMapMode } = props;
const { navigate, addListener, isFocused } = useNavigation(); const { navigate, addListener, isFocused } = useNavigation();
const { favoriteStation } = useFavoriteStation(); const { favoriteStation } = useFavoriteStation();
const { originalStationList } = useStationList(); const { originalStationList,getStationDataFromNameBase } = useStationList();
const { height, width } = useWindowDimensions(); const { height, width } = useWindowDimensions();
const { bottom, left, right, top } = useSafeAreaInsets(); const { bottom, left, right, top } = useSafeAreaInsets();
const tabBarHeight = useBottomTabBarHeight(); const tabBarHeight = useBottomTabBarHeight();
@ -172,25 +172,31 @@ export default function Menu(props) {
const [listUpStation, setListUpStation] = useState([]); const [listUpStation, setListUpStation] = useState([]);
const [isSearchMode, setisSearchMode] = useState(false); const [isSearchMode, setisSearchMode] = useState(false);
const [input, setInput] = React.useState("");
useLayoutEffect(() => { useLayoutEffect(() => {
if (!!isSearchMode) { if (!!isSearchMode) {
const returnData = []; const returnData = [];
Object.keys(lineList_LineWebID).forEach((d, indexBase) => { if (!input || input == "") {
originalStationList[d].forEach((D, index) => { Object.keys(lineList_LineWebID).forEach((d, indexBase) => {
if ( originalStationList[d].forEach((D, index) => {
isSearchMode && if (
isSearchMode != stationIDPair[lineList_LineWebID[d]] isSearchMode &&
) isSearchMode != stationIDPair[lineList_LineWebID[d]]
return; )
const latlng = [D.lat, D.lng]; return;
if (latlng.length == 0) return null; const latlng = [D.lat, D.lng];
if (D.StationNumber == undefined) { if (latlng.length == 0) return null;
return null; if (D.StationNumber == undefined) {
} return null;
returnData.push([D]); }
returnData.push([D]);
});
}); });
}); if (JSON.stringify(returnData) == JSON.stringify(listUpStation)) return;
if (JSON.stringify(returnData) == JSON.stringify(listUpStation)) return; }else{
const hoge = getStationDataFromNameBase(input);
hoge.forEach(d=>returnData.push([d]));
}
setListUpStation(returnData); setListUpStation(returnData);
} else if (stationListMode == "position") { } else if (stationListMode == "position") {
const returnData = nearPositionStation.filter((d) => d != undefined); const returnData = nearPositionStation.filter((d) => d != undefined);
@ -290,7 +296,7 @@ export default function Menu(props) {
> >
<MapView <MapView
ref={mapsRef} ref={mapsRef}
style={{ width: "100%", height:( mapMode ? MapFullHeight : mapHeight) }} style={{ width: "100%", height: mapMode ? MapFullHeight : mapHeight }}
showsUserLocation={true} showsUserLocation={true}
loadingEnabled={true} loadingEnabled={true}
showsMyLocationButton={false} showsMyLocationButton={false}
@ -371,6 +377,10 @@ export default function Menu(props) {
setMapMode, setMapMode,
isSearchMode, isSearchMode,
setisSearchMode, setisSearchMode,
listUpStation,
setListUpStation,
input,
setInput,
}} }}
/> />
)} )}
@ -386,7 +396,7 @@ export default function Menu(props) {
listIndex, listIndex,
navigate, navigate,
stationListMode, stationListMode,
isSearchMode isSearchMode,
}} }}
/> />
{listUpStation[listIndex] && ( {listUpStation[listIndex] && (
@ -416,6 +426,10 @@ export default function Menu(props) {
setMapMode, setMapMode,
isSearchMode, isSearchMode,
setisSearchMode, setisSearchMode,
listUpStation,
setListUpStation,
input,
setInput,
}} }}
/> />
)} )}

View File

@ -16,6 +16,7 @@ type initialStateType = {
setOriginalStationList: React.Dispatch<React.SetStateAction<any[]>>; setOriginalStationList: React.Dispatch<React.SetStateAction<any[]>>;
getStationDataFromName: (id: string) => any[]; getStationDataFromName: (id: string) => any[];
getStationDataFromId: (id: string) => any[]; getStationDataFromId: (id: string) => any[];
getStationDataFromNameBase: (name: string) => any[];
stationList: any[]; stationList: any[];
getInjectJavascriptAddress: (StationNumber: string) => string; getInjectJavascriptAddress: (StationNumber: string) => string;
}; };
@ -24,6 +25,7 @@ const initialState = {
setOriginalStationList: () => {}, setOriginalStationList: () => {},
getStationDataFromName: () => [], getStationDataFromName: () => [],
getStationDataFromId: () => [], getStationDataFromId: () => [],
getStationDataFromNameBase: () => [],
stationList: [], stationList: [],
getInjectJavascriptAddress: (StationNumber: string) => "", getInjectJavascriptAddress: (StationNumber: string) => "",
}; };
@ -66,6 +68,23 @@ export const StationListProvider: FC<Props> = ({ children }) => {
}); });
return returnArray; return returnArray;
}; };
const getStationDataFromNameBase: (name: string) => any[] = (name) => {
const returnArray = [];
Object.keys(originalStationList).forEach((key) => {
originalStationList[key].forEach((station) => {
if (!station.StationNumber) return;
if (typeof station.StationNumber === "string" && station.StationNumber.includes(name)) {
if (!!station.jslodApi) returnArray.push(station);
}
else if (typeof station.Station_JP === "string" && station.Station_JP.includes(name)) {
if (!!station.jslodApi) returnArray.push(station);
}
});
});
return returnArray;
};
const [stationList, setStationList] = useState<any[][]>([[]]); const [stationList, setStationList] = useState<any[][]>([[]]);
useEffect(() => { useEffect(() => {
if (originalStationList.length === 0) return; if (originalStationList.length === 0) return;
@ -113,6 +132,7 @@ export const StationListProvider: FC<Props> = ({ children }) => {
setOriginalStationList, setOriginalStationList,
getStationDataFromName, getStationDataFromName,
getStationDataFromId, getStationDataFromId,
getStationDataFromNameBase,
stationList, stationList,
getInjectJavascriptAddress, getInjectJavascriptAddress,
}} }}