From 8a8af6f5a3906b6dc47bc4e7a82c0b1b123abb25 Mon Sep 17 00:00:00 2001 From: harukin-expo-dev-env Date: Sat, 31 Aug 2024 08:33:33 +0000 Subject: [PATCH] =?UTF-8?q?LottieDelayView=E3=82=92=E7=A7=BB=E5=8B=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/駅名表/LottieDelayView.tsx | 36 +++++++++++ components/駅名表/Sign.js | 81 ++++++++---------------- 2 files changed, 61 insertions(+), 56 deletions(-) create mode 100644 components/駅名表/LottieDelayView.tsx diff --git a/components/駅名表/LottieDelayView.tsx b/components/駅名表/LottieDelayView.tsx new file mode 100644 index 0000000..79008a5 --- /dev/null +++ b/components/駅名表/LottieDelayView.tsx @@ -0,0 +1,36 @@ +import React, { CSSProperties, FC, useEffect, useState } from "react"; +import LottieView, { AnimationObject } from "lottie-react-native"; +import { ViewStyle } from "react-native"; + +type Props = { + progress: number; + speed: number; + style: ViewStyle; + source: AnimationObject; + lottieRef: React.RefObject; + loop: boolean; +}; +export const LottieDelayView: FC = (props) => { + const { progress, speed, style, source, lottieRef, loop } = props; + const [progressState, setProgressState] = useState(undefined); + useEffect(() => { + if (progress == 0) { + lottieRef.current.play(progressState !== undefined ? 35 : 7, 7); + } else { + lottieRef.current.play(progressState !== undefined ? 7 : 35, 35); + } + }, [progress]); + return ( + { + setProgressState(progress); + }} + /> + ); +}; diff --git a/components/駅名表/Sign.js b/components/駅名表/Sign.js index a320202..053cb5f 100644 --- a/components/駅名表/Sign.js +++ b/components/駅名表/Sign.js @@ -7,12 +7,10 @@ import { useInterval } from "../../lib/useInterval"; import { AS } from "../../storageControl"; import { useFavoriteStation } from "../../stateBox/useFavoriteStation"; -import { StationName } from "./StationName"; import { StationNameArea } from "./StationNameArea"; import { StationNumberMaker } from "./StationNumberMaker"; import { NextPreStationLine } from "./NextPreStationLine"; - -import lineColorList from "../../assets/originData/lineColorList"; +import { LottieDelayView } from "./LottieDelayView"; export default function Sign(props) { const { @@ -102,6 +100,27 @@ export default function Sign(props) { const lottieRef = useRef(); const isMatsuyama = currentStation[0].StationNumber == "Y55"; //const isMatsuyama = true; + const favoliteChanger = () => { + if (testButtonStatus) { + const otherData = favoriteStation.filter((d) => { + const compare = JSON.stringify(d); + const current = JSON.stringify(currentStation); + if (compare !== current) { + return true; + } else { + return false; + } + }); + AS.setItem("favoriteStation", JSON.stringify(otherData)); + setFavoriteStation(otherData); + } else { + let ret = favoriteStation; + ret.push(currentStation); + AS.setItem("favoriteStation", JSON.stringify(ret)); + setFavoriteStation(ret); + } + setTestButtonStatus(!testButtonStatus); + }; return ( {isMatsuyama && ( @@ -127,38 +146,18 @@ export default function Sign(props) { isMatsuyama={isMatsuyama} /> {isCurrentStation ? ( - + - + ) : ( { - if (testButtonStatus) { - const otherData = favoriteStation.filter((d) => { - const compare = JSON.stringify(d); - const current = JSON.stringify(currentStation); - if (compare !== current) { - return true; - } else { - return false; - } - }); - AS.setItem("favoriteStation", JSON.stringify(otherData)); - setFavoriteStation(otherData); - } else { - let ret = favoriteStation; - ret.push(currentStation); - AS.setItem("favoriteStation", JSON.stringify(ret)); - setFavoriteStation(ret); - } - setTestButtonStatus(!testButtonStatus); - }} + onPress={favoliteChanger} > { - const [progressState, setProgressState] = useState(undefined); - useEffect(() => { - if (progress == 0) { - lottieRef.current.play(progressState !== undefined ? 35 : 7, 7); - } else { - lottieRef.current.play(progressState !== undefined ? 7 : 35, 35); - } - }, [progress]); - return ( - { - setProgressState(progress); - }} - /> - ); -}; const styleSheet = { 外枠: {