diff --git a/package.json b/package.json index f635415f..0c4fa422 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,6 @@ "expo-linear-gradient": "~8.4.0", "expo-linking": "~2.0.0", "expo-localization": "~9.1.0", - "expo-permissions": "~10.0.0", "expo-random": "~10.0.0", "expo-secure-store": "~9.3.0", "expo-splash-screen": "~0.8.1", diff --git a/src/screens/Shared/Compose/Root.tsx b/src/screens/Shared/Compose/Root.tsx index f38c7d73..ca294e74 100644 --- a/src/screens/Shared/Compose/Root.tsx +++ b/src/screens/Shared/Compose/Root.tsx @@ -1,9 +1,5 @@ import Emojis from '@components/Timelines/Timeline/Shared/Emojis' -import { - ComposeAction, - ComposeState, - ComposeContext -} from '@screens/Shared/Compose' +import { ComposeContext } from '@screens/Shared/Compose' import ComposeActions from '@screens/Shared/Compose/Actions' import ComposeRootFooter from '@screens/Shared/Compose/Root/Footer' import ComposeRootHeader from '@screens/Shared/Compose/Root/Header' @@ -31,6 +27,7 @@ import { } from 'react-native' import { Chase } from 'react-native-animated-spinkit' import { useQuery } from 'react-query' +import { ComposeAction, ComposeState } from './utils/types' const ListItem = React.memo( ({ @@ -125,20 +122,6 @@ const ComposeRoot: React.FC = () => { } }, [composeState.tag?.text]) - useEffect(() => { - ;(async () => { - Permissions.askAsync(Permissions.CAMERA) - // const permissionGaleery = await ImagePicker.requestCameraRollPermissionsAsync() - // if (permissionGaleery.status !== 'granted') { - // alert('Sorry, we need camera roll permissions to make this work!') - // } - // const permissionCamera = await ImagePicker.requestCameraPermissionsAsync() - // if (permissionCamera.status !== 'granted') { - // alert('Sorry, we need camera roll permissions to make this work!') - // } - })() - }, []) - const { data: emojisData } = useQuery(['Emojis'], emojisFetch) useEffect(() => { if (emojisData && emojisData.length) { diff --git a/src/screens/Shared/Compose/addAttachment.ts b/src/screens/Shared/Compose/addAttachment.ts index cc22c61d..4954b7ed 100644 --- a/src/screens/Shared/Compose/addAttachment.ts +++ b/src/screens/Shared/Compose/addAttachment.ts @@ -3,7 +3,7 @@ import * as ImagePicker from 'expo-image-picker' import { ImageInfo } from 'expo-image-picker/build/ImagePicker.types' import * as VideoThumbnails from 'expo-video-thumbnails' import { Dispatch } from 'react' -import { ActionSheetIOS, Alert } from 'react-native' +import { ActionSheetIOS, Alert, Linking } from 'react-native' import { ComposeAction } from './utils/types' export interface Props { @@ -103,22 +103,56 @@ const addAttachment = async ({ composeDispatch }: Props): Promise => { }, async buttonIndex => { if (buttonIndex === 0) { - const result = await ImagePicker.launchImageLibraryAsync({ - mediaTypes: ImagePicker.MediaTypeOptions.All, - exif: false - }) + const { + status + } = await ImagePicker.requestMediaLibraryPermissionsAsync() + if (status !== 'granted') { + Alert.alert('🈚️读取权限', '需要相片权限才能上传照片', [ + { + text: '取消', + style: 'cancel', + onPress: () => {} + }, + { + text: '去系统设置', + style: 'default', + onPress: () => Linking.openURL('app-settings:') + } + ]) + } else { + const result = await ImagePicker.launchImageLibraryAsync({ + mediaTypes: ImagePicker.MediaTypeOptions.All, + exif: false + }) - if (!result.cancelled) { - uploadAttachment(result) + if (!result.cancelled) { + uploadAttachment(result) + } } } else if (buttonIndex === 1) { - const result = await ImagePicker.launchCameraAsync({ - mediaTypes: ImagePicker.MediaTypeOptions.All, - exif: false - }) + const { status } = await ImagePicker.requestCameraPermissionsAsync() + if (status !== 'granted') { + Alert.alert('🈚️读取权限', '需要相机权限才能上传照片', [ + { + text: '取消', + style: 'cancel', + onPress: () => {} + }, + { + text: '去系统设置', + style: 'default', + onPress: () => Linking.openURL('app-settings:') + } + ]) + } else { + const result = await ImagePicker.launchCameraAsync({ + mediaTypes: ImagePicker.MediaTypeOptions.All, + exif: false + }) - if (!result.cancelled) { - uploadAttachment(result) + if (!result.cancelled) { + uploadAttachment(result) + } } } }