お気に入り/現在地切り替え機能を仮作成
This commit is contained in:
parent
f922edb973
commit
3b98882d80
@ -2,7 +2,13 @@ import React, { useRef } from "react";
|
|||||||
import { View, TouchableOpacity, Text } from "react-native";
|
import { View, TouchableOpacity, Text } from "react-native";
|
||||||
import Ionicons from "react-native-vector-icons/Ionicons";
|
import Ionicons from "react-native-vector-icons/Ionicons";
|
||||||
|
|
||||||
export const CarouselTypeChanger = ({ locationStatus, position, mapsRef }) => {
|
export const CarouselTypeChanger = ({
|
||||||
|
locationStatus,
|
||||||
|
position,
|
||||||
|
mapsRef,
|
||||||
|
stationListMode,
|
||||||
|
setStationListMode,setSelectedCurrentStation
|
||||||
|
}) => {
|
||||||
return (
|
return (
|
||||||
<View style={{ width: "100%", height: 40, flexDirection: "row" }}>
|
<View style={{ width: "100%", height: 40, flexDirection: "row" }}>
|
||||||
<TouchableOpacity
|
<TouchableOpacity
|
||||||
@ -13,7 +19,10 @@ export const CarouselTypeChanger = ({ locationStatus, position, mapsRef }) => {
|
|||||||
alignItems: "center",
|
alignItems: "center",
|
||||||
flexDirection: "row",
|
flexDirection: "row",
|
||||||
marginHorizontal: 5,
|
marginHorizontal: 5,
|
||||||
borderRadius: 30,
|
borderTopLeftRadius: 20,
|
||||||
|
borderTopRightRadius: 20,
|
||||||
|
borderBottomLeftRadius: stationListMode == "position" ? 0 : 20,
|
||||||
|
borderBottomRightRadius: stationListMode == "position" ? 0 : 20,
|
||||||
}}
|
}}
|
||||||
disabled={!locationStatus}
|
disabled={!locationStatus}
|
||||||
onPress={() => {
|
onPress={() => {
|
||||||
@ -28,6 +37,7 @@ export const CarouselTypeChanger = ({ locationStatus, position, mapsRef }) => {
|
|||||||
},
|
},
|
||||||
1000
|
1000
|
||||||
);
|
);
|
||||||
|
setStationListMode("position");
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Ionicons
|
<Ionicons
|
||||||
@ -48,6 +58,36 @@ export const CarouselTypeChanger = ({ locationStatus, position, mapsRef }) => {
|
|||||||
現在地基準
|
現在地基準
|
||||||
</Text>
|
</Text>
|
||||||
</TouchableOpacity>
|
</TouchableOpacity>
|
||||||
|
<TouchableOpacity
|
||||||
|
style={{
|
||||||
|
padding: 5,
|
||||||
|
alignItems: "center",
|
||||||
|
flexDirection: "row",
|
||||||
|
marginHorizontal: 5,
|
||||||
|
borderRadius: 50,
|
||||||
|
}}
|
||||||
|
disabled={true}
|
||||||
|
onPress={() => {
|
||||||
|
if (!position) return;
|
||||||
|
const { latitude, longitude } = position.coords;
|
||||||
|
mapsRef.current.animateToRegion(
|
||||||
|
{
|
||||||
|
latitude,
|
||||||
|
longitude,
|
||||||
|
latitudeDelta: 0.05,
|
||||||
|
longitudeDelta: 0.05,
|
||||||
|
},
|
||||||
|
1000
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Ionicons
|
||||||
|
name="menu"
|
||||||
|
size={30}
|
||||||
|
color="#0099CC"
|
||||||
|
style={{ marginHorizontal: 5 }}
|
||||||
|
/>
|
||||||
|
</TouchableOpacity>
|
||||||
<TouchableOpacity
|
<TouchableOpacity
|
||||||
style={{
|
style={{
|
||||||
flex: 1,
|
flex: 1,
|
||||||
@ -56,10 +96,15 @@ export const CarouselTypeChanger = ({ locationStatus, position, mapsRef }) => {
|
|||||||
alignItems: "center",
|
alignItems: "center",
|
||||||
flexDirection: "row",
|
flexDirection: "row",
|
||||||
marginHorizontal: 5,
|
marginHorizontal: 5,
|
||||||
borderRadius: 30,
|
borderTopLeftRadius: 20,
|
||||||
|
borderTopRightRadius: 20,
|
||||||
|
borderBottomLeftRadius: stationListMode == "favorite" ? 0 : 20,
|
||||||
|
borderBottomRightRadius: stationListMode == "favorite" ? 0 : 20,
|
||||||
}}
|
}}
|
||||||
onPress={() => {
|
onPress={() => {
|
||||||
// お気に入りリスト更新
|
// お気に入りリスト更新
|
||||||
|
setStationListMode("favorite");
|
||||||
|
setSelectedCurrentStation(0);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Ionicons name="star" size={14} color="white" style={{ margin: 5 }} />
|
<Ionicons name="star" size={14} color="white" style={{ margin: 5 }} />
|
||||||
|
18
menu.js
18
menu.js
@ -35,6 +35,7 @@ export default function Menu({ getCurrentTrain, scrollRef }) {
|
|||||||
const { bottom, left, right, top } = useSafeAreaInsets();
|
const { bottom, left, right, top } = useSafeAreaInsets();
|
||||||
const tabBarHeight = useBottomTabBarHeight();
|
const tabBarHeight = useBottomTabBarHeight();
|
||||||
const [mapsOpacity, setMapsOpacity] = useState(false);
|
const [mapsOpacity, setMapsOpacity] = useState(false);
|
||||||
|
const [stationListMode, setStationListMode] = useState/*<"position"|"favorite">*/("position");
|
||||||
const mapsRef = useRef(null);
|
const mapsRef = useRef(null);
|
||||||
const MapHeight =
|
const MapHeight =
|
||||||
height -
|
height -
|
||||||
@ -62,7 +63,7 @@ export default function Menu({ getCurrentTrain, scrollRef }) {
|
|||||||
const makeCurrentStation = (location) => {
|
const makeCurrentStation = (location) => {
|
||||||
if (!originalStationList) return () => {};
|
if (!originalStationList) return () => {};
|
||||||
const findStationEachLine = (selectLine) => {
|
const findStationEachLine = (selectLine) => {
|
||||||
const searchArea = 0.002;
|
const searchArea = stationListMode == "position" ? 0.1 : 0.002;
|
||||||
const _calcDistance = (from, to) => {
|
const _calcDistance = (from, to) => {
|
||||||
let lat = Math.abs(from.lat - to.lat);
|
let lat = Math.abs(from.lat - to.lat);
|
||||||
let lng = Math.abs(from.lng - to.lng);
|
let lng = Math.abs(from.lng - to.lng);
|
||||||
@ -80,7 +81,9 @@ export default function Menu({ getCurrentTrain, scrollRef }) {
|
|||||||
|
|
||||||
let returnDataBase = lineList
|
let returnDataBase = lineList
|
||||||
.map((d) => findStationEachLine(originalStationList[d]))
|
.map((d) => findStationEachLine(originalStationList[d]))
|
||||||
.filter((d) => d.length > 0)
|
.filter((d) => {
|
||||||
|
console.log(d);
|
||||||
|
return d.length > 0})
|
||||||
.reduce((pre, current) => {
|
.reduce((pre, current) => {
|
||||||
pre.push(...current);
|
pre.push(...current);
|
||||||
return pre;
|
return pre;
|
||||||
@ -102,10 +105,17 @@ export default function Menu({ getCurrentTrain, scrollRef }) {
|
|||||||
|
|
||||||
const [allStationData, setAllStationData] = useState([]);
|
const [allStationData, setAllStationData] = useState([]);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
if(stationListMode == "position"){
|
||||||
|
setAllStationData(
|
||||||
|
[currentStation].filter((d) => d != undefined)
|
||||||
|
);
|
||||||
|
}else{
|
||||||
setAllStationData(
|
setAllStationData(
|
||||||
[currentStation, ...favoriteStation].filter((d) => d != undefined)
|
[currentStation, ...favoriteStation].filter((d) => d != undefined)
|
||||||
);
|
);
|
||||||
}, [currentStation, favoriteStation]);
|
|
||||||
|
}
|
||||||
|
}, [currentStation, favoriteStation,stationListMode]);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (allStationData.length == 0) {
|
if (allStationData.length == 0) {
|
||||||
setSelectedCurrentStation(0);
|
setSelectedCurrentStation(0);
|
||||||
@ -178,7 +188,7 @@ export default function Menu({ getCurrentTrain, scrollRef }) {
|
|||||||
}}
|
}}
|
||||||
onPress={() => alert("地図をタップ")}
|
onPress={() => alert("地図をタップ")}
|
||||||
/>
|
/>
|
||||||
<CarouselTypeChanger {...{ locationStatus, position, mapsRef }} />
|
<CarouselTypeChanger {...{ locationStatus, position, mapsRef,stationListMode, setStationListMode,setSelectedCurrentStation }} />
|
||||||
{allStationData.length != 0 && originalStationList.length != 0 && (
|
{allStationData.length != 0 && originalStationList.length != 0 && (
|
||||||
<>
|
<>
|
||||||
<CarouselBox
|
<CarouselBox
|
||||||
|
Loading…
Reference in New Issue
Block a user