Simple permission request

This commit is contained in:
Zhiyuan Zheng 2020-12-30 01:33:58 +01:00
parent 3473337442
commit c9726d904f
No known key found for this signature in database
GPG Key ID: 078A93AB607D85E0
3 changed files with 49 additions and 33 deletions

View File

@ -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",

View File

@ -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) {

View File

@ -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,6 +103,23 @@ const addAttachment = async ({ composeDispatch }: Props): Promise<any> => {
},
async buttonIndex => {
if (buttonIndex === 0) {
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
@ -111,7 +128,23 @@ const addAttachment = async ({ composeDispatch }: Props): Promise<any> => {
if (!result.cancelled) {
uploadAttachment(result)
}
}
} else if (buttonIndex === 1) {
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
@ -122,6 +155,7 @@ const addAttachment = async ({ composeDispatch }: Props): Promise<any> => {
}
}
}
}
)
}