Skip to content

Commit 1753656

Browse files
committed
fix(compare): share technology exports on iOS
1 parent 0a5ad7d commit 1753656

1 file changed

Lines changed: 24 additions & 5 deletions

File tree

components/technology-compare/technology-compare-client.tsx

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ import {
2323
getDomainFaviconSrc,
2424
resolveExportFaviconSrc,
2525
resolveExportImageSrc,
26+
sharePngBlob,
27+
shouldUseNativePngShare,
2628
waitForAnimationFrames,
2729
waitForImages,
2830
writePngBlobToClipboard,
@@ -1959,6 +1961,7 @@ export function TechnologyCompareClient({
19591961
setExportStatus("downloading")
19601962

19611963
try {
1964+
const useNativeShare = shouldUseNativePngShare()
19621965
const { value: dataUrl, usedSafeMode } = await withImageSafeRetry(async () => {
19631966
if (!exportRef.current) {
19641967
throw new Error("Export frame unavailable.")
@@ -1967,12 +1970,28 @@ export function TechnologyCompareClient({
19671970
await waitForImages(exportRef.current)
19681971
await waitForAnimationFrames(2)
19691972

1970-
return toPng(exportRef.current, imageExportOptions)
1973+
return useNativeShare
1974+
? toBlob(exportRef.current, imageExportOptions)
1975+
: toPng(exportRef.current, imageExportOptions)
19711976
})
1972-
const anchor = document.createElement("a")
1973-
anchor.href = dataUrl
1974-
anchor.download = getExportFileName(selectedTechnologyLabel)
1975-
anchor.click()
1977+
const fileName = getExportFileName(selectedTechnologyLabel)
1978+
1979+
if (useNativeShare) {
1980+
if (!(dataUrl instanceof Blob)) {
1981+
throw new Error("Export image could not be created.")
1982+
}
1983+
1984+
await sharePngBlob(dataUrl, fileName)
1985+
} else {
1986+
if (typeof dataUrl !== "string") {
1987+
throw new Error("Export image could not be created.")
1988+
}
1989+
1990+
const anchor = document.createElement("a")
1991+
anchor.href = dataUrl
1992+
anchor.download = fileName
1993+
anchor.click()
1994+
}
19761995
setExportStatus(usedSafeMode ? "downloaded-safe" : "downloaded")
19771996
} catch {
19781997
setExportStatus("error")

0 commit comments

Comments
 (0)