新增自动更新功能,隐藏首页T5骑行台入口
① 新增自动更新功能(UpdateModal),HomeScreen接入版本检测 ② LanguageModal 添加 statusBarTranslucent 浸润样式 ③ 首页T5骑行台入口注释隐藏 ④ 版本号从 1.0.1 升级至 1.0.2 ⑤ 多语言文件更新(en.json, zh.json) ⑥ 新增 CLAUDE.md 项目说明文档 ⑦ 更新 yarn.lock 依赖 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
8dd0edd2ce
commit
64beed9c4e
12 files changed
+983
-746
No files matched your search
+95
-33
@@ -1,48 +1,111 @@
|
||||
import React from "react";
|
||||
import { View, Text, TouchableOpacity, StyleSheet, StatusBar, Image } from "react-native";
|
||||
import { NativeStackScreenProps,NativeStackNavigationProp } from "@react-navigation/native-stack";
|
||||
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';
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
type Props = NativeStackScreenProps<RootStackParamList>;
|
||||
|
||||
interface UpdateInfo {
|
||||
latestVersion: string;
|
||||
downloadUrl: string;
|
||||
updateLogs: string[];
|
||||
}
|
||||
|
||||
const UPDATE_JSON_URL = "https://powerfun.oss-cn-shanghai.aliyuncs.com/yecongdfu/apks/update.json";
|
||||
|
||||
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<UpdateInfo | null>(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 (
|
||||
<View style={styles.container}>
|
||||
{/* 设置状态栏颜色 */}
|
||||
<MyStatusbar backgroundColor="#E7141E" dark={false}></MyStatusbar>
|
||||
<MyHeader title={t('home.title')} textColor="#fff" backgroundColor="#E7141E" hideBack navigation={navigation}
|
||||
rightView={<TouchableOpacity style={{width:pxToDp(56),height:pxToDp(56),alignItems:'center',justifyContent:'center'}}
|
||||
onPress={() => navigation.navigate("Setting")}>
|
||||
<Image source={require('./img/Settings.png')} style={{width:pxToDp(48),height:pxToDp(44)}}></Image>
|
||||
</TouchableOpacity>}></MyHeader>
|
||||
{/* 中间按钮 */}
|
||||
<MyHeader
|
||||
title={t("home.title")}
|
||||
textColor="#fff"
|
||||
backgroundColor="#E7141E"
|
||||
hideBack
|
||||
navigation={navigation}
|
||||
rightView={
|
||||
<TouchableOpacity
|
||||
style={{ width: pxToDp(56), height: pxToDp(56), alignItems: "center", justifyContent: "center" }}
|
||||
onPress={() => navigation.navigate("Setting")}
|
||||
>
|
||||
<Image source={require("./img/Settings.png")} style={{ width: pxToDp(48), height: pxToDp(44) }}></Image>
|
||||
</TouchableOpacity>
|
||||
}
|
||||
></MyHeader>
|
||||
|
||||
<View style={styles.centerBox}>
|
||||
<Image source={require("./img/Search.png")} style={{width:pxToDp(568),height:pxToDp(344),marginBottom:pxToDp(100)}}></Image>
|
||||
<TouchableOpacity
|
||||
style={styles.button}
|
||||
onPress={() => navigation.navigate("Scan")}
|
||||
>
|
||||
<Image source={require("./img/Search.png")} style={{ width: pxToDp(568), height: pxToDp(344), marginBottom: pxToDp(100) }}></Image>
|
||||
<TouchableOpacity style={styles.button} onPress={() => navigation.navigate("Scan")}>
|
||||
<Text style={styles.buttonText}>{t("home.powerMeter")}</Text>
|
||||
</TouchableOpacity>
|
||||
<TouchableOpacity
|
||||
style={[styles.button, { marginTop: pxToDp(20) }]}
|
||||
onPress={() => navigation.navigate("ScanScreen2")}
|
||||
>
|
||||
<TouchableOpacity style={[styles.button, { marginTop: pxToDp(20) }]} onPress={() => navigation.navigate("ScanScreen2")}>
|
||||
<Text style={styles.buttonText}>{t("home.paddle")}</Text>
|
||||
</TouchableOpacity>
|
||||
<TouchableOpacity
|
||||
style={[styles.button, { marginTop: pxToDp(20) }]}
|
||||
onPress={() => navigation.navigate("ScanScreen3")}
|
||||
>
|
||||
{/* <TouchableOpacity style={[styles.button, { marginTop: pxToDp(20) }]} onPress={() => navigation.navigate("ScanScreen3")}>
|
||||
<Text style={styles.buttonText}>{t("home.T5trainer")}</Text>
|
||||
</TouchableOpacity>
|
||||
</TouchableOpacity> */}
|
||||
</View>
|
||||
|
||||
<UpdateModal
|
||||
visible={updateModalVisible}
|
||||
updateInfo={updateInfo}
|
||||
currentVersion={currentVersion}
|
||||
onClose={() => setUpdateModalVisible(false)}
|
||||
/>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
@@ -54,18 +117,17 @@ const styles = StyleSheet.create({
|
||||
},
|
||||
centerBox: {
|
||||
flex: 1,
|
||||
// justifyContent: "center",
|
||||
alignItems: "center",
|
||||
backgroundColor:'#fff',
|
||||
paddingTop:pxToDp(250)
|
||||
backgroundColor: "#fff",
|
||||
paddingTop: pxToDp(250),
|
||||
},
|
||||
button: {
|
||||
backgroundColor: "#E7141E",
|
||||
borderRadius: pxToDp(24),
|
||||
width:pxToDp(300),
|
||||
height:pxToDp(96),
|
||||
alignItems:'center',
|
||||
justifyContent:'center'
|
||||
width: pxToDp(300),
|
||||
height: pxToDp(96),
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
},
|
||||
buttonText: {
|
||||
color: "#fff",
|
||||
@@ -78,7 +140,7 @@ const styles = StyleSheet.create({
|
||||
},
|
||||
privacyText: {
|
||||
fontSize: 16,
|
||||
color: "#E7141E", // 红色字体
|
||||
color: "#E7141E",
|
||||
marginBottom: 8,
|
||||
},
|
||||
version: {
|
||||
|
||||
Reference in new issue
Block a user