locationAndFavoriteの位置変更
This commit is contained in:
parent
23927a3f16
commit
2e535c2685
60
menu.js
60
menu.js
@ -47,7 +47,7 @@ export default function Menu(props) {
|
|||||||
const StationBoardAcSR = useRef(null);
|
const StationBoardAcSR = useRef(null);
|
||||||
const navigation = useNavigation();
|
const navigation = useNavigation();
|
||||||
|
|
||||||
//位置情報
|
//ここから位置情報
|
||||||
const [location, setLocation] = useState(null);
|
const [location, setLocation] = useState(null);
|
||||||
const [locationStatus, setLocationStatus] = useState(null);
|
const [locationStatus, setLocationStatus] = useState(null);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -70,29 +70,16 @@ export default function Menu(props) {
|
|||||||
if (locationStatus !== "granted") return () => {};
|
if (locationStatus !== "granted") return () => {};
|
||||||
getCurrentPosition();
|
getCurrentPosition();
|
||||||
}, 5000);
|
}, 5000);
|
||||||
|
//ここまで位置情報
|
||||||
|
|
||||||
|
//基礎駅情報取得
|
||||||
const [originalStationList, setOriginalStationList] = useState();
|
const [originalStationList, setOriginalStationList] = useState();
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
getStationList().then(setOriginalStationList);
|
getStationList().then(setOriginalStationList);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const [locationAndFavorite, setLocationAndFavorite] = useState([]); //Favoriteから現在地を排除したバージョン
|
//ここから現在地付近の駅情報整理
|
||||||
useEffect(() => {
|
const [currentAreaStation, setCurrentAreaStation] = useState([]);
|
||||||
if (!favoriteStation) return () => {};
|
|
||||||
const data = favoriteStation.filter((d) =>
|
|
||||||
JSON.stringify(d) === JSON.stringify(currentStation) ? false : true
|
|
||||||
);
|
|
||||||
setLocationAndFavorite(data);
|
|
||||||
}, [currentStation, favoriteStation]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (!(selectedCurrentStation < favoriteStation.length)) {
|
|
||||||
setSelectedCurrentStation(favoriteStation.length - 1);
|
|
||||||
carouselRef.current.snapToItem(favoriteStation.length - 1);
|
|
||||||
}
|
|
||||||
}, [favoriteStation]);
|
|
||||||
|
|
||||||
const [currentStation, setCurrentStation] = useState([]);
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!location) return () => {};
|
if (!location) return () => {};
|
||||||
if (!originalStationList) return () => {};
|
if (!originalStationList) return () => {};
|
||||||
@ -122,14 +109,31 @@ export default function Menu(props) {
|
|||||||
}, []);
|
}, []);
|
||||||
LayoutAnimation.easeInEaseOut();
|
LayoutAnimation.easeInEaseOut();
|
||||||
if (returnDataBase.length) {
|
if (returnDataBase.length) {
|
||||||
if (currentStation.toString() != returnDataBase.toString()) {
|
if (currentAreaStation.toString() != returnDataBase.toString()) {
|
||||||
setCurrentStation(returnDataBase);
|
setCurrentAreaStation(returnDataBase);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
setCurrentStation([]);
|
setCurrentAreaStation([]);
|
||||||
}
|
}
|
||||||
}, [location, originalStationList]);
|
}, [location, originalStationList]);
|
||||||
|
|
||||||
|
//Favoriteから現在地を排除し現在地を最初に持ってくるバージョン
|
||||||
|
const [locationAndFavorite, setLocationAndFavorite] = useState([]);
|
||||||
|
useEffect(() => {
|
||||||
|
if (!favoriteStation) return () => {};
|
||||||
|
const data = favoriteStation.filter((d) =>
|
||||||
|
JSON.stringify(d) === JSON.stringify(currentAreaStation) ? false : true
|
||||||
|
);
|
||||||
|
setLocationAndFavorite([...currentAreaStation, ...data]);
|
||||||
|
}, [currentAreaStation, favoriteStation]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!(selectedCurrentStation < favoriteStation.length)) {
|
||||||
|
setSelectedCurrentStation(favoriteStation.length - 1);
|
||||||
|
carouselRef.current.snapToItem(favoriteStation.length - 1);
|
||||||
|
}
|
||||||
|
}, [favoriteStation]);
|
||||||
|
|
||||||
const [count, setCount] = useState(0);
|
const [count, setCount] = useState(0);
|
||||||
const [delayData, setDelayData] = useState(undefined);
|
const [delayData, setDelayData] = useState(undefined);
|
||||||
const [getTime, setGetTime] = useState(new Date());
|
const [getTime, setGetTime] = useState(new Date());
|
||||||
@ -168,9 +172,7 @@ export default function Menu(props) {
|
|||||||
<Carousel
|
<Carousel
|
||||||
ref={carouselRef}
|
ref={carouselRef}
|
||||||
layout={"default"}
|
layout={"default"}
|
||||||
data={
|
data={originalStationList && locationAndFavorite}
|
||||||
originalStationList && [...currentStation, ...locationAndFavorite]
|
|
||||||
}
|
|
||||||
sliderWidth={wp("100%")}
|
sliderWidth={wp("100%")}
|
||||||
itemWidth={wp("80%")}
|
itemWidth={wp("80%")}
|
||||||
enableMomentum
|
enableMomentum
|
||||||
@ -194,14 +196,11 @@ export default function Menu(props) {
|
|||||||
);
|
);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
{[...currentStation, ...locationAndFavorite].length != 0 &&
|
{locationAndFavorite.length != 0 && originalStationList && (
|
||||||
originalStationList && (
|
|
||||||
<LED_vision
|
<LED_vision
|
||||||
station={
|
station={
|
||||||
originalStationList &&
|
originalStationList &&
|
||||||
[...currentStation, ...locationAndFavorite][
|
locationAndFavorite[selectedCurrentStation][0]
|
||||||
selectedCurrentStation
|
|
||||||
][0]
|
|
||||||
}
|
}
|
||||||
navigate={navigate}
|
navigate={navigate}
|
||||||
/>
|
/>
|
||||||
@ -217,8 +216,7 @@ export default function Menu(props) {
|
|||||||
<StationDeteilView
|
<StationDeteilView
|
||||||
StationBoardAcSR={StationBoardAcSR}
|
StationBoardAcSR={StationBoardAcSR}
|
||||||
currentStation={
|
currentStation={
|
||||||
originalStationList &&
|
originalStationList && locationAndFavorite[selectedCurrentStation]
|
||||||
[...currentStation, ...locationAndFavorite][selectedCurrentStation]
|
|
||||||
}
|
}
|
||||||
originalStationList={originalStationList}
|
originalStationList={originalStationList}
|
||||||
favoriteStation={favoriteStation}
|
favoriteStation={favoriteStation}
|
||||||
|
Loading…
Reference in New Issue
Block a user