mirror of
				https://github.com/tooot-app/app
				synced 2025-06-05 22:19:13 +02:00 
			
		
		
		
	Android sharing working
This commit is contained in:
		| @@ -31,12 +31,30 @@ | |||||||
|         <data android:scheme="tooot"/> |         <data android:scheme="tooot"/> | ||||||
|         <data android:scheme="com.xmflsct.app.tooot"/> |         <data android:scheme="com.xmflsct.app.tooot"/> | ||||||
|       </intent-filter> |       </intent-filter> | ||||||
|  |       <intent-filter> | ||||||
|  |         <action android:name="android.intent.action.SEND_MULTIPLE" /> | ||||||
|  |         <category android:name="android.intent.category.DEFAULT" /> | ||||||
|  |         <data android:mimeType="image/*" /> | ||||||
|  |       </intent-filter> | ||||||
|  |       <intent-filter> | ||||||
|  |         <action android:name="android.intent.action.SEND_MULTIPLE" /> | ||||||
|  |         <category android:name="android.intent.category.DEFAULT" /> | ||||||
|  |         <data android:mimeType="text/plain" /> | ||||||
|  |       </intent-filter> | ||||||
|       <intent-filter> |       <intent-filter> | ||||||
|         <action android:name="android.intent.action.SEND" /> |         <action android:name="android.intent.action.SEND" /> | ||||||
|         <category android:name="android.intent.category.DEFAULT" /> |         <category android:name="android.intent.category.DEFAULT" /> | ||||||
|         <data android:mimeType="text/plain" /> |         <data android:mimeType="text/plain" /> | ||||||
|  |       </intent-filter> | ||||||
|  |       <intent-filter> | ||||||
|  |         <action android:name="android.intent.action.SEND" /> | ||||||
|  |         <category android:name="android.intent.category.DEFAULT" /> | ||||||
|         <data android:mimeType="image/*" /> |         <data android:mimeType="image/*" /> | ||||||
|         <!-- Any other mime types you want to support --> |       </intent-filter> | ||||||
|  |       <intent-filter> | ||||||
|  |         <action android:name="android.intent.action.SEND" /> | ||||||
|  |         <category android:name="android.intent.category.DEFAULT" /> | ||||||
|  |         <data android:mimeType="video/*"/> | ||||||
|       </intent-filter> |       </intent-filter> | ||||||
|     </activity> |     </activity> | ||||||
|   </application> |   </application> | ||||||
|   | |||||||
| @@ -1,18 +1,22 @@ | |||||||
| diff --git a/node_modules/@types/react-native-share-menu/index.d.ts b/node_modules/@types/react-native-share-menu/index.d.ts | diff --git a/node_modules/@types/react-native-share-menu/index.d.ts b/node_modules/@types/react-native-share-menu/index.d.ts | ||||||
| index f52822c..b1d3bdd 100755 | index f52822c..ee98565 100755 | ||||||
| --- a/node_modules/@types/react-native-share-menu/index.d.ts | --- a/node_modules/@types/react-native-share-menu/index.d.ts | ||||||
| +++ b/node_modules/@types/react-native-share-menu/index.d.ts | +++ b/node_modules/@types/react-native-share-menu/index.d.ts | ||||||
| @@ -6,9 +6,7 @@ | @@ -5,11 +5,9 @@ | ||||||
|  |  // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped | ||||||
|  // Minimum TypeScript Version: 3.7 |  // Minimum TypeScript Version: 3.7 | ||||||
|   |   | ||||||
|  export interface ShareData { | -export interface ShareData { | ||||||
| -    mimeType: string; | -    mimeType: string; | ||||||
| -    data: string | string[]; | -    data: string | string[]; | ||||||
| -    extraData?: object | undefined; | -    extraData?: object | undefined; | ||||||
|  | -} | ||||||
|  | +export type ShareData = { | ||||||
| +    data: {mimeType: string; data: string}[]; | +    data: {mimeType: string; data: string}[]; | ||||||
|  } | +} | {mimeType: string; data: string | string[]} | ||||||
|   |   | ||||||
|  export type ShareCallback = (share?: ShareData) => void; |  export type ShareCallback = (share?: ShareData) => void; | ||||||
|  |   | ||||||
| @@ -28,7 +26,7 @@ interface ShareMenuReactView { | @@ -28,7 +26,7 @@ interface ShareMenuReactView { | ||||||
|      dismissExtension(error?: string): void; |      dismissExtension(error?: string): void; | ||||||
|      openApp(): void; |      openApp(): void; | ||||||
|   | |||||||
| @@ -161,32 +161,51 @@ const Screens: React.FC<Props> = ({ localCorrupt }) => { | |||||||
|  |  | ||||||
|   // Share Extension |   // Share Extension | ||||||
|   const handleShare = useCallback( |   const handleShare = useCallback( | ||||||
|     (item?: { data?: { mimeType: string; data: string }[] }) => { |     ( | ||||||
|  |       item?: | ||||||
|  |         | { | ||||||
|  |             data: { mimeType: string; data: string }[] | ||||||
|  |             mimeType: undefined | ||||||
|  |           } | ||||||
|  |         | { data: string | string[]; mimeType: string } | ||||||
|  |     ) => { | ||||||
|       if (instanceActive < 0) { |       if (instanceActive < 0) { | ||||||
|         return |         return | ||||||
|       } |       } | ||||||
|       if (!item || !item.data || !Array.isArray(item.data) || !item.data) { |       if (!item || !item.data) { | ||||||
|         return |         return | ||||||
|       } |       } | ||||||
|  |  | ||||||
|       let text: string | undefined = undefined |       let text: string | undefined = undefined | ||||||
|       let images: { type: string; uri: string }[] = [] |       let images: { type: string; uri: string }[] = [] | ||||||
|       let video: { type: string; uri: string } | undefined = undefined |       let video: { type: string; uri: string } | undefined = undefined | ||||||
|       item.data.forEach((d, i) => { |  | ||||||
|  |       switch (Platform.OS) { | ||||||
|  |         case 'ios': | ||||||
|  |           if (!Array.isArray(item.data) || !item.data) { | ||||||
|  |             return | ||||||
|  |           } | ||||||
|  |  | ||||||
|  |           item.data.forEach(d => { | ||||||
|  |             if (typeof d === 'string') return | ||||||
|             const typesImage = ['png', 'jpg', 'jpeg', 'gif'] |             const typesImage = ['png', 'jpg', 'jpeg', 'gif'] | ||||||
|             const typesVideo = ['mp4', 'm4v', 'mov', 'webm'] |             const typesVideo = ['mp4', 'm4v', 'mov', 'webm'] | ||||||
|             const { mimeType, data } = d |             const { mimeType, data } = d | ||||||
|         console.log('mimeType', mimeType) |  | ||||||
|         console.log('data', data) |  | ||||||
|             if (mimeType.startsWith('image/')) { |             if (mimeType.startsWith('image/')) { | ||||||
|               if (!typesImage.includes(mimeType.split('/')[1])) { |               if (!typesImage.includes(mimeType.split('/')[1])) { | ||||||
|             console.warn('Image type not supported:', mimeType.split('/')[1]) |                 console.warn( | ||||||
|  |                   'Image type not supported:', | ||||||
|  |                   mimeType.split('/')[1] | ||||||
|  |                 ) | ||||||
|                 return |                 return | ||||||
|               } |               } | ||||||
|               images.push({ type: mimeType.split('/')[1], uri: data }) |               images.push({ type: mimeType.split('/')[1], uri: data }) | ||||||
|             } else if (mimeType.startsWith('video/')) { |             } else if (mimeType.startsWith('video/')) { | ||||||
|               if (!typesVideo.includes(mimeType.split('/')[1])) { |               if (!typesVideo.includes(mimeType.split('/')[1])) { | ||||||
|             console.warn('Video type not supported:', mimeType.split('/')[1]) |                 console.warn( | ||||||
|  |                   'Video type not supported:', | ||||||
|  |                   mimeType.split('/')[1] | ||||||
|  |                 ) | ||||||
|                 return |                 return | ||||||
|               } |               } | ||||||
|               video = { type: mimeType.split('/')[1], uri: data } |               video = { type: mimeType.split('/')[1], uri: data } | ||||||
| @@ -202,20 +221,71 @@ const Screens: React.FC<Props> = ({ localCorrupt }) => { | |||||||
|               text = !text ? data : text.concat(text, `\n${data}`) |               text = !text ? data : text.concat(text, `\n${data}`) | ||||||
|             } |             } | ||||||
|           }) |           }) | ||||||
|  |           break | ||||||
|  |         case 'android': | ||||||
|  |           if (!item.mimeType) { | ||||||
|  |             return | ||||||
|  |           } | ||||||
|  |           let tempData: string[] | ||||||
|  |           if (!Array.isArray(item.data)) { | ||||||
|  |             tempData = [item.data] | ||||||
|  |           } else { | ||||||
|  |             tempData = item.data | ||||||
|  |           } | ||||||
|  |           tempData.forEach(d => { | ||||||
|  |             const typesImage = ['png', 'jpg', 'jpeg', 'gif'] | ||||||
|  |             const typesVideo = ['mp4', 'm4v', 'mov', 'webm', 'mpeg'] | ||||||
|  |             if (item.mimeType!.startsWith('image/')) { | ||||||
|  |               if (!typesImage.includes(item.mimeType.split('/')[1])) { | ||||||
|  |                 console.warn( | ||||||
|  |                   'Image type not supported:', | ||||||
|  |                   item.mimeType.split('/')[1] | ||||||
|  |                 ) | ||||||
|  |                 return | ||||||
|  |               } | ||||||
|  |               images.push({ type: item.mimeType.split('/')[1], uri: d }) | ||||||
|  |             } else if (item.mimeType.startsWith('video/')) { | ||||||
|  |               if (!typesVideo.includes(item.mimeType.split('/')[1])) { | ||||||
|  |                 console.warn( | ||||||
|  |                   'Video type not supported:', | ||||||
|  |                   item.mimeType.split('/')[1] | ||||||
|  |                 ) | ||||||
|  |                 return | ||||||
|  |               } | ||||||
|  |               video = { type: item.mimeType.split('/')[1], uri: d } | ||||||
|  |             } else { | ||||||
|  |               if (typesImage.includes(d.split('.').pop() || '')) { | ||||||
|  |                 images.push({ type: d.split('.').pop()!, uri: d }) | ||||||
|  |                 return | ||||||
|  |               } | ||||||
|  |               if (typesVideo.includes(d.split('.').pop() || '')) { | ||||||
|  |                 video = { type: d.split('.').pop()!, uri: d } | ||||||
|  |                 return | ||||||
|  |               } | ||||||
|  |               text = !text ? d : text.concat(text, `\n${d}`) | ||||||
|  |             } | ||||||
|  |           }) | ||||||
|  |           break | ||||||
|  |       } | ||||||
|  |  | ||||||
|  |       if (!text && (!images || !images.length) && !video) { | ||||||
|  |         return | ||||||
|  |       } else { | ||||||
|         navigationRef.navigate('Screen-Compose', { |         navigationRef.navigate('Screen-Compose', { | ||||||
|           type: 'share', |           type: 'share', | ||||||
|           text, |           text, | ||||||
|           images, |           images, | ||||||
|           video |           video | ||||||
|         }) |         }) | ||||||
|  |       } | ||||||
|     }, |     }, | ||||||
|     [instanceActive] |     [instanceActive] | ||||||
|   ) |   ) | ||||||
|   useEffect(() => { |   useEffect(() => { | ||||||
|     ShareMenu.getInitialShare(item => handleShare(item)) |     ShareMenu.getInitialShare(handleShare) | ||||||
|   }, []) |   }, []) | ||||||
|   useEffect(() => { |   useEffect(() => { | ||||||
|     const listener = ShareMenu.addNewShareListener(item => handleShare(item)) |     const listener = ShareMenu.addNewShareListener(handleShare) | ||||||
|     return () => { |     return () => { | ||||||
|       listener.remove() |       listener.remove() | ||||||
|     } |     } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user