// app/(auth)/(tabs)/(home)/notificationDetailPage.tsx
import {
View,
Text,
Pressable,
Image,
ScrollView,
Alert,
ImageBackground,
ActivityIndicator,
Dimensions
} from 'react-native';
import { SafeAreaView } from 'react-native-safe-area-context';
import { router, useLocalSearchParams } from 'expo-router';
import { CrossLogoSvg, PreviousPageBlackSvg } from '../../../../component/global/SVG';
import { useEffect, useState } from 'react';
import { chargeStationService } from '../../../../service/chargeStationService';
import { formatToChineseDateTime } from '../../../../util/lib';
import { useTranslation } from '../../../../util/hooks/useTranslation';
const NotificationDetailPage = () => {
const { t, getCurrentLanguageConfig } = useTranslation(); // 使用翻译钩子
const isEn = getCurrentLanguageConfig()?.code === 'en';
const screenHeight = Dimensions.get('window').height;
const { promotion } = useLocalSearchParams();
const promotionObj = JSON.parse(promotion as string);
const [loading, setLoading] = useState(false);
const [promotionImage, setPromotionImage] = useState('');
const AdaptiveImage = ({ source }: { source: string }) => {
const [aspectRatio, setAspectRatio] = useState(1);
const [error, setError] = useState(false);
const windowWidth = Dimensions.get('window').width;
useEffect(() => {
if (source) {
// Remote image
Image.getSize(
source,
(width, height) => {
if (width && height) {
setAspectRatio(width / height);
setError(false);
} else {
setError(true);
console.error('Invalid image dimensions received');
}
},
(error) => {
setError(true);
console.error('Error getting image size:', error);
}
);
} else {
try {
// Local image
const dimensions = Image.resolveAssetSource({ uri: source });
if (dimensions && dimensions.width && dimensions.height) {
setAspectRatio(dimensions.width / dimensions.height);
setError(false);
} else {
setError(true);
console.error('Invalid dimensions from resolveAssetSource');
}
} catch (e) {
setError(true);
console.error('Error resolving asset source:', e);
}
}
}, [source]);
if (error) {
return;
}
return (
);
};
useEffect(() => {
setLoading(true);
const fetchPromotionImage = async () => {
try {
const promotionImage = await chargeStationService.getProcessedImageUrl(promotionObj.image_url);
setPromotionImage(promotionImage);
} catch (e) {
} finally {
setLoading(false);
}
};
fetchPromotionImage();
}, []);
return (
{loading ? (
{t('common.loading')}
) : (
{
if (router.canGoBack()) {
router.back();
} else {
router.replace('/notificationPage');
}
}}
hitSlop={{ top: 20, bottom: 20, left: 20, right: 20 }}
>
{t('notifications.charging_detail.title')}
{isEn?promotionObj.title_en:promotionObj.title}
{promotionImage && (
)}
{isEn?promotionObj.text_en:promotionObj.text}
{t('notifications.charging_detail.last_updated')}: {formatToChineseDateTime(promotionObj.updatedAt)}
)}
);
};
export default NotificationDetailPage;