-
-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4d934a5
commit a4858bb
Showing
8 changed files
with
183 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { View, Text } from 'react-native'; | ||
|
||
interface BaseProps { | ||
heading?: string | ||
} | ||
|
||
type ErrorBannerProps = | ||
| (BaseProps & { message: string; error?: never }) | ||
| (BaseProps & { error: Error; message?: never }) | ||
|
||
const ErrorBanner = ({ heading, message, error }: ErrorBannerProps) => { | ||
return ( | ||
<View className="container"> | ||
<View className="border-l-[6px] border-error-border bg-error-background flex w-full rounded-lg px-6 py-3 md:p-9"> | ||
<View className="w-full"> | ||
{(heading || error) && (heading ? | ||
<Text className="mb-3 text-lg font-semibold text-error-heading"> | ||
{heading} | ||
</Text> : | ||
<Text className="mb-3 text-lg font-semibold text-error-heading"> | ||
{error?.name} | ||
</Text> | ||
)} | ||
{(message || error) && (message ? | ||
<Text className="text-error mb-2"> | ||
{message} | ||
</Text> : | ||
<Text className="text-error mb-2"> | ||
{error?.message} | ||
</Text> | ||
)} | ||
</View> | ||
</View> | ||
</View> | ||
) | ||
} | ||
|
||
export default ErrorBanner |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import ErrorBanner from "@components/common/ErrorBanner"; | ||
import useFileURL from "@hooks/useFileURL"; | ||
import { useWindowDimensions, Image, View } from "react-native"; | ||
import { fitContainer, ResumableZoom, Source, useImageResolution } from "react-native-zoom-toolkit"; | ||
|
||
interface ImageViewerProps { | ||
uri: string | ||
handleShowHeader: VoidFunction | ||
} | ||
|
||
const ImageViewer = ({ uri, handleShowHeader }: ImageViewerProps) => { | ||
console.log('ImageViewer', uri) | ||
const source = useFileURL(uri) | ||
if (!source) { | ||
return <View className="p-2"> | ||
<ErrorBanner message="Something went wrong" heading="Couldn't open image" /> | ||
</View> | ||
} | ||
return ( | ||
<ImageComponent source={source} handleShowHeader={handleShowHeader} /> | ||
) | ||
} | ||
|
||
export default ImageViewer | ||
|
||
const ImageComponent = ({ source, handleShowHeader }: { source: Source, handleShowHeader: VoidFunction }) => { | ||
|
||
const { width, height } = useWindowDimensions() | ||
const { isFetching, resolution, error } = useImageResolution(source) | ||
if (isFetching || resolution === undefined || error) { | ||
console.log('isFetching', isFetching) | ||
console.log('resolution', resolution) | ||
return <View className="p-2"> | ||
{error && <ErrorBanner error={error} />} | ||
</View> | ||
} | ||
|
||
const size = fitContainer(resolution.width / resolution.height, { | ||
width, | ||
height, | ||
}) | ||
|
||
return ( | ||
<ResumableZoom maxScale={resolution} onTap={handleShowHeader}> | ||
<Image source={source} style={{ ...size }} resizeMethod={'scale'} /> | ||
</ResumableZoom> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.