- Remove 'as any' type assertion in LoginScreen.tsx, use Platform.OS check - Fix malformed className string in LogoutButton.tsx (extra quotes) - Remove @ts-ignore comments in Tooltip.tsx with proper web-specific types - Replace 'any' type with Schedule type in AvailabilityTab.tsx - Replace 'any' type with 'string' for SF Symbol icons in EventTypeListItem.ios.tsx - Remove console.log error handling in SvgImage.tsx - Extract duplicated formatDuration function to use shared utility from formatters.ts - Extract repeated inline styles to sectionDividerStyle constant in AvailabilityTab.tsx Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Dhairyashil <[email protected]>
54 lines
1.4 KiB
TypeScript
54 lines
1.4 KiB
TypeScript
import React, { useState } from "react";
|
|
import { View, Image } from "react-native";
|
|
import { SvgUri } from "react-native-svg";
|
|
|
|
interface SvgImageProps {
|
|
uri: string;
|
|
width: number;
|
|
height: number;
|
|
style?: { marginRight?: number };
|
|
}
|
|
|
|
/**
|
|
* Component that can display both SVG and regular images
|
|
* Falls back to regular Image if SVG fails
|
|
*/
|
|
export const SvgImage: React.FC<SvgImageProps> = ({ uri, width, height, style }) => {
|
|
const [useFallback, setUseFallback] = useState(false);
|
|
// Extract pathname (ignore query strings and hash) to detect SVG correctly
|
|
// Handles URLs like: icon.svg?variant=dark or icon.svg#hash
|
|
const pathname = uri.split("?")[0].split("#")[0];
|
|
const isSvg = pathname.toLowerCase().endsWith(".svg");
|
|
|
|
if (!isSvg || useFallback) {
|
|
// Use regular Image for non-SVG or if SVG failed
|
|
return (
|
|
<View style={style}>
|
|
<Image
|
|
source={{ uri }}
|
|
style={{ width, height }}
|
|
resizeMode="contain"
|
|
onError={() => {
|
|
// Image load errors are expected for invalid/missing URLs - silently handled
|
|
}}
|
|
/>
|
|
</View>
|
|
);
|
|
}
|
|
|
|
// Use SvgUri for SVG files
|
|
return (
|
|
<View style={[{ width, height }, style]}>
|
|
<SvgUri
|
|
uri={uri}
|
|
width={width}
|
|
height={height}
|
|
onError={() => {
|
|
// SVG load errors trigger fallback to regular Image component
|
|
setUseFallback(true);
|
|
}}
|
|
/>
|
|
</View>
|
|
);
|
|
};
|