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: Modal closes immediately after launch #2114

Merged
merged 23 commits into from
Apr 6, 2021

Conversation

kidroca
Copy link
Contributor

@kidroca kidroca commented Mar 26, 2021

Details

Converts the existing Attachment Picker implementation to a bottom docked modal. There's a sample video in the iOS section

Notable changes:

  • AttachmentPicker: Since this is a multi index component - to keep props interface uniform it was extracted to separate file
  • Converted native AttachmentPicker to a class based component, preserving existing render prop interface
  • Removed logic that causes a side effect that closes the attachment options modal
  • Added error handling to let the user know when image picking fails for reasons other than permissions instead of leaving him guessing
  • The wrapped calls to RNImage picker with promises to keep a uniform and easy to follow interface

Fixed Issues

Fixes #1913 also fixes #2198

Tests

For web, mWeb and Desktop

Found a bug related to Safari, please use another browser to test (Chrome works): #2109

  1. Open a chat
  2. Press the (+) plus button to open the input menu
  3. Select "Add Attachment"
  4. The browser's file picker should open and you can select a file
  5. When you select a file you should see File Preview modal
  6. Pressing upload should upload the file and you should see the attachment/thumb inside the chat
  7. Upon the File Preview closes (previous step) focus should be returned to the compose input field

iOS/Android

  1. Open a chat
  2. Press the (+) plus button to open the input menu
  3. Select "Add Attachment"
  4. A second modal should open and show options for: camera, gallery, document
  • Selecting "Take Photo"
    • default flow: You shoot a photo, select "Use Photo" and continue to the next step (File Preview)
    • other cases:
      • pressing "Cancel" (inside the camera) closes any modals and returns you to the "Chat".
      • not granting permission should display a helpful Alert message
      • other errors should display a general error message to let the user know something did go right. You can verify this by selecting "Take Photo" on a iOS simulator - you should see a message that taking photos on a simulator is not supported
  • Selecting "Choose from Gallery"
    • default flow: You select a photo from the gallery and continue to the next step (File Preview)
    • other cases:
      • pressing "Cancel" (inside the gallery) closes any modals and returns you to the "Chat".
      • there's error handling that should alert the user in case of an error but I don't know a way to trigger it. I tested it by manually forcing code execution through that flow
  • Selecting "Choose Document"
    • default flow: You select a document and continue to the next step (File Preview)
    • other cases: Same as in "Choose from Gallery"
  1. File Preview
  • At this point you should see a preview of whatever was selected using the previous options
  • Pressing "Upload" should upload the file and you should see the attachment/thumb inside the chat
  • Pressing (x) close on the top right corner should close the preview and not upload anything
  • Upon the File Preview closes focus should be returned to the compose input field

Regarding field input focusing

  • the field is no longer focused when any modal closes
  • the field would autofocus at the end of the full attachment flow

QA Steps

Same as above

Note that the video sample is using the iOS simulator with the software keyboard toggled on:
#2114 (comment)

Tested On

  • Web
  • Mobile Web
  • Desktop
  • iOS
  • Android

Screenshots

Web

image

Mobile Web

image

Desktop

image

iOS (Video)

2021-03-29.13-56-42.mp4

Android

image

@kidroca kidroca requested a review from a team as a code owner March 26, 2021 19:32
@github-actions
Copy link
Contributor

github-actions bot commented Mar 26, 2021

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

@botify botify requested review from NikkiWines and removed request for a team March 26, 2021 19:33
@kidroca
Copy link
Contributor Author

kidroca commented Mar 26, 2021

I have read the CLA Document and I hereby sign the CLA

@kidroca
Copy link
Contributor Author

kidroca commented Mar 26, 2021

recheck

@kidroca kidroca force-pushed the kidroca/attachment-modal-update branch 3 times, most recently from 5ea8508 to 8820d75 Compare March 29, 2021 10:51
@NikkiWines
Copy link
Contributor

NikkiWines commented Mar 30, 2021

going to also add @Julesssss here as a reviewer since he's got context to for issue and proposed solution. Ran out of time to get to this today but will review it first thing tomorrow.

@NikkiWines NikkiWines requested a review from Julesssss March 30, 2021 00:58
@Julesssss
Copy link
Contributor

