import React, { createContext, useContext } from 'react'; import { ActivityIndicator, Image, Pressable, ScrollView, StyleSheet, Text, TextInput, View, useColorScheme } from 'react-native'; import Ionicons from '@expo/vector-icons/Ionicons'; import {darkTheme,lightTheme} from './core/appearance'; export type Appearance = 'system' | 'light' | 'dark'; export const AppearanceContext=createContext<{mode:Appearance;setMode:(mode:Appearance)=>void}>({mode:'system',setMode:()=>{}}); export function useTheme() { const {mode}=useContext(AppearanceContext),system=useColorScheme();return (mode==='system'?system:mode) === 'dark' ? darkTheme : lightTheme; } export type IconName=React.ComponentProps['name']; export function Icon({name,size=22,color}:{name:IconName;size?:number;color?:string}){const t=useTheme();return ;} export function Avatar({name,uri,size=48}:{name:string;uri?:string;size?:number}){const t=useTheme();return {uri?:{name.slice(0,1)||'我'}};} export function MenuItem({title,detail,icon,onPress,last=false}:{title:string;detail?:string;icon:IconName;onPress:()=>void;last?:boolean}){const t=useTheme();return ({flexDirection:'row',alignItems:'center',gap:13,minHeight:64,paddingVertical:12,opacity:pressed?.65:1,borderBottomWidth:last?0:1,borderColor:t.line})}>{title}{!!detail&&{detail}};} export function Button({ title, onPress, disabled, busy, secondary = false }: { title: string; onPress: () => void; disabled?: boolean; busy?: boolean; secondary?: boolean; }) { const t=useTheme(); return [s.button,{backgroundColor:secondary?t.soft:t.accent,opacity:disabled||busy?0.5:pressed?.75:1}]}> {busy&&}{title}; } export function Field({ label, value, onChange, secure, keyboard, multiline, disabled, maxLength }: { label:string; value:string; onChange:(v:string)=>void; secure?:boolean; keyboard?:'decimal-pad'|'default'|'email-address'|'phone-pad'; multiline?:boolean; disabled?:boolean; maxLength?:number; }) { const t=useTheme(); return {label} ; } export function Card({children}:{children:React.ReactNode}) {const t=useTheme();return {children}} export function Note({children}:{children:React.ReactNode}) {const t=useTheme();return {children}} export function Heading({children}:{children:React.ReactNode}) {const t=useTheme();return {children}} export function Choice({label,items,value,onChange,nameKey}:{label:string;items:Record[];value:Record|null;onChange:(item:Record)=>void;nameKey:string}){ const t=useTheme(),[query,setQuery]=React.useState(''),[expanded,setExpanded]=React.useState(false); const matches=items.filter(item=>String(item[nameKey]||item.areaCode||'').toLowerCase().includes(query.toLowerCase())); return {label}setExpanded(v=>!v)} style={{flexDirection:'row',gap:12,alignItems:'center',padding:14,minHeight:50,borderWidth:1,borderColor:expanded?t.accent:t.line,borderRadius:10,backgroundColor:t.card}}>{value?.[nameKey]||value?.areaCode||`请选择${label}`} {expanded&&{matches.slice(0,20).map(item=>{onChange(item);setExpanded(false);setQuery('');}} style={{paddingVertical:15,paddingHorizontal:4,borderBottomWidth:1,borderColor:t.line,flexDirection:'row',gap:10,alignItems:'center'}}>{item[nameKey]||item.areaCode}{value?.id===item.id&&})} {matches.length>20&&还有 {matches.length-20} 项,请输入名称缩小范围。}{!matches.length&&未找到匹配项。}} ; } export const s=StyleSheet.create({fill:{flex:1},page:{padding:18,gap:16,paddingBottom:36},row:{flexDirection:'row',gap:10,alignItems:'center',flexWrap:'wrap'}, button:{minHeight:46,paddingHorizontal:16,paddingVertical:12,borderRadius:10,flexDirection:'row',gap:8,justifyContent:'center',alignItems:'center'}, input:{borderWidth:1,borderRadius:9,padding:12,fontSize:16},card:{padding:16,borderRadius:14,borderWidth:1,gap:12},header:{paddingHorizontal:18,paddingVertical:14,borderBottomWidth:1,gap:10}, pair:{flexDirection:'row',alignItems:'flex-start',gap:14},label:{width:96,flexShrink:0},value:{flex:1,lineHeight:22}});