From fa758c144f5558de7ec18c48fb76f84a79e296f0 Mon Sep 17 00:00:00 2001 From: harukin-expo-dev-env Date: Mon, 14 Apr 2025 18:52:21 +0000 Subject: [PATCH] =?UTF-8?q?=E3=82=B9=E3=82=AF=E3=83=AD=E3=83=BC=E3=83=AB?= =?UTF-8?q?=E3=81=AE=E6=8C=99=E5=8B=95=E3=81=8C=E3=81=8A=E3=81=8B=E3=81=97?= =?UTF-8?q?=E3=81=8B=E3=81=A3=E3=81=9F=E3=83=90=E3=82=B0=E3=82=92=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MenuPage.js | 26 +++--- .../Menu/Carousel/CarouselTypeChanger.tsx | 14 +-- menu.js | 88 ++++++++++++++++--- 3 files changed, 91 insertions(+), 37 deletions(-) diff --git a/MenuPage.js b/MenuPage.js index b3a20e7..e9f16b4 100644 --- a/MenuPage.js +++ b/MenuPage.js @@ -1,4 +1,4 @@ -import React, { useEffect, useRef } from "react"; +import React, { useEffect, useRef,useState } from "react"; import { createStackNavigator } from "@react-navigation/stack"; import { useWindowDimensions, Platform } from "react-native"; import Constants from "expo-constants"; @@ -50,16 +50,20 @@ export function MenuPage() { }, []); const scrollRef = useRef(null); - const MapHeight = - height - - tabBarHeight + - (Platform.OS == "android" ? Constants.statusBarHeight : 0) - - 100 - - ((((width / 100) * 80) / 20) * 9 + 10 + 30); + const [mapHeight,setMapHeight] = useState(0); + useEffect(()=>{ + const MapHeight = + height - + tabBarHeight + + (Platform.OS == "android" ? Constants.statusBarHeight : 0) - + 100 - + ((((width / 100) * 80) / 20) * 9 + 10 + 30); + setMapHeight(MapHeight); + }, [height, tabBarHeight, width]); useEffect(() => { const unsubscribe = addListener("tabPress", (e) => { scrollRef.current.scrollTo({ - y: MapHeight - 80, + y: mapHeight - 80, animated: true, }); AS.getItem("favoriteStation") @@ -73,7 +77,7 @@ export function MenuPage() { }); return unsubscribe; - }, [navigation]); + }, [navigation, mapHeight]); return ( ( - - )} + children={() => } /> { if (!position) return; returnToDefaultMode(); - const { latitude, longitude } = position.coords; - mapsRef.current.animateToRegion( - { - latitude, - longitude, - latitudeDelta: 0.05, - longitudeDelta: 0.05, - }, - 1000 - ); setStationListMode("position"); }} > @@ -83,7 +73,7 @@ export const CarouselTypeChanger = ({ marginHorizontal: 5, borderRadius: 50, }} - onPress={() => returnToDefaultMode()} + onPressIn={() => returnToDefaultMode()} > { + scrollRef.current.scrollTo({ + y: mapHeight > 80 ?mapHeight - 80 :0, + animated: bool, + }); + }; + const goToMap = () => { + scrollRef.current.scrollTo({ + y: 0, + animated: true, + }); + }; useEffect(() => { - setTimeout(() => { - if (scrollRef.current) { - scrollRef.current.scrollTo({ - y: MapHeight - 80, - animated: false, - }); - } + setTimeout(()=>{ + returnToTop(false); }, 10); - }, []); - + }, [mapHeight]); + const returnToDefaultMode = () => { + LayoutAnimation.configureNext({ + duration: 300, + create: { + type: LayoutAnimation.Types.easeInEaseOut, + property: LayoutAnimation.Properties.opacity, + }, + update: { + type: LayoutAnimation.Types.easeInEaseOut, + property: LayoutAnimation.Properties.opacity, + }, + }); + setMapMode(false); + }; //現在地基準の駅名標リストアップ機能 const { position, locationStatus } = useUserPosition(); useEffect(() => { @@ -125,6 +155,7 @@ export default function Menu({ scrollRef }) { } if (listUpStation[listIndex] == undefined) { const count = listIndex - 1; + setMapMode(false); setListIndex(count); } }, [listIndex, nearPositionStation, listUpStation]); @@ -139,8 +170,10 @@ export default function Menu({ scrollRef }) { latitudeDelta: 0.05, longitudeDelta: 0.05, }; + if (mapMode) return; mapsRef.current.animateToRegion(mapRegion, 1000); }, [listIndex, nearPositionStation, listUpStation, mapsRef]); + return ( returnToDefaultMode()} > {listUpStation.map(([{ lat, lng, StationNumber }], index) => ( @@ -196,6 +231,33 @@ export default function Menu({ scrollRef }) { longitude: parseFloat(lng), }} image={require("@/assets/reccha-small.png")} + onPress={() => { + setMapMode(false); + setListIndex(index); + if (mapsRef.current) { + mapsRef.current.animateToRegion( + { + latitude: parseFloat(lat), + longitude: parseFloat(lng), + latitudeDelta: 0.05, + longitudeDelta: 0.05, + }, + 1000 + ); + } + LayoutAnimation.configureNext({ + duration: 300, + create: { + type: LayoutAnimation.Types.easeInEaseOut, + property: LayoutAnimation.Properties.opacity, + }, + update: { + type: LayoutAnimation.Types.easeInEaseOut, + property: LayoutAnimation.Properties.opacity, + }, + }); + returnToTop(); + }} /> ))} @@ -238,4 +300,4 @@ export default function Menu({ scrollRef }) { ); -} +} \ No newline at end of file