Bluesky app fork with some witchin' additions 💫
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Fix image sharing on iOS (#561)

authored by

Paul Frazee and committed by
GitHub
ddb8ebb4 bd80db61

+39 -9
+39 -9
src/lib/media/manip.ts
··· 1 1 import RNFetchBlob from 'rn-fetch-blob' 2 2 import ImageResizer from '@bam.tech/react-native-image-resizer' 3 - import {Image as RNImage} from 'react-native' 3 + import {Image as RNImage, Share as RNShare} from 'react-native' 4 4 import {Image} from 'react-native-image-crop-picker' 5 - import RNFS from 'react-native-fs' 5 + import * as RNFS from 'react-native-fs' 6 6 import uuid from 'react-native-uuid' 7 7 import * as Sharing from 'expo-sharing' 8 8 import {Dimensions} from './types' 9 9 import {POST_IMG_MAX} from 'lib/constants' 10 - import {isAndroid} from 'platform/detection' 10 + import {isAndroid, isIOS} from 'platform/detection' 11 11 12 12 export async function compressAndResizeImageForPost( 13 13 image: Image, ··· 128 128 fileCache: true, 129 129 }).fetch('GET', uri) 130 130 131 + // NOTE 132 + // assuming PNG 133 + // we're currently relying on the fact our CDN only serves pngs 134 + // -prf 135 + 131 136 let imagePath = downloadResponse.path() 132 - await Sharing.shareAsync(normalizePath(imagePath, true), { 133 - mimeType: 'image/png', 134 - UTI: 'public.png', 135 - }) 137 + imagePath = normalizePath(await moveToPermanentPath(imagePath, '.png'), true) 138 + 139 + // NOTE 140 + // for some reason expo-sharing refuses to work on iOS 141 + // ...and visa versa 142 + // -prf 143 + if (isIOS) { 144 + await RNShare.share({url: imagePath}) 145 + } else { 146 + await Sharing.shareAsync(imagePath, { 147 + mimeType: 'image/png', 148 + UTI: 'image/png', 149 + }) 150 + } 136 151 RNFS.unlink(imagePath) 137 152 } 138 153 ··· 187 202 ) 188 203 } 189 204 190 - async function moveToPermanentPath(path: string): Promise<string> { 205 + async function moveToPermanentPath(path: string, ext = ''): Promise<string> { 191 206 /* 192 207 Since this package stores images in a temp directory, we need to move the file to a permanent location. 193 208 Relevant: IOS bug when trying to open a second time: ··· 195 210 */ 196 211 const filename = uuid.v4() 197 212 198 - const destinationPath = `${RNFS.TemporaryDirectoryPath}/${filename}` 213 + const destinationPath = joinPath( 214 + RNFS.TemporaryDirectoryPath, 215 + `${filename}${ext}`, 216 + ) 199 217 await RNFS.moveFile(path, destinationPath) 200 218 return normalizePath(destinationPath) 219 + } 220 + 221 + function joinPath(a: string, b: string) { 222 + if (a.endsWith('/')) { 223 + if (b.startsWith('/')) { 224 + return a.slice(0, -1) + b 225 + } 226 + return a + b 227 + } else if (b.startsWith('/')) { 228 + return a + b 229 + } 230 + return a + '/' + b 201 231 } 202 232 203 233 function normalizePath(str: string, allPlatforms = false): string {