/** * 新充电流程:正在充电模块 * @邠心vbe on 2023/06/20 */ import React, { useEffect, useRef, useState } from 'react'; import { Animated, Easing, Image, ScrollView, StyleSheet, Text, View } from 'react-native'; import Button, { ElevationObject } from '../../components/Button'; import TextView from '../../components/TextView'; import utils from '../../utils/utils'; import { PaymentList } from '../chargeV2/Payment'; const StepCharging = ({ connectorInfo={}, currentPayment, curerntPerUse, onStopCharge }) => { const [isCharging, setCharging] = useState(false); const [loadingEmps, setEmps] = useState(""); const [skipAnim, setAnimSkip] = useState(false); const topAnim = useRef(new Animated.Value($vw(16)*-2)).current; const fadeAnim = useRef(new Animated.Value(0)).current; const moveTop = () => { fadeAnim.setValue(0); Animated.timing(topAnim, { toValue: ($vh(50) * -1 - $vw(16) - 32), duration: 1000, easing: Easing.linear, useNativeDriver: false }).start(); setTimeout(() => { setCharging(true); showFade(); }, 1100); } const showFade = () => { Animated.timing(fadeAnim, { toValue: 1, duration: 1000, useNativeDriver: false }).start(); setTimeout(() => { setAnimSkip(true); }, 1100); } useEffect(() => { const isCharge = (connectorInfo.status == "Charging"); console.log("[useEffect]:start", isCharge, fadeAnim); setCharging(isCharge); setAnimSkip(isCharge); if (!isCharge) { changeEmps(); } }, []) useEffect(() => { //console.log("[useEffect]:connectorInfo", connectorInfo.status); if (connectorInfo.status == "Charging") { if (!isCharging) { moveTop(); } } else { setCharging(false) } }, [connectorInfo]) useEffect(() => { //console.log("[useEffect]:loadingEmps", loadingEmps); if (connectorInfo.status == "Charging") { moveTop(); } else { setTimeout(() => { changeEmps(); }, 500); } }, [loadingEmps]) const changeEmps = () => { let emp = loadingEmps; if (loadingEmps.length == 3) { emp = ""; } else { emp += "."; } setEmps(emp); } return ( isCharging ? {$t('charging.statusCharging')} {$t('charging.stepChargingDesc')} { connectorInfo.batteryPercent >= 0 && {connectorInfo.batteryPercent || "0"}% } {$t('charging.labelTimeElapsed')} {utils.minutes2HHMM(connectorInfo?.timeElapsed ?? 0)} {$t('charging.labelTotalkWh')} {connectorInfo.totalKWhDelivered || "0"} kWh {$t('charging.labelRate')} {connectorInfo.rates || "S$0.00/kWh"} ({connectorInfo.userRates || "S$0.00/kWh"}) {$t('charging.labelTotalCharges')} {connectorInfo.totalCharges || "S$ 0.0"} ({connectorInfo.userTotalCharges || "S$ 0.0"}) {$t('charging.paymentMethod')}