mirror of
https://github.com/tooot-app/app
synced 2025-06-05 22:19:13 +02:00
Get back to the tutorial
This commit is contained in:
@ -161,25 +161,18 @@ const Screens: React.FC<Props> = ({ localCorrupt }) => {
|
||||
|
||||
// Share Extension
|
||||
const handleShare = useCallback(
|
||||
(item?: {
|
||||
extraData?: { share: { mimeType: string; data: string }[] }
|
||||
}) => {
|
||||
(item?: { data?: { mimeType: string; data: string }[] }) => {
|
||||
if (instanceActive < 0) {
|
||||
return
|
||||
}
|
||||
if (
|
||||
!item ||
|
||||
!item.extraData ||
|
||||
!Array.isArray(item.extraData.share) ||
|
||||
!item.extraData.share.length
|
||||
) {
|
||||
if (!item || !item.data || !Array.isArray(item.data) || !item.data) {
|
||||
return
|
||||
}
|
||||
|
||||
let text: string | undefined = undefined
|
||||
let images: { type: string; uri: string }[] = []
|
||||
let video: { type: string; uri: string } | undefined = undefined
|
||||
item.extraData.share.forEach((d, i) => {
|
||||
item.data.forEach((d, i) => {
|
||||
const typesImage = ['png', 'jpg', 'jpeg', 'gif']
|
||||
const typesVideo = ['mp4', 'm4v', 'mov', 'webm']
|
||||
const { mimeType, data } = d
|
||||
@ -219,12 +212,10 @@ const Screens: React.FC<Props> = ({ localCorrupt }) => {
|
||||
[instanceActive]
|
||||
)
|
||||
useEffect(() => {
|
||||
console.log('getting intial share')
|
||||
ShareMenu.getInitialShare(handleShare)
|
||||
ShareMenu.getInitialShare(item => handleShare(item))
|
||||
}, [])
|
||||
useEffect(() => {
|
||||
console.log('getting just share')
|
||||
const listener = ShareMenu.addNewShareListener(handleShare)
|
||||
const listener = ShareMenu.addNewShareListener(item => handleShare(item))
|
||||
return () => {
|
||||
listener.remove()
|
||||
}
|
||||
|
@ -1,9 +1,7 @@
|
||||
import { useEffect, useState } from 'react'
|
||||
import { Appearance, Platform, Pressable, Text } from 'react-native'
|
||||
import { useEffect } from 'react'
|
||||
import { Appearance, Pressable } from 'react-native'
|
||||
import { Circle } from 'react-native-animated-spinkit'
|
||||
import RNFS from 'react-native-fs'
|
||||
import { ShareMenuReactView } from 'react-native-share-menu'
|
||||
import uuid from 'react-native-uuid'
|
||||
|
||||
// mimeType
|
||||
// text/plain - text only, website URL, video?!
|
||||
@ -21,58 +19,9 @@ const colors = {
|
||||
}
|
||||
}
|
||||
|
||||
const clearDir = async (dir: string) => {
|
||||
try {
|
||||
const files = await RNFS.readDir(dir)
|
||||
for (const file of files) {
|
||||
await RNFS.unlink(file.path)
|
||||
}
|
||||
} catch (err: any) {
|
||||
console.warn(err.message)
|
||||
}
|
||||
}
|
||||
|
||||
const ShareExtension = () => {
|
||||
const [errorMessage, setErrorMessage] = useState<string>()
|
||||
|
||||
useEffect(() => {
|
||||
ShareMenuReactView.data().then(async ({ data }) => {
|
||||
console.log('length', data.length)
|
||||
const newData = []
|
||||
switch (Platform.OS) {
|
||||
case 'ios':
|
||||
for (const d of data) {
|
||||
if (d.data.startsWith('file:///')) {
|
||||
const extension = d.data.split('.').pop()?.toLowerCase()
|
||||
const filename = `${uuid.v4()}.${extension}`
|
||||
const groupDirectory = await RNFS.pathForGroup(
|
||||
'group.com.xmflsct.app.tooot'
|
||||
)
|
||||
await clearDir(groupDirectory)
|
||||
const newFilepath = `file://${groupDirectory}/${filename}`
|
||||
console.log('newFilepath', newFilepath)
|
||||
try {
|
||||
await RNFS.copyFile(d.data, newFilepath)
|
||||
newData.push({ ...d, data: newFilepath })
|
||||
} catch (err: any) {
|
||||
setErrorMessage(err.message)
|
||||
console.warn(err.message)
|
||||
}
|
||||
} else {
|
||||
newData.push(d)
|
||||
}
|
||||
}
|
||||
break
|
||||
case 'android':
|
||||
break
|
||||
default:
|
||||
return
|
||||
}
|
||||
console.log('new data', newData)
|
||||
if (!errorMessage) {
|
||||
ShareMenuReactView.continueInApp({ share: newData })
|
||||
}
|
||||
})
|
||||
ShareMenuReactView.continueInApp()
|
||||
}, [])
|
||||
|
||||
const theme = Appearance.getColorScheme() || 'light'
|
||||
@ -85,19 +34,8 @@ const ShareExtension = () => {
|
||||
alignItems: 'center',
|
||||
backgroundColor: colors.background[theme]
|
||||
}}
|
||||
onPress={() => {
|
||||
if (errorMessage) {
|
||||
ShareMenuReactView.dismissExtension(errorMessage)
|
||||
}
|
||||
}}
|
||||
>
|
||||
{!errorMessage ? (
|
||||
<Text style={{ fontSize: 16, color: colors.primary[theme] }}>
|
||||
{errorMessage}
|
||||
</Text>
|
||||
) : (
|
||||
<Circle size={18} color={colors.primary[theme]} />
|
||||
)}
|
||||
<Circle size={18} color={colors.primary[theme]} />
|
||||
</Pressable>
|
||||
)
|
||||
}
|
||||
|
Reference in New Issue
Block a user