-
Notifications
You must be signed in to change notification settings - Fork 936
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(mobile): enhance iOS image preview with SDWebImage and improved …
…QuickLook handling - Add SDWebImage dependency to FollowNative.podspec - Refactor ImagePreview and PreviewControllerController for robust image preview - Implement dynamic file extension handling for image preview - Update WebView bridge to support more flexible image preview payload - Improve MarkdownImage component to use Uint8Array for image conversion Signed-off-by: Innei <[email protected]>
- Loading branch information
Showing
8 changed files
with
134 additions
and
71 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
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
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
47 changes: 27 additions & 20 deletions
47
apps/mobile/web-app/html-renderer/src/components/image.tsx
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 |
---|---|---|
@@ -1,37 +1,44 @@ | ||
import { useRef } from "react" | ||
|
||
import type { HTMLProps } from "~/HTML" | ||
|
||
export const MarkdownImage = (props: HTMLProps<"img">) => { | ||
const { src, ...rest } = props | ||
|
||
const imageRef = useRef<HTMLImageElement>(null) | ||
|
||
return ( | ||
<button | ||
type="button" | ||
onClick={() => { | ||
if (!src) return | ||
const $image = new Image() | ||
$image.src = src | ||
$image.crossOrigin = "anonymous" | ||
|
||
$image.onload = () => { | ||
// Create a canvas element | ||
const canvas = document.createElement("canvas") | ||
canvas.width = $image.width | ||
canvas.height = $image.height | ||
const $image = imageRef.current | ||
if (!$image) return | ||
const canvas = document.createElement("canvas") | ||
canvas.width = $image.naturalWidth | ||
canvas.height = $image.naturalHeight | ||
|
||
// Draw image on canvas | ||
const ctx = canvas.getContext("2d") | ||
ctx?.drawImage($image, 0, 0) | ||
// Draw image on canvas | ||
const ctx = canvas.getContext("2d") | ||
if (!ctx) return | ||
ctx.drawImage($image, 0, 0) | ||
|
||
// Convert to base64 | ||
const imageBase64 = canvas.toDataURL("image/png") | ||
canvas.toBlob((blob) => { | ||
if (!blob) return | ||
const reader = new FileReader() | ||
// eslint-disable-next-line unicorn/prefer-blob-reading-methods | ||
reader.readAsArrayBuffer(blob) | ||
|
||
// Remove base64 prefix | ||
const base64 = imageBase64.split(",")[1]! | ||
bridge.previewImage([base64]) | ||
} | ||
reader.onloadend = () => { | ||
const uint8Array = new Uint8Array(reader.result as ArrayBuffer) | ||
bridge.previewImage({ | ||
images: [uint8Array], | ||
index: 0, | ||
}) | ||
} | ||
}, "image/png") | ||
}} | ||
> | ||
<img {...rest} src={src} /> | ||
<img {...rest} crossOrigin="anonymous" src={src} ref={imageRef} /> | ||
</button> | ||
) | ||
} |