- 在 package.json 和 package-lock.json 中新增 @sentry/react-native、react-native-device-info 和 react-native-purchases 依赖 - 更新统计页面,替换 CircularRing 组件为 FitnessRingsCard,增强健身数据展示 - 在布局文件中引入 ToastProvider,优化用户通知体验 - 新增 SuccessToast 组件,提供全局成功提示功能 - 更新健康数据获取逻辑,支持健身圆环数据的提取 - 优化多个组件的样式和交互,提升用户体验
58 lines
1.4 KiB
TypeScript
58 lines
1.4 KiB
TypeScript
/**
|
|
* 全局Toast工具函数
|
|
*
|
|
* 使用方式:
|
|
* import { Toast } from '@/utils/toast.utils';
|
|
*
|
|
* Toast.success('操作成功!');
|
|
* Toast.error('操作失败!');
|
|
* Toast.warning('注意!');
|
|
*/
|
|
|
|
import { ToastContextType } from '@/contexts/ToastContext';
|
|
|
|
let toastRef: ToastContextType | null = null;
|
|
|
|
export const setToastRef = (ref: ToastContextType) => {
|
|
toastRef = ref;
|
|
};
|
|
|
|
export const Toast = {
|
|
success: (message: string, duration?: number) => {
|
|
if (toastRef) {
|
|
toastRef.showSuccess(message, duration);
|
|
} else {
|
|
console.warn('Toast not initialized. Please wrap your app with ToastProvider');
|
|
}
|
|
},
|
|
|
|
error: (message: string, duration?: number) => {
|
|
if (toastRef) {
|
|
toastRef.showError(message, duration);
|
|
} else {
|
|
console.warn('Toast not initialized. Please wrap your app with ToastProvider');
|
|
}
|
|
},
|
|
|
|
warning: (message: string, duration?: number) => {
|
|
if (toastRef) {
|
|
toastRef.showWarning(message, duration);
|
|
} else {
|
|
console.warn('Toast not initialized. Please wrap your app with ToastProvider');
|
|
}
|
|
},
|
|
|
|
show: (config: {
|
|
message: string;
|
|
duration?: number;
|
|
backgroundColor?: string;
|
|
textColor?: string;
|
|
icon?: string;
|
|
}) => {
|
|
if (toastRef) {
|
|
toastRef.showToast(config);
|
|
} else {
|
|
console.warn('Toast not initialized. Please wrap your app with ToastProvider');
|
|
}
|
|
},
|
|
}; |