import React, { useEffect, useRef, useState } from 'react';
import {
AccessibilityInfo, KeyboardAvoidingView, Platform, Pressable, ScrollView,
StatusBar, StyleSheet, Switch, Text, TextInput, View,
} from 'react-native';
import AsyncStorage from '@react-native-async-storage/async-storage';
import { SafeAreaProvider, SafeAreaView } from 'react-native-safe-area-context';
const KEY = 'dashen-ui:preferences:v1';
const color = {
bg: '#070907', panel: '#10120f', text: '#f1e8d6', muted: '#bcae95', label: '#ffae36',
accent: '#ed6e2e', focus: '#ffae36', rule: '#ff3300', line: '#79532c',
success: '#64eaa1', error: '#ff604c',
};
function ButtonNotch({position}) {
// Two nested triangles expose a one-pixel diagonal edge over the panel.
const corner = position === 'top' ? s.topRight : s.bottomLeft;
return <>
>;
}
function PartId({children}) {
return {children};
}
function Preferences() {
const [name, setName] = useState('编辑');
const [notifications, setNotifications] = useState(true);
const [busy, setBusy] = useState(true);
const [message, setMessage] = useState('');
const [tone, setTone] = useState('muted');
const [focused, setFocused] = useState(false);
const [fieldInvalid, setFieldInvalid] = useState(false);
const [buttonFocused, setButtonFocused] = useState(false);
const [pressedKey, setPressedKey] = useState(false);
const [hovered, setHovered] = useState(false);
const [reduceMotion, setReduceMotion] = useState(true);
const input = useRef(null);
const saving = useRef(false);
useEffect(() => {
let active = true;
AccessibilityInfo.isReduceMotionEnabled().then(value => {
if (active) setReduceMotion(value);
}).catch(() => {});
const motion = AccessibilityInfo.addEventListener('reduceMotionChanged', setReduceMotion);
async function load() {
try {
const item = await AsyncStorage.getItem(KEY);
if (item && active) {
const value = JSON.parse(item);
if (typeof value.name === 'string') setName(value.name);
if (typeof value.notifications === 'boolean') setNotifications(value.notifications);
}
} catch {
if (active) { setMessage('读取失败,可重新填写并保存。'); setTone('error'); }
} finally {
if (active) setBusy(false);
}
}
load();
return () => { active = false; motion.remove(); };
}, []);
function clearMessage() { setMessage(''); setTone('muted'); setFieldInvalid(false); }
async function save() {
if (busy || saving.current) return;
const trimmed = name.trim();
if (Array.from(trimmed).length < 2 || Array.from(trimmed).length > 24) {
setFieldInvalid(true); setTone('error'); setMessage('请输入 2–24 个字符。'); input.current?.focus(); return;
}
saving.current = true;
setBusy(true); setMessage('正在保存…'); setTone('muted');
try {
await AsyncStorage.setItem(KEY, JSON.stringify({ name: trimmed, notifications }));
setName(trimmed); setTone('success'); setMessage('偏好设置已保存到此设备。');
} catch {
setTone('error'); setMessage('保存失败,请重试。');
} finally {
saving.current = false; setBusy(false);
}
}
const nameLength = Array.from(name.trim()).length;
const validLength = nameLength >= 2 && nameLength <= 24;
return
ADP-APP · UI-009 · UI-009-TITLE
偏好设置
仅保存在此设备上。
UI-009-RULE
UI-009-SECTION · UI-006-LABEL
显示名称
{['UI-006-FIELD', focused && 'UI-006-FOCUS', fieldInvalid && 'UI-006-ERROR'].filter(Boolean).join(' · ')}
{ setName(v); clearMessage(); }}
onFocus={() => setFocused(true)} onBlur={() => setFocused(false)}
style={[s.input, focused && {borderColor: color.focus}, fieldInvalid && {borderColor: color.error}]} returnKeyType="done" />
2–24 个字符
{nameLength} / 24
UI-006-HELP
{notifications ? "UI-007-LABEL · UI-007-ON" : "UI-007-LABEL · UI-007-OFF"}
状态通知
{ setNotifications(v); clearMessage(); }} />
UI-007-TRACK · UI-007-THUMB
{["UI-005-PRIMARY",busy && "UI-005-DISABLED",busy && "UI-005-BUSY",pressedKey && "UI-005-ACTIVE",hovered && "UI-005-HOVER",buttonFocused && "UI-005-FOCUS"].filter(Boolean).join(" · ")}
setPressedKey(true)} onPressOut={() => setPressedKey(false)}
onFocus={() => setButtonFocused(true)} onBlur={() => setButtonFocused(false)}
onHoverIn={() => setHovered(true)} onHoverOut={() => setHovered(false)}
style={({pressed}) => [s.button, hovered && s.hovered, pressed && s.pressed,
!reduceMotion && !busy && {transform: [{translateY: pressed ? 2 : hovered ? -1 : 0}]},
buttonFocused && s.buttonFocus, busy && s.disabled]}>
保存设置
UI-005-CUT · UI-005-RAIL
{tone === "error" ? "UI-008-ERROR" : "UI-008-STATUS"}
{message}
;
}
export default function App() {
return ;
}
const s = StyleSheet.create({
id: {fontFamily: Platform.select({ios:"Menlo",android:"monospace"}), fontSize:11, color:"#bcae95", marginVertical:3, flexShrink:1},
screen: {flex: 1, backgroundColor: color.bg},
page: {width: '100%', maxWidth: 640, alignSelf: 'center', padding: 20, paddingVertical: 32},
meterHead: {flexDirection:'row', alignItems:'center', justifyContent:'space-between', flexWrap:'wrap'},
count: {color:color.label, fontFamily:Platform.select({ios:'Menlo',android:'monospace'}), fontVariant:['tabular-nums']},
meterTrack: {height:3, backgroundColor:color.line, marginTop:3, marginBottom:6},
title: {fontSize: 38, fontWeight: '800', letterSpacing: -1.8, color: color.accent,
textShadowColor: color.rule, textShadowOffset: {width: 0, height: 0}, textShadowRadius: 3, marginBottom: 8},
help: {color: color.muted, fontSize: 15, marginVertical: 3},
rule: {marginTop: 20, height: 2, backgroundColor: color.rule, zIndex: 1,
boxShadow: '0 0 6px #ff3300'},
card: {backgroundColor: color.panel, borderColor: color.line, borderWidth: 1, borderTopColor: color.label, padding: 20},
label: {fontSize: 17, fontWeight: '600', color: color.label, flexShrink: 1},
input: {marginTop: 8, fontSize: 18, minHeight: 48, color: color.text,
borderColor: color.line, borderWidth: 2, paddingHorizontal: 12, backgroundColor: color.bg},
row: {paddingVertical: 20, flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', gap: 12},
button: {minHeight: 56, justifyContent: 'center', alignItems: 'center', backgroundColor: color.panel,
paddingTop: 7, paddingBottom: 21, paddingHorizontal: 18,
borderWidth: 1, borderRadius: 0, borderColor: color.accent,
boxShadow: '0 3px 0 #392612, 0 5px 8px #000'},
spectrum: {position: 'absolute', left: 0, right: 0, bottom: 0, height: 4,
experimental_backgroundImage: 'linear-gradient(90deg, #ffae36, #ff7934)'},
cutEdge: {position: 'absolute', width: 0, height: 0, borderTopWidth: 13, borderLeftWidth: 13,
borderTopColor: color.accent, borderLeftColor: 'transparent'},
cutMask: {borderTopWidth: 11, borderLeftWidth: 11, borderTopColor: color.panel},
topRight: {right: -1, top: -1},
bottomLeft: {left: -1, bottom: -1, transform: [{rotate: '180deg'}]},
hovered: {borderColor: color.label, boxShadow: '0 3px 0 #392612, 0 0 10px #79532c'},
pressed: {borderColor: color.focus, boxShadow: '0 1px 0 #392612'},
buttonFocus: {outlineStyle: 'solid', outlineColor: color.focus, outlineWidth: 2, outlineOffset: 3},
disabled: {opacity: 0.6, boxShadow: 'none'},
action: {fontSize: 17, fontWeight: '700', color: color.label},
status: {marginTop: 12, minHeight: 22, fontSize: 15},
});