スクロールの挙動がおかしかったバグを修正

This commit is contained in:
harukin-expo-dev-env
2025-04-14 18:52:21 +00:00
parent 99ba90f324
commit fa758c144f
3 changed files with 91 additions and 37 deletions

View File

@@ -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 (
<Stack.Navigator>
<Stack.Screen
@@ -83,9 +87,7 @@ export function MenuPage() {
gestureEnabled: true,
headerTransparent: true,
}}
children={() => (
<Menu scrollRef={scrollRef} />
)}
children={() => <Menu scrollRef={scrollRef} mapHeight={mapHeight} />}
/>
<Stack.Screen name="news" options={optionData} component={News} />
<Stack.Screen