ソースを参照

removed expo-media-library

Viktoriia 1 ヶ月 前
コミット
9e43163a5a

+ 0 - 1
package.json

@@ -56,7 +56,6 @@
     "expo-image": "~3.0.8",
     "expo-image-picker": "~17.0.8",
     "expo-location": "~19.0.7",
-    "expo-media-library": "~18.2.0",
     "expo-notifications": "~0.32.12",
     "expo-splash-screen": "~31.0.10",
     "expo-sqlite": "~16.0.8",

+ 0 - 6
src/components/AddPhoto/index.tsx

@@ -35,12 +35,6 @@ const AddPhoto: React.FC<AddPhotoProps> = ({ isModalVisible, initialImagePath, i
   };
 
   const handleImagePick = async () => {
-    const { status } = await ImagePicker.requestMediaLibraryPermissionsAsync();
-    if (status !== 'granted') {
-      Alert.alert('Permission Denied', 'Sorry, we need media library permissions to make this work!');
-      return;
-    }
-
     let result = await ImagePicker.launchImageLibraryAsync({
       mediaTypes: ImagePicker.MediaTypeOptions.Images,
       quality: 1,

+ 11 - 13
src/screens/InAppScreens/MessagesScreen/ChatScreen/index.tsx

@@ -73,7 +73,7 @@ import { dismissChatNotifications, isMessageEdited } from '../utils';
 import { useMessagesStore } from 'src/stores/unreadMessagesStore';
 import FileViewer from 'react-native-file-viewer';
 import * as FileSystem from 'expo-file-system/legacy';
-import * as MediaLibrary from 'expo-media-library';
+import Share from 'react-native-share';
 
 import BanIcon from 'assets/icons/messages/ban.svg';
 import AttachmentsModal from '../Components/AttachmentsModal';
@@ -556,6 +556,7 @@ const ChatScreen = ({ route }: { route: any }) => {
     const fileUrl = currentMessage.video
       ? currentMessage.video
       : API_HOST + currentMessage.attachment?.attachment_full_url;
+
     const fileType = currentMessage.attachment?.filetype || 'application/octet-stream';
     let fileExt = fileType.split('/').pop() || (currentMessage.video ? 'mp4' : 'jpg');
 
@@ -567,22 +568,16 @@ const ChatScreen = ({ route }: { route: any }) => {
     const fileUri = `${FileSystem.cacheDirectory}${fileName}.${fileExt}`;
 
     try {
-      const { status } = await MediaLibrary.requestPermissionsAsync();
-      if (status !== 'granted') {
-        return;
-      }
-
       const downloadOptions = {
         headers: { Nmtoken: token, 'App-Version': APP_VERSION, Platform: Platform.OS }
       };
       const { uri } = await FileSystem.downloadAsync(fileUrl, fileUri, downloadOptions);
 
-      await MediaLibrary.createAssetAsync(uri);
-
-      Alert.alert(
-        'Success',
-        `${fileType.startsWith('video') ? 'Video' : 'Image'} saved to gallery.`
-      );
+      await Share.open({
+        url: uri,
+        type: fileType,
+        failOnCancel: false
+      });
     } catch (error) {
       Alert.alert('Error', 'Failed to download the file.');
     }
@@ -1295,8 +1290,11 @@ const ChatScreen = ({ route }: { route: any }) => {
         setIsModalVisible(false);
         break;
       case 'download':
-        downloadFileToDevice(selectedMessage.currentMessage);
         setIsModalVisible(false);
+
+        setTimeout(() => {
+          downloadFileToDevice(selectedMessage.currentMessage);
+        }, 300);
         break;
       case 'edit':
         handleEditMessage(selectedMessage.currentMessage);

+ 1 - 6
src/screens/InAppScreens/MessagesScreen/Components/AttachmentsModal.tsx

@@ -39,6 +39,7 @@ const AttachmentsModal = () => {
     if (!chatData) return;
 
     setShouldOpenWarningModal({
+      visible: true,
       title: `Report ${chatData.name}`,
       buttonTitle: 'Report',
       message: `Are you sure you want to report ${chatData.name}?\nIf you proceed, the chat history with ${chatData.name} will become visible to NomadMania admins for investigation.`,
@@ -60,12 +61,6 @@ const AttachmentsModal = () => {
     const chatData = chatDataRef.current;
     if (!chatData) return;
     try {
-      const perm = await ImagePicker.requestMediaLibraryPermissionsAsync();
-      if (!perm.granted) {
-        console.warn('Permission for gallery not granted');
-        return;
-      }
-
       const result = await ImagePicker.launchImageLibraryAsync({
         mediaTypes: ImagePicker.MediaTypeOptions.All,
         allowsMultipleSelection: true,

+ 0 - 6
src/screens/InAppScreens/MessagesScreen/Components/ChatOptionsBlock.tsx

@@ -28,12 +28,6 @@ const ChatOptionsBlock: React.FC<Props> = ({
 }) => {
   const handleOpenGallery = useCallback(async () => {
     try {
-      const perm = await ImagePicker.requestMediaLibraryPermissionsAsync();
-      if (!perm.granted) {
-        console.warn('Permission for gallery not granted');
-        return;
-      }
-
       const result = await ImagePicker.launchImageLibraryAsync({
         mediaTypes: ImagePicker.MediaTypeOptions.Images,
         allowsMultipleSelection: true,

+ 10 - 13
src/screens/InAppScreens/MessagesScreen/GroupChatScreen/index.tsx

@@ -81,7 +81,7 @@ import { dismissChatNotifications, isMessageEdited } from '../utils';
 import { useMessagesStore } from 'src/stores/unreadMessagesStore';
 import FileViewer from 'react-native-file-viewer';
 import * as FileSystem from 'expo-file-system/legacy';
-import * as MediaLibrary from 'expo-media-library';
+import Share from 'react-native-share';
 
 import BanIcon from 'assets/icons/messages/ban.svg';
 import AttachmentsModal from '../Components/AttachmentsModal';
@@ -584,23 +584,17 @@ const GroupChatScreen = ({ route }: { route: any }) => {
     const fileUri = `${FileSystem.cacheDirectory}${fileName}.${fileExt}`;
 
     try {
-      const { status } = await MediaLibrary.requestPermissionsAsync();
-      if (status !== 'granted') {
-        return;
-      }
-
       const downloadOptions = {
         headers: { Nmtoken: token, 'App-Version': APP_VERSION, Platform: Platform.OS }
       };
 
       const { uri } = await FileSystem.downloadAsync(fileUrl, fileUri, downloadOptions);
 
-      await MediaLibrary.createAssetAsync(uri);
-
-      Alert.alert(
-        'Success',
-        `${fileType.startsWith('video') ? 'Video' : 'Image'} saved to gallery.`
-      );
+      await Share.open({
+        url: uri,
+        type: fileType,
+        failOnCancel: false
+      });
     } catch (error) {
       Alert.alert('Error', 'Failed to download the file.');
     }
@@ -1381,8 +1375,11 @@ const GroupChatScreen = ({ route }: { route: any }) => {
         setIsModalVisible(false);
         break;
       case 'download':
-        downloadFileToDevice(selectedMessage.currentMessage);
         setIsModalVisible(false);
+
+        setTimeout(() => {
+          downloadFileToDevice(selectedMessage.currentMessage);
+        }, 300);
         break;
       case 'info':
         SheetManager.show('group-status', {

+ 0 - 6
src/screens/InAppScreens/TravelsScreen/EventScreen/index.tsx

@@ -401,12 +401,6 @@ const EventScreen = ({ route }: { route: any }) => {
     if (!event) return;
 
     try {
-      const perm = await ImagePicker.requestMediaLibraryPermissionsAsync();
-      if (!perm.granted) {
-        console.warn('Permission for gallery not granted');
-        return;
-      }
-
       const result = await ImagePicker.launchImageLibraryAsync({
         mediaTypes: ImagePicker.MediaTypeOptions.Images,
         allowsMultipleSelection: true,