Skip to content

Commit 6b32e7b

Browse files
authored
Merge pull request #855 from thundersdata-frontend/rn-issue
fix: 修复授权弹窗的bug
2 parents 8cb2c0d + 5707f68 commit 6b32e7b

File tree

4 files changed

+8
-34
lines changed

4 files changed

+8
-34
lines changed

.changeset/honest-turtles-chew.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@td-design/react-native-image-picker': minor
3+
---
4+
5+
fix: 修复授权弹窗的bug

packages/react-native-image-picker/src/index.tsx

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { forwardRef, useImperativeHandle } from 'react';
2-
import { Image, Rationale, TouchableWithoutFeedback } from 'react-native';
2+
import { Image, TouchableWithoutFeedback } from 'react-native';
33
import { CameraOptions } from 'react-native-image-picker';
44

55
import { ActionSheet, Box, helpers, Indicator, Modal, Pressable, Theme, useTheme } from '@td-design/react-native';
@@ -16,21 +16,6 @@ const cameraOptions: CameraOptions = {
1616
quality: 1,
1717
saveToPhotos: false,
1818
durationLimit: 15,
19-
videoQuality: 'high',
20-
};
21-
const cameraRationaleOptions: Rationale = {
22-
title: '获取摄像头权限',
23-
message: '若不允许,您将无法使用摄像头功能',
24-
buttonPositive: '同意',
25-
buttonNegative: '取消',
26-
buttonNeutral: '下次再说',
27-
};
28-
const libraryRationaleOptions: Rationale = {
29-
title: '获取读取文件权限',
30-
message: '若不允许,您将无法访问图库',
31-
buttonPositive: '同意',
32-
buttonNegative: '取消',
33-
buttonNeutral: '下次再说',
3419
};
3520

3621
const ImagePicker = forwardRef<ImagePickerRef, ImagePickerProps>(
@@ -41,8 +26,6 @@ const ImagePicker = forwardRef<ImagePickerRef, ImagePickerProps>(
4126
height = px(100),
4227
options = cameraOptions,
4328
showUploadImg = true,
44-
cameraRationale = cameraRationaleOptions,
45-
libraryRationale = libraryRationaleOptions,
4629
launchLibraryText = '打开相册',
4730
launchCameraText = '打开摄像头',
4831
previewImgText = '预览图片',
@@ -85,8 +68,6 @@ const ImagePicker = forwardRef<ImagePickerRef, ImagePickerProps>(
8568
onCancel,
8669
onFail,
8770
onGrantFail,
88-
cameraRationale,
89-
libraryRationale,
9071
});
9172

9273
useImperativeHandle(ref, () => ({}));

packages/react-native-image-picker/src/type.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,4 @@ export type HookProps = Pick<
4949
ImagePickerProps,
5050
'value' | 'onBeforeUpload' | 'onUpload' | 'onAfterUpload' | 'onCancel' | 'onFail' | 'onGrantFail'
5151
> &
52-
Required<Pick<ImagePickerProps, 'options' | 'showUploadImg' | 'cameraRationale' | 'libraryRationale'>>;
52+
Required<Pick<ImagePickerProps, 'options' | 'showUploadImg'>>;

packages/react-native-image-picker/src/useImagePicker.ts

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ export default function useImagePicker({
2424
onCancel,
2525
onFail,
2626
onGrantFail,
27-
cameraRationale,
28-
libraryRationale,
2927
}: HookProps) {
3028
/** 打开相册或者摄像头的ActionSheet */
3129
const [launchVisible, { setTrue: setLaunchVisibleTrue, setFalse: setLaunchVisibleFalse }] = useBoolean(false);
@@ -46,24 +44,14 @@ export default function useImagePicker({
4644

4745
/** 打开相册 */
4846
const launchLibrary = async () => {
49-
if (Platform.OS === 'android') {
50-
const result = await PermissionsAndroid.request(
51-
PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE,
52-
libraryRationale
53-
);
54-
if (result !== 'granted') {
55-
onGrantFail?.();
56-
return;
57-
}
58-
}
5947
const response = await launchImageLibrary(options);
6048
handleCallback(response);
6149
};
6250

6351
/** 打开摄像头 */
6452
const launchCamera = async () => {
6553
if (Platform.OS === 'android') {
66-
const result = await PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.CAMERA, cameraRationale);
54+
const result = await PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.CAMERA);
6755
if (result !== 'granted') {
6856
onGrantFail?.();
6957
return;

0 commit comments

Comments
 (0)