import React, { useEffect, useState } from "react"; import { View, Text, TouchableOpacity, StyleSheet, Image, Platform } from "react-native"; import { NativeStackScreenProps } from "@react-navigation/native-stack"; import { RootStackParamList } from "../App"; import MyStatusbar from "./component/MyStatusbar"; import MyHeader from "./component/MyHeader"; import UpdateModal from "./component/UpdateModal"; import pxToDp from "./helper/pxToDp"; import DeviceInfo from "react-native-device-info"; import { useTranslation } from "react-i18next"; type Props = NativeStackScreenProps; interface UpdateInfo { latestVersion: string; downloadUrl: string; updateLogs: string[]; } const UPDATE_JSON_URL = `https://powerfun.oss-cn-shanghai.aliyuncs.com/yecongdfu/apks/update.json?t=${Date.now()}`; const compareVersions = (latest: string, current: string): boolean => { const latestParts = latest.split(".").map(Number); const currentParts = current.split(".").map(Number); for (let i = 0; i < Math.max(latestParts.length, currentParts.length); i++) { const latestNum = latestParts[i] || 0; const currentNum = currentParts[i] || 0; if (latestNum > currentNum) return true; if (latestNum < currentNum) return false; } return false; }; export default function HomeScreen({ navigation }: Props) { const { t } = useTranslation(); const [updateModalVisible, setUpdateModalVisible] = useState(false); const [updateInfo, setUpdateInfo] = useState(null); const [currentVersion, setCurrentVersion] = useState(""); useEffect(() => { const checkUpdate = async () => { try { const version = DeviceInfo.getVersion(); setCurrentVersion(version); const resp = await fetch(UPDATE_JSON_URL); if (!resp.ok) return; const data = await resp.json(); const platform = Platform.OS === "ios" ? "ios" : "android"; const platformUpdate = data[platform]; if (!platformUpdate) return; if (compareVersions(platformUpdate.latestVersion, version)) { setUpdateInfo({ latestVersion: platformUpdate.latestVersion, downloadUrl: platformUpdate.downloadUrl, updateLogs: platformUpdate.updateLogs || [], }); setUpdateModalVisible(true); } } catch (e) { console.log("检查更新失败:", e); } }; checkUpdate(); }, []); return ( navigation.navigate("Setting")} > } > navigation.navigate("Scan")}> {t("home.powerMeter")} navigation.navigate("ScanScreen2")}> {t("home.paddle")} {/* navigation.navigate("ScanScreen3")}> {t("home.T5trainer")} */} setUpdateModalVisible(false)} /> ); } const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: "#fff", }, centerBox: { flex: 1, alignItems: "center", backgroundColor: "#fff", paddingTop: pxToDp(250), }, button: { backgroundColor: "#E7141E", borderRadius: pxToDp(24), width: pxToDp(300), height: pxToDp(96), alignItems: "center", justifyContent: "center", }, buttonText: { color: "#fff", fontSize: pxToDp(32), fontWeight: "bold", }, bottomBox: { alignItems: "center", marginBottom: 20, }, privacyText: { fontSize: 16, color: "#E7141E", marginBottom: 8, }, version: { fontSize: 14, color: "#999", }, });