Skip to content

Commit 4583701

Browse files
fix(image-picker): skip android permission checks for 11+
Android 11 (API 30)+ doesn't require storage permissions thanks to the system Photo Picker. Add a skip flag to the permission check functions to bypass checks for Android, and update the ImagePicker component to enable this skip automatically for Android platforms.
1 parent 0c37244 commit 4583701

3 files changed

Lines changed: 36 additions & 21 deletions

File tree

‎src/components/core/ImagePicker.tsx‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,10 @@ export function ImagePicker({
104104
selectionLimit: 1,
105105
};
106106

107-
const result = await checkLibrary();
107+
// On Android, we skip permission check, because it's not required (Photo Picker Everywhere)
108+
// Since Android 11(API 30)
109+
const skip = Platform.OS === 'android';
110+
const result = await checkLibrary(skip);
108111
if (result.status === 'granted') {
109112
launchImageLibrary(options, handleImageResponse);
110113
} else {

‎src/modules/core/application/permissions/use-permissions.ts‎

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -42,23 +42,34 @@ export function usePermission(type: PermissionType) {
4242
return result;
4343
}, [type]);
4444

45-
const checkAndRequest = useCallback(async () => {
46-
setIsLoading(true);
47-
const result = await permissionsService.checkAndRequest(type);
48-
setIsLoading(false);
49-
if (result instanceof Error) {
50-
setStatus('unavailable');
51-
setCanAskAgain(false);
52-
return {
53-
type,
54-
status: 'unavailable' as PermissionStatus,
55-
canAskAgain: false,
56-
};
57-
}
58-
setStatus(result.status);
59-
setCanAskAgain(result.canAskAgain);
60-
return result;
61-
}, [type]);
45+
const checkAndRequest = useCallback(
46+
async (skip?: boolean) => {
47+
if (skip) {
48+
return {
49+
type,
50+
status: 'granted' as PermissionStatus,
51+
canAskAgain: false,
52+
};
53+
}
54+
55+
setIsLoading(true);
56+
const result = await permissionsService.checkAndRequest(type);
57+
setIsLoading(false);
58+
if (result instanceof Error) {
59+
setStatus('unavailable');
60+
setCanAskAgain(false);
61+
return {
62+
type,
63+
status: 'unavailable' as PermissionStatus,
64+
canAskAgain: false,
65+
};
66+
}
67+
setStatus(result.status);
68+
setCanAskAgain(result.canAskAgain);
69+
return result;
70+
},
71+
[type],
72+
);
6273

6374
const openSettings = useCallback(async () => {
6475
await permissionsService.openSettings();

‎src/theme/hooks/useFocusFadeIn.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { useCallback, useRef } from 'react';
22
import { Animated } from 'react-native';
33
import { useFocusEffect } from '@react-navigation/native';
44
import { ANIMATION_DURATION } from '../animations';
5+
import { isIOS } from '@theme/responsive';
56

67
interface FocusFadeInConfig {
78
duration?: number;
@@ -14,11 +15,11 @@ export function useFocusFadeIn({
1415
delay = 0,
1516
offset = 20,
1617
}: FocusFadeInConfig = {}) {
17-
const opacity = useRef(new Animated.Value(0)).current;
18-
const translateY = useRef(new Animated.Value(offset)).current;
19-
18+
const opacity = useRef(new Animated.Value(isIOS ? 1 : 0)).current;
19+
const translateY = useRef(new Animated.Value(isIOS ? 0 : offset)).current;
2020
useFocusEffect(
2121
useCallback(() => {
22+
if (isIOS) return;
2223
opacity.setValue(0);
2324
translateY.setValue(offset);
2425

0 commit comments

Comments
 (0)