dpv007 commited on
Commit
b163d32
·
1 Parent(s): c1aa1f0
Files changed (1) hide show
  1. keystone-app/app/(tabs)/index.tsx +29 -16
keystone-app/app/(tabs)/index.tsx CHANGED
@@ -6,11 +6,11 @@ import {
6
  Dimensions,
7
  TouchableOpacity,
8
  Text,
9
- SafeAreaView,
10
  Alert,
11
  Platform,
12
  ActivityIndicator
13
  } from 'react-native';
 
14
  import * as MediaLibrary from 'expo-media-library';
15
  import { Image } from 'expo-image';
16
  import * as FileSystem from 'expo-file-system';
@@ -35,9 +35,17 @@ type SectionData = {
35
  };
36
 
37
  export default function PhotosScreen() {
38
- const [permissionResponse, requestPermission] = MediaLibrary.usePermissions({
39
- granularPermissions: ['photo', 'video'],
40
- });
 
 
 
 
 
 
 
 
41
  const [sections, setSections] = useState<SectionData[]>([]);
42
  const [allPhotos, setAllPhotos] = useState<MediaLibrary.Asset[]>([]);
43
 
@@ -47,19 +55,24 @@ export default function PhotosScreen() {
47
  const [syncTotal, setSyncTotal] = useState(0);
48
 
49
  useEffect(() => {
50
- if (Platform.OS !== 'web') {
51
- if (!permissionResponse) {
52
- requestPermission();
53
- } else if (permissionResponse.status !== 'granted') {
54
- // Optionally prompt user if they denied it previously
55
- if (permissionResponse.canAskAgain) {
56
- requestPermission();
57
- }
58
- } else {
59
- loadPhotos();
 
 
 
60
  }
61
- }
62
- }, [permissionResponse]);
 
 
63
 
64
  const groupPhotosByDate = (photos: MediaLibrary.Asset[]): SectionData[] => {
65
  const groups: { [key: string]: MediaLibrary.Asset[] } = {};
 
6
  Dimensions,
7
  TouchableOpacity,
8
  Text,
 
9
  Alert,
10
  Platform,
11
  ActivityIndicator
12
  } from 'react-native';
13
+ import { SafeAreaView } from 'react-native-safe-area-context';
14
  import * as MediaLibrary from 'expo-media-library';
15
  import { Image } from 'expo-image';
16
  import * as FileSystem from 'expo-file-system';
 
35
  };
36
 
37
  export default function PhotosScreen() {
38
+ const [permissionResponse, setPermissionResponse] = useState<any>(null);
39
+
40
+ const requestPermission = async () => {
41
+ try {
42
+ const res = await MediaLibrary.requestPermissionsAsync(false, ['photo', 'video']);
43
+ setPermissionResponse(res);
44
+ } catch (err) {
45
+ console.warn('Media Library permission request failed or rejected by host:', err);
46
+ setPermissionResponse({ granted: false, canAskAgain: false });
47
+ }
48
+ };
49
  const [sections, setSections] = useState<SectionData[]>([]);
50
  const [allPhotos, setAllPhotos] = useState<MediaLibrary.Asset[]>([]);
51
 
 
55
  const [syncTotal, setSyncTotal] = useState(0);
56
 
57
  useEffect(() => {
58
+ const checkPermissions = async () => {
59
+ if (Platform.OS === 'web') return;
60
+ try {
61
+ const res = await MediaLibrary.getPermissionsAsync(false, ['photo', 'video']);
62
+ setPermissionResponse(res);
63
+ if (res.granted) {
64
+ loadPhotos();
65
+ } else if (res.canAskAgain) {
66
+ await requestPermission();
67
+ }
68
+ } catch (err) {
69
+ console.warn('Media Library getPermissions failed or rejected by host:', err);
70
+ setPermissionResponse({ granted: false, canAskAgain: false });
71
  }
72
+ };
73
+
74
+ checkPermissions();
75
+ }, []);
76
 
77
  const groupPhotosByDate = (photos: MediaLibrary.Asset[]): SectionData[] => {
78
  const groups: { [key: string]: MediaLibrary.Asset[] } = {};