cmvr-wms/mobile-app/src/dialogs.tsx
lixiaolong d37b4ff379 refactor(mobile): 重构移动端应用结构和配置
- 将 Account 组件中的 Text 导入移动到顶部
- 移除 App.tsx 中的 expo-updates 相关代码
- 添加 PackageUpdates 相关组件和 hooks
- 更新应用名称从 "CMVR 物资管理" 为 "车研物资"
- 添加应用图标和自适应图标配置
- 更新 Android 权限配置,添加 REQUEST_INSTALL_PACKAGES 权限
- 修改堆栈导航数据结构,支持路由参数传递
- 添加阅读尺寸偏好设置功能
- 重构登录界面为独立组件 LoginView
- 添加文件库界面组件 FileLibrary
- 更新状态栏样式逻辑
- 调整 Tab 栏样式和尺寸
- 集成包更新和应用更新对话框
- 修复导入语句顺序和类型引用
- 优化业务列表组件的路由参数处理
- 添加作用域参数用于 API 请求区分
2026-10-28 17:30:35 +08:00

21 lines
1.8 KiB
TypeScript

import {Text} from './typography';
import React,{useEffect,useState} from 'react';
import {Alert,Modal,Platform,View,type AlertButton} from 'react-native';
import {Button,s,useTheme} from './ui';
type Prompt={title:string;message?:string;buttons:AlertButton[]};
let present:((prompt:Prompt)=>void)|undefined;
// React Native Web has no Alert implementation. Keep preview confirmations functional,
// while Android uses its familiar accessible native confirmation dialog.
export const Dialog={alert:(title:string,message?:string,buttons:AlertButton[]=[{text:'知道了'}])=>{
if(Platform.OS!=='web')Alert.alert(title,message,buttons);else present?.({title,message,buttons});
}};
export function PreviewDialogs(){
const t=useTheme(),[prompt,setPrompt]=useState<Prompt|null>(null);
useEffect(()=>{present=p=>setPrompt(old=>old||p);return()=>{present=undefined;};},[]);
// Mount the portal only when needed. A permanently mounted hidden Modal keeps
// its original DOM position and can sit underneath a later stock-operation Modal.
if(Platform.OS!=='web'||!prompt)return null;
function dismiss(){const cancel=prompt?.buttons.find(b=>b.style==='cancel');if(cancel){setPrompt(null);cancel.onPress?.();}}
return <Modal transparent visible={!!prompt} animationType="fade" onRequestClose={dismiss}><View style={{flex:1,backgroundColor:'rgba(10,20,35,.45)',justifyContent:'center',alignItems:'center',padding:24}}><View accessibilityRole="alert" style={{backgroundColor:t.card,borderRadius:22,padding:24,gap:18,maxWidth:380,width:'100%'}}><Text style={{color:t.text,fontSize:18,fontWeight:'700'}}>{prompt?.title}</Text><Text style={{color:t.muted,lineHeight:24}}>{prompt?.message}</Text>{prompt?.buttons.map((button,i)=><Button key={i} title={button.text||'确定'} secondary={button.style==='cancel'} onPress={()=>{setPrompt(null);button.onPress?.();}}/>)}</View></View></Modal>;
}