the field is no longer focused when any modal closes

This is a regression for Web & Desktop. We need to regain focus when the attachment picker closes (not for mobile though)

Also, it looks like we're not closing the AttachmentPicker menu when on item is selected, can we do this? IMO it's odd mobile UX to see the prior modal when cancelling from the gallery (for example) -- I would expect the modal to close as the gallery/camera/picker is launched

@Julesssss
Copy link
Contributor

Julesssss commented Mar 30, 2021

It tested well on Web and mobile, but mobile web (iOS) didn't work for me. I see the AttachmentModal, but tapping Add Attachment does nothing. -- nevermind, just realised this is the same safari issue you'll fix elsewhere!

I also would expect the options here to match mobile?

@kidroca
Copy link
Contributor Author

kidroca commented Mar 30, 2021

This is a regression for Web & Desktop. We need to regain focus when the attachment picker closes (not for mobile though)

I've also brought this up here: #2129 (comment)
Autofocus should be handled differently on mobile vs web/desktop but I don't think this can be address by the current PR

Also, it looks like we're not closing the AttachmentPicker menu when on item is selected, can we do this? IMO it's odd mobile UX to see the prior modal when cancelling from the gallery (for example) -- I would expect the modal to close as the gallery/camera/picker is launched

I wasn't sure about this, I can update it to close. My logic was that if I selected gallery by mistake I can press "Cancel" and return to select something else like documents

@kidroca
Copy link
Contributor Author

kidroca commented Mar 30, 2021

I also would expect the options here to match mobile?

I don't think the options would match on mWeb, it would use the web component with the hidden input - that would bring whatever file picker the browser would display to you.

Something like this:
image

It's not even possible to test it right now as this issue is also affecting mobile Chrome: #2109:
image

It might present something like this:
image

Depending on what the <input accept="..." /> is set to

This is well documented here: https://developers.google.com/web/fundamentals/media/capturing-images
I'll make sure it works in #2109

@kidroca
Copy link
Contributor Author

kidroca commented Mar 30, 2021

Updated

  • reverted changes regarding "This is a regression for Web & Desktop."
  • this also closes the 2nd modal when "Cancel" is picked inside the gallery/camera

@Julesssss
Copy link
Contributor

Autofocus should be handled differently on mobile vs web/desktop but I don't think this can be address by the current PR.

Yeah, no problem. I just mentioned it in case it simplified things, clearly not :D

@kidroca
Copy link
Contributor Author

kidroca commented Mar 30, 2021

Updated

Included a fix for Android camera permissions - it appears on android the response.error is different and was not covered by the switch (and the original logic)
image

Still needs a designer touch as the message is used as title.
Maybe something like:

Alert.alert(
  'Expensify.cash does not have access to your camera', // Title
  'Please enable the permission and try again.', // Message
  [...]
)

Copy link
Contributor

@NikkiWines NikkiWines left a comment

Choose a reason for hiding this comment

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

Some small comments

src/components/AttachmentPicker/index.native.js Outdated Show resolved Hide resolved
src/components/AttachmentPicker/index.native.js Outdated Show resolved Hide resolved
src/components/AttachmentPicker/propTypes.js Outdated Show resolved Hide resolved
@kidroca kidroca force-pushed the kidroca/attachment-modal-update branch from c98f119 to 6801322 Compare March 31, 2021 12:04
@kidroca
Copy link
Contributor Author

kidroca commented Mar 31, 2021

Updated

  • improved error messages

@kidroca kidroca force-pushed the kidroca/attachment-modal-update branch from 626d077 to 08d8d7b Compare April 2, 2021 17:14
@kidroca
Copy link
Contributor Author

kidroca commented Apr 2, 2021

Updated

To preserve review history, I'll push a backup branch or a tag that will store the original commits
This way I think review history will be kept as the original commits would still exist

Sorry this didn't work. 😞

You can still see what changes were requested in the Conversation tab here, but they won't appear in "File Changes"

I've addressed all merge conflicts and tested that this still works as expected with the latest codebase

@kidroca kidroca requested a review from NikkiWines April 2, 2021 17:29
Copy link
Contributor

