about summary refs log tree commit diff
path: root/src/lib/media/manip.ts
diff options
context:
space:
mode:
authorPaul Frazee <pfrazee@gmail.com>2023-04-24 16:36:05 -0500
committerGitHub <noreply@github.com>2023-04-24 16:36:05 -0500
commitda8af38dcc23ea33c686714be2ce5f0bf0e65798 (patch)
tree78156a3b5803ccda6883e9e694ca79ccfdc40473 /src/lib/media/manip.ts
parent9d8600c21387999f8621274c553d5385be0c92c7 (diff)
downloadvoidsky-da8af38dcc23ea33c686714be2ce5f0bf0e65798.tar.zst
Android & visual fixes: color themes, repost icon, navigation, back handler, etc (#519)
* Switch android to use slide left/right animations on navigation

* Bump the repost icon down by a pixel

* Tune theme colors for contrast and darker bg on darkmode

* Move back handler to a point in the init flow that leads to more consistent capture of events

* Fix image share flow on android

* Fix lint

* Add todo about sharing not available

* Drop the android slide animation because it's too slow

* Fix 'flashes of white' in dark mode android
Diffstat (limited to 'src/lib/media/manip.ts')
-rw-r--r--src/lib/media/manip.ts25
1 files changed, 12 insertions, 13 deletions
diff --git a/src/lib/media/manip.ts b/src/lib/media/manip.ts
index f77b861e2..3b3ff8c6d 100644
--- a/src/lib/media/manip.ts
+++ b/src/lib/media/manip.ts
@@ -1,10 +1,10 @@
 import RNFetchBlob from 'rn-fetch-blob'
 import ImageResizer from '@bam.tech/react-native-image-resizer'
-import {Image as RNImage, Share} from 'react-native'
+import {Image as RNImage} from 'react-native'
 import {Image} from 'react-native-image-crop-picker'
 import RNFS from 'react-native-fs'
 import uuid from 'react-native-uuid'
-import * as Toast from 'view/com/util/Toast'
+import * as Sharing from 'expo-sharing'
 import {Dimensions} from './types'
 import {POST_IMG_MAX} from 'lib/constants'
 import {isAndroid} from 'platform/detection'
@@ -120,20 +120,19 @@ export async function downloadAndResize(opts: DownloadAndResizeOpts) {
 }
 
 export async function saveImageModal({uri}: {uri: string}) {
+  if (!(await Sharing.isAvailableAsync())) {
+    // TODO might need to give an error to the user in this case -prf
+    return
+  }
   const downloadResponse = await RNFetchBlob.config({
     fileCache: true,
   }).fetch('GET', uri)
 
-  const imagePath = downloadResponse.path()
-  const base64Data = await downloadResponse.readFile('base64')
-  const result = await Share.share({
-    url: 'data:image/png;base64,' + base64Data,
+  let imagePath = downloadResponse.path()
+  await Sharing.shareAsync(normalizePath(imagePath, true), {
+    mimeType: 'image/png',
+    UTI: 'public.png',
   })
-  if (result.action === Share.sharedAction) {
-    Toast.show('Image saved to gallery')
-  } else if (result.action === Share.dismissedAction) {
-    // dismissed
-  }
   RNFS.unlink(imagePath)
 }
 
@@ -201,8 +200,8 @@ async function moveToPermanentPath(path: string): Promise<string> {
   return normalizePath(destinationPath)
 }
 
-function normalizePath(str: string): string {
-  if (isAndroid) {
+function normalizePath(str: string, allPlatforms = false): string {
+  if (isAndroid || allPlatforms) {
     if (!str.startsWith('file://')) {
       return `file://${str}`
     }