From 1e232d5259ab8aa71e7d6eae193f90161ad24549 Mon Sep 17 00:00:00 2001 From: Roland Osborne Date: Sat, 22 Apr 2023 17:40:04 -0700 Subject: [PATCH] fixing uri scheme for sharing images --- .../android/app/src/main/AndroidManifest.xml | 1 + .../src/session/conversation/addTopic/AddTopic.jsx | 9 ++++----- .../conversation/addTopic/useAddTopic.hook.js | 14 +++++++++----- .../session/sharing/sharingItem/SharingItem.jsx | 3 +-- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/app/mobile/android/app/src/main/AndroidManifest.xml b/app/mobile/android/app/src/main/AndroidManifest.xml index ce584331..77235871 100644 --- a/app/mobile/android/app/src/main/AndroidManifest.xml +++ b/app/mobile/android/app/src/main/AndroidManifest.xml @@ -15,6 +15,7 @@ + { if (shareIntent) { - Alert.alert('SHARING', JSON.stringify(shareIntent)); shareIntent.forEach(share => { if (share.text) { actions.setMessage(share.text); @@ -27,14 +26,14 @@ export function AddTopic({ contentKey, shareIntent, setShareIntent }) { if (share.weblink) { actions.setMessage(share.weblink); } - const mimeType = share.mimeType?.toLowerCase(); - if (mimeType === '.jpg' || mimeType === '.png') { + const mime = share.mimeType?.toLowerCase(); + if (mime === '.jpg' || mime === '.png' || mime === 'image/jpeg' || mime == 'image/png' ) { actions.addImage(share.filePath) } - if (mimeType === '.mp4') { + if (mime === '.mp4' || mime === 'video/mp4' || mime == 'video/mpeg') { actions.addVideo(share.filePath) } - if (mimeType === '.mp3') { + if (mime === '.mp3') { actions.addAudio(share.filePath) } }); diff --git a/app/mobile/src/session/conversation/addTopic/useAddTopic.hook.js b/app/mobile/src/session/conversation/addTopic/useAddTopic.hook.js index 2763e0ff..6e783f6b 100644 --- a/app/mobile/src/session/conversation/addTopic/useAddTopic.hook.js +++ b/app/mobile/src/session/conversation/addTopic/useAddTopic.hook.js @@ -85,20 +85,24 @@ export function useAddTopic(contentKey) { updateState({ message }); }, addImage: (data) => { + const url = data.startsWith('file:') ? data : 'file://' + data; + assetId.current++; - Image.getSize(data, (width, height) => { - const asset = { key: assetId.current, type: 'image', data: data, ratio: width/height }; + Image.getSize(url, (width, height) => { + const asset = { key: assetId.current, type: 'image', data: url, ratio: width/height }; updateState({ assets: [ ...state.assets, asset ] }); - }); + }) }, addVideo: (data) => { + const url = data.startsWith('file:') ? data : 'file://' + data assetId.current++; - const asset = { key: assetId.current, type: 'video', data: data, ratio: 1, duration: 0, position: 0 }; + const asset = { key: assetId.current, type: 'video', data: url, ratio: 1, duration: 0, position: 0 }; updateState({ assets: [ ...state.assets, asset ] }); }, addAudio: (data, label) => { + const url = data.startsWith('file:') ? data : 'file://' + data assetId.current++; - const asset = { key: assetId.current, type: 'audio', data: data, label }; + const asset = { key: assetId.current, type: 'audio', data: url, label }; updateState({ assets: [ ...state.assets, asset ] }); }, setVideoPosition: (key, position) => { diff --git a/app/mobile/src/session/sharing/sharingItem/SharingItem.jsx b/app/mobile/src/session/sharing/sharingItem/SharingItem.jsx index b8f4aefe..0dad879f 100644 --- a/app/mobile/src/session/sharing/sharingItem/SharingItem.jsx +++ b/app/mobile/src/session/sharing/sharingItem/SharingItem.jsx @@ -1,5 +1,4 @@ -import { Text, View } from 'react-native'; -import { TouchableOpacity } from 'react-native-gesture-handler'; +import { TouchableOpacity, Alert, Text, View } from 'react-native'; import { Logo } from 'utils/Logo'; import { styles } from './SharingItem.styled'; import Colors from 'constants/Colors';