Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for iOS Image Downloads not going through Photos lib #7849

Merged
merged 48 commits into from
May 4, 2022

Conversation

mananjadhav
Copy link
Collaborator

@mananjadhav mananjadhav commented Feb 21, 2022

Details

  • Adds code to save the images and videos to Photos lib in iOS
  • Adds two dependencies - react-native-cameraroll and react-native-mime-types
  • Little code cleanup for splitting the logic for android and iOS
  • Adds translations for attachment download alerts

Fixed Issues

$ #7307

Tests

  1. Tested download of file, image and video on all platforms
  2. Tested the permissions for iOS. First download popup and subsequent settings redirect
  3. Tested Android downloads to ensure nothing breaks + translations
  • Verify that no errors appear in the JS console

QA Steps

iOS Image

  1. Go to any chat with the image attachment on the iOS native app
  2. Open the attachment preview and click on the Download icon
  3. It should show a success message
  4. Check the attachment is saved in Photos lib for iOS

iOS Video

  1. Go to any chat with the video attachment on the iOS native app
  2. Click on the download icon on the right of the attachment view
  3. It should show a success message
  4. Check the attachment is saved in Photos lib for iOS

iOS Other files

  1. Go to any chat with the doc/zip/other file type attachment on the iOS native app
  2. Click on the download icon on the right of the attachment view
  3. It should show a success message
  4. Check the attachment is saved in the iOS Files app under Expensify directory

Android all files

  1. Go to any chat with any attachment on the Android native app
  2. Click on the download icon on the right of the attachment view for video and other file types. For image, open preview and click on the download button.
  3. It should show a success message
  4. Check the attachment is saved in the Downloads/Expensify directory

Web/MWeb/Desktop

  1. Go to any chat with any attachment on the Web Desktop or Mobile Web
  2. Click on the download icon on the right of the attachment view for video and other file types. For image, open preview and click on the download button.
  3. It should download the file via browser or save on the desktop app
  • Verify that no errors appear in the JS console

Tested On

  • Web
  • Mobile Web
  • Desktop
  • iOS
  • Android

Screenshots

Web

Mobile Web

Desktop

iOS

Screenshot 2022-03-14 at 6 34 28 PM

Screenshot 2022-03-14 at 6 33 10 PM

ios-image-download.mp4

Android

Screenshot 2022-03-14 at 6 44 20 PM

@mananjadhav
Copy link
Collaborator Author

@thienlnam @parasharrajat While I am implementing this with the proposal I mentioned, I am guessing this isn't an issue with Android. I don't have a phone to test.

  1. Should I move my changes to index.ios.js and move the functions of RNFetchBlob to nativeFileDownload like I did for others? and keep index.android.js will just use functions.
  2. I want to check if to identify the type of the file, should we use mime-type or maintain some extension, etc.

@thienlnam
Copy link
Contributor

I am guessing this isn't an issue with Android. I don't have a phone to test.

Yeah I don't think it is, seems like we deal with android permission properly already but can also be checked with an android simulator

Should I move my changes to index.ios.js and move the functions of RNFetchBlob to nativeFileDownload like I did for others? and keep index.android.js will just use functions.

Yeah I would create a seperate file

I want to check if to identify the type of the file, should we use mime-type or maintain some extension, etc.

You can use an external library to determine mime type - we probably won't want to maintain a library for that

@thienlnam
Copy link
Contributor

👋🏽 Hi @mananjadhav is there is any progress here? I'm still looking for an update from the comment I left you #7307 (comment)

If there is no further progress on this issue within the next 24 hours we will be un-assigning this and reopening it back to the pool of other contributors. We'd like to keep working with you on this but we will need some more communication. For more details check step 11 here https://github.com/Expensify/App/blob/main/CONTRIBUTING.md#begin-coding-your-solution-in-a-pull-request

@mananjadhav
Copy link
Collaborator Author

Hey, @thienlnam missed your comment. Sorry. Almost done.

Works fine on Android, iOS images working fine, the issue with videos. I'll finish by today and push by tomorrow for review.

Also it seems I cannot build on iOS device and can only test on simulator.

@thienlnam
Copy link
Contributor

Thanks for the update. That's fine if you can't build on a physical iOS device, simulator testing should suffice

@mananjadhav mananjadhav marked this pull request as ready for review March 14, 2022 13:15
@parasharrajat
Copy link
Member

is this ready @mananjadhav?

@mananjadhav
Copy link
Collaborator Author

Yes ready for review and merge.

Copy link
Member

@parasharrajat parasharrajat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, Video downloading is failing on iOS. When we directly download the attachment from the chat list for the first time you download an attachment. It asks for permission and then the video never downloads.

Steps:

  1. install the app.
  2. Download the video from any chat.
  3. It should ask for permission. Give the permission. Wait to see the download.
  4. Download never completes.

I don't see any Expensify folder in the Files app. I don't know where did the pdf go.

@mananjadhav
Copy link
Collaborator Author

@parasharrajat I am not able to reproduce the video download error. I tried a fresh install with All Allow and Selected Photos both the options. I tried on iPhone 12 and iPhone 8 simulators. I did test a few more cases and it did work fine. Additionally retested the permission rejection case with the second settings popupview.

I also checked the PDF file. For me a new directory, "New Expensify" is created and the PDF is saved in Files -> On My iPhone -> New Expensify path.

Can you test once more from your side?

@parasharrajat
Copy link
Member

Sure, I will do that.

parasharrajat
parasharrajat previously approved these changes Apr 19, 2022
Copy link
Member

@parasharrajat parasharrajat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok Tested it. Everything looking good.

cc: @thienlnam

🎀 👀 🎀 C+ reviewed

Copy link
Contributor

@thienlnam thienlnam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look good, just have a few comments. Going to have the copy double checked

src/CONST.js Show resolved Hide resolved
src/CONST.js Show resolved Hide resolved
src/languages/en.js Outdated Show resolved Hide resolved
Comment on lines +14 to +26
return Promise.all([writePromise, readPromise]).then(([hasWritePermission, hasReadPermission]) => {
if (hasWritePermission && hasReadPermission) {
return true; // Return true if permission is already given
}

// Ask for permission if not given
return PermissionsAndroid.requestMultiple([
PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE,
PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE,
]).then(status => status['android.permission.READ_EXTERNAL_STORAGE'] === 'granted'
&& status['android.permission.WRITE_EXTERNAL_STORAGE'] === 'granted');
});
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if the user has given read permission but not write permission? Does it matter if we request it again?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't tested this. Also considering that this issue was specifically for iOS, in Android I just checked if it doesn't break anything. Do you want me to test this thoroughly for Android as well?

Copy link
Member

@parasharrajat parasharrajat Apr 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

During my testing, Android only ask once for permission which means it combines them together. So if you deny it shows an error. Downloading the file again asks for permission.

src/languages/es.js Outdated Show resolved Hide resolved
Copy link
Contributor

@thienlnam thienlnam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thanks! 🚀

@thienlnam thienlnam merged commit 60690ee into Expensify:main May 4, 2022
@OSBotify
Copy link
Contributor

OSBotify commented May 5, 2022

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@OSBotify
Copy link
Contributor

OSBotify commented May 9, 2022

🚀 Cherry-picked to staging by @sketchydroide in version: 1.1.57-8 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

@Expensify/applauseleads please QA this PR and check it off on the deploy checklist if it passes.

@OSBotify
Copy link
Contributor

🚀 Deployed to production by @chiragsalian in version: 1.1.57-17 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants