This commit is contained in:
zimplexing
2025-07-02 13:56:22 +08:00
parent 53381843fd
commit 810a13a33c
4 changed files with 24 additions and 6 deletions

View File

@@ -148,7 +148,6 @@ export default function HomeScreen() {
setHasMore(true); setHasMore(true);
} }
} catch (err: any) { } catch (err: any) {
console.error("Failed to load data:", err);
if (err.message === "API_URL_NOT_SET") { if (err.message === "API_URL_NOT_SET") {
setError("请点击右上角设置按钮,配置您的 API 地址"); setError("请点击右上角设置按钮,配置您的 API 地址");
} else { } else {
@@ -297,7 +296,9 @@ export default function HomeScreen() {
</View> </View>
) : error ? ( ) : error ? (
<View style={styles.centerContainer}> <View style={styles.centerContainer}>
<ThemedText type="subtitle">{error}</ThemedText> <ThemedText type="subtitle" style={{ padding: 10 }}>
{error}
</ThemedText>
</View> </View>
) : ( ) : (
<FlatList <FlatList

View File

@@ -1,4 +1,4 @@
import React, { useState, useEffect } from "react"; import React, { useState, useEffect, useRef } from "react";
import { import {
Modal, Modal,
View, View,
@@ -25,13 +25,19 @@ export const SettingsModal: React.FC<SettingsModalProps> = ({
onSave, onSave,
}) => { }) => {
const [apiUrl, setApiUrl] = useState(""); const [apiUrl, setApiUrl] = useState("");
const [isInputFocused, setIsInputFocused] = useState(false);
const colorScheme = useColorScheme(); const colorScheme = useColorScheme();
const inputRef = useRef<TextInput>(null);
useEffect(() => { useEffect(() => {
if (visible) { if (visible) {
SettingsManager.get().then((settings) => { SettingsManager.get().then((settings) => {
setApiUrl(settings.apiBaseUrl); setApiUrl(settings.apiBaseUrl);
}); });
const timer = setTimeout(() => {
inputRef.current?.focus();
}, 200);
return () => clearTimeout(timer);
} }
}, [visible]); }, [visible]);
@@ -72,6 +78,14 @@ export const SettingsModal: React.FC<SettingsModalProps> = ({
color: colorScheme === "dark" ? "white" : "black", color: colorScheme === "dark" ? "white" : "black",
borderColor: "transparent", borderColor: "transparent",
}, },
inputFocused: {
borderColor: "#007AFF",
shadowColor: "#007AFF",
shadowOffset: { width: 0, height: 0 },
shadowOpacity: 0.8,
shadowRadius: 10,
elevation: 5,
},
buttonContainer: { buttonContainer: {
flexDirection: "row", flexDirection: "row",
justifyContent: "space-around", justifyContent: "space-around",
@@ -115,13 +129,16 @@ export const SettingsModal: React.FC<SettingsModalProps> = ({
<ThemedView style={styles.modalContent}> <ThemedView style={styles.modalContent}>
<ThemedText style={styles.title}></ThemedText> <ThemedText style={styles.title}></ThemedText>
<TextInput <TextInput
style={styles.input} ref={inputRef}
style={[styles.input, isInputFocused && styles.inputFocused]}
value={apiUrl} value={apiUrl}
onChangeText={setApiUrl} onChangeText={setApiUrl}
placeholder="输入 API 地址" placeholder="输入 API 地址"
placeholderTextColor={colorScheme === "dark" ? "#888" : "#555"} placeholderTextColor={colorScheme === "dark" ? "#888" : "#555"}
autoCapitalize="none" autoCapitalize="none"
autoCorrect={false} autoCorrect={false}
onFocus={() => setIsInputFocused(true)}
onBlur={() => setIsInputFocused(false)}
/> />
<View style={styles.buttonContainer}> <View style={styles.buttonContainer}>
<Pressable <Pressable

View File

@@ -15,7 +15,7 @@
"test": "jest --watchAll", "test": "jest --watchAll",
"lint": "expo lint", "lint": "expo lint",
"prebuild": "EXPO_USE_METRO_WORKSPACE_ROOT=1 expo prebuild --clean", "prebuild": "EXPO_USE_METRO_WORKSPACE_ROOT=1 expo prebuild --clean",
"prebuild-tv": "EXPO_TV=1 EXPO_USE_METRO_WORKSPACE_ROOT=1 expo prebuild --clean && yarn copy-config", "prebuild-tv": "EXPO_TV=1 EXPO_USE_METRO_WORKSPACE_ROOT=1 expo prebuild --clean",
"copy-config": "cp -r xml/* android/app/src/*", "copy-config": "cp -r xml/* android/app/src/*",
"build-local": "cd android && ./gradlew assembleRelease" "build-local": "cd android && ./gradlew assembleRelease"
}, },

View File

@@ -178,7 +178,7 @@ export class SettingsManager {
theme: "auto", theme: "auto",
autoPlay: true, autoPlay: true,
playbackSpeed: 1.0, playbackSpeed: 1.0,
apiBaseUrl: "http://127.0.0.1:3001", apiBaseUrl: "",
}; };
try { try {
const data = await AsyncStorage.getItem(STORAGE_KEYS.SETTINGS); const data = await AsyncStorage.getItem(STORAGE_KEYS.SETTINGS);