@NikkiWines NikkiWines left a comment

Choose a reason for hiding this comment

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

This looks good! Gonna leave it to @Julesssss for the final review + merge.

Toggling the keyboard on the simulator will switch between these behaviors. Though for a real device the keyboard will always pop out (unless the device is connected to an external keyboard)

I would put this in your testing steps so that QA knows to do this if they're using a simulator. Otherwise they might think there's an issue with the PR.

Copy link
Contributor

@Julesssss Julesssss left a comment

Choose a reason for hiding this comment

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

Code is looking good, but I ran through the tests again and I'm seeing a regression in the menu options. The 'Upload Photo' option is displayed -- for every single platform.

androidAttachment
Simulator Screen Shot - iPhone 11 - 2021-04-06 at 11 16 00
Screenshot 2021-04-06 at 11 19 39

Copy link
Contributor

@Julesssss Julesssss left a comment

Choose a reason for hiding this comment

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

Whoops, forget that last review -- the option has just been renamed to 'Upload Photo'. Outside of the scope of this PR.

@Julesssss Julesssss merged commit 7cfbaae into Expensify:master Apr 6, 2021
@kidroca kidroca deleted the kidroca/attachment-modal-update branch April 6, 2021 14:15
@isagoico
Copy link

isagoico commented Apr 7, 2021

PR was a pass, only thing is that we were able to reproduce this scratch that, we found an issue in iOS mWeb

image

Edit: we found an issue in mWeb.

@isagoico
Copy link

isagoico commented Apr 7, 2021

This issue was reproducible in mWeb iOS only. On mWeb Android it was working as expected.

Title:
iOS mWeb - Attachment - Upload photo button does not work

Expected Result

The 3 attachment options appear.

Actual Result

Nothing happens after clicking the upload photo button

Action Performed

  1. In a iOS device, go to Safari or Chrome
  2. Navigate to staging.expensify.cash
  3. Log in and navigate to a conversation
  4. Click on the attachment button
  5. Click on upload photo button.

Platform

mWeb iOS ✔️

Version Number: 1.0.11-0

Logs: https://stackoverflow.com/c/expensify/questions/4856

Notes/Photos/Videos: Any additional supporting documentation
I didn't add the deploy blocker label since the issue is already reported and reproducible in production.

Pr.2114.Mweb.mp4

@isagoico
Copy link

isagoico commented Apr 7, 2021

Step 7 of the Web steps is failing only on firefox browser. Chrome browser works as expected.

Title:
Web - Firefox browser - After File Preview closes focus does not return to the input field automatically

Expected Result

After File Preview closes focus should be returned to the compose input field

Actual Result

After File Preview closes focus does not return to the input field automatically

Action Performed

  1. Login in app https://staging.expensify.cash/signin
  2. Open a chat
  3. Press the (+) plus button to open the input menu
  4. Select "Add Attachment"
  5. The browser's file picker should open and you can select a file
  6. When you select a file you should see File Preview modal
  7. Pressing upload should upload the file and you should see the attachment/thumb inside the chat

Platform

Web (Firefox) ✔️

Build: 1.0.13-0

Notes/Images/Videos
Important: This is only happening on Firefox. Let me know if I should open a separate issue for this. On chrome, the PR was a pass.

Bug5007651_PR_2114.mp4

@kidroca
Copy link
Contributor Author

kidroca commented Apr 7, 2021

This issue was reproducible in mWeb iOS only. On mWeb Android it was working as expected.

It wouldn't do anything on desktop Safari too

Web - Firefox browser - After File Preview closes focus does not return to the input field automatically

I've went to the point before the changes introduced here - v1.0.10-2 and the issue is still recreatable - it predates these changes

@Julesssss
Copy link
Contributor

Thanks @isagoico. We have these issues covered already:

iOS mWeb - Attachment - Upload photo button does not work

  • We have a separate issue for Safari attachments, which currently doesn't work

Web - Firefox browser - After File Preview closes focus does not return to the input field automatically

@isagoico
Copy link

isagoico commented Apr 7, 2021

Thanks for the clarification! Will check the PR off then 🙇

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.

Android - Denying permissions to use camera is not handled iOS issue: Modal closes immediately after launch
5 participants