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