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,
|
| 39 |
-
|
| 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 |
-
|
| 51 |
-
if (
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
|
|
|
|
|
|
|
|
|
| 60 |
}
|
| 61 |
-
}
|
| 62 |
-
|
|
|
|
|
|
|
| 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[] } = {};
|