diff --git a/components/Menu/Carousel/CarouselBox.tsx b/components/Menu/Carousel/CarouselBox.tsx index d093f8e..680addf 100644 --- a/components/Menu/Carousel/CarouselBox.tsx +++ b/components/Menu/Carousel/CarouselBox.tsx @@ -29,7 +29,8 @@ export const CarouselBox = ({ useEffect(() => { if (!carouselBadgeScrollViewRef.current) return; - const scrollToIndex = (dotButton ? 28 : 22) * listIndex - (width / 2) + (dotButton ? 28 : 22) - 5; + const dotSize = dotButton ? 28 : 24; + const scrollToIndex = dotSize * listIndex - width / 2 + dotSize - 5; carouselBadgeScrollViewRef.current.scrollTo({ x: scrollToIndex, animated: true, @@ -64,13 +65,6 @@ export const CarouselBox = ({ setDotButton(data === "true"); }); }, []); - useEffect(() => { - if (!carouselRef.current) return; - carouselRef?.current.scrollTo({ - count: listIndex - carouselRef.current.getCurrentIndex(), - animated: true, - }); - }, [listIndex]); const RenderItem = ({ item, index }) => { return ( = listUpStation.length ? 0 : listIndex} /> { + useLayoutEffect(() => { if (!!isSearchMode) { const returnData = []; Object.keys(lineList_LineWebID).forEach((d, indexBase) => { @@ -191,20 +191,16 @@ export default function Menu(props) { returnData.push([D]); }); }); - if (mapMode) { - mapsRef?.current.fitToCoordinates( - listUpStation.map((d) => ({ - latitude: parseFloat(d[0].lat), - longitude: parseFloat(d[0].lng), - })), - { edgePadding: { top: 80, bottom: 120, left: 50, right: 50 } } // Add margin values here - ); - } + if (JSON.stringify(returnData) == JSON.stringify(listUpStation)) return; setListUpStation(returnData); } else if (stationListMode == "position") { - setListUpStation(nearPositionStation.filter((d) => d != undefined)); + const returnData = nearPositionStation.filter((d) => d != undefined); + if (JSON.stringify(returnData) == JSON.stringify(listUpStation)) return; + setListUpStation(returnData); } else { - setListUpStation(favoriteStation.filter((d) => d != undefined)); + const returnData = favoriteStation.filter((d) => d != undefined); + if (JSON.stringify(returnData) == JSON.stringify(listUpStation)) return; + setListUpStation(returnData); } }, [nearPositionStation, favoriteStation, stationListMode, isSearchMode]); useEffect(() => { @@ -221,7 +217,7 @@ export default function Menu(props) { setMapMode(false); setListIndex(count); } - }, [listIndex, nearPositionStation, listUpStation, isSearchMode]); + }, [listIndex, listUpStation, isSearchMode]); useEffect(() => { if (originalStationList == undefined) return; if (listUpStation.length == 0) return; @@ -233,9 +229,18 @@ export default function Menu(props) { latitudeDelta: 0.05, longitudeDelta: 0.05, }; - if (mapMode) return; - mapsRef.current.animateToRegion(mapRegion, 1000); - }, [listIndex, nearPositionStation, listUpStation, mapsRef]); + if (mapMode) { + mapsRef?.current.fitToCoordinates( + listUpStation.map((d) => ({ + latitude: parseFloat(d[0].lat), + longitude: parseFloat(d[0].lng), + })), + { edgePadding: { top: 80, bottom: 120, left: 50, right: 50 } } // Add margin values here + ); + } else { + mapsRef.current.animateToRegion(mapRegion, 1000); + } + }, [listIndex, listUpStation]); return ( ) : ( - - JRShikoku RailScope - + <> + // + // JRShikoku RailScope + // )}