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'; const NotificationDetailPage = () => { 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 ? ( ) : ( { if (router.canGoBack()) { router.back(); } else { router.replace('/notificationPage'); } }} hitSlop={{ top: 20, bottom: 20, left: 20, right: 20 }} > 詳情 {promotionObj.title} {promotionImage && ( )} {promotionObj.text} 最新更新日期:{formatToChineseDateTime(promotionObj.updatedAt)} )} ); }; export default NotificationDetailPage;