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

adding carousel to attachment modal #9279

Merged
merged 59 commits into from
Mar 8, 2023

Conversation

JediWattson
Copy link
Contributor

@JediWattson JediWattson commented Jun 1, 2022

Details

add a carousel to the attachment modal that navigates through a chat's attachments

Fixed Issues

#7862
PROPOSAL: #7862 (comment)

Tests

iOS / android

  1. tap on an image in chat and an attachment modal presents
  2. swipe left or right to change the attachment to the next or previous one
  3. tap on the modal to make the arrows on the sides appear or disappear
  4. tap on an arrow to change the attachment to the next or previous one
  5. verify attachment's name are displayed correctly in modal header

web / desktop

  1. click an image
  2. clicking an arrow will change the attachment to the next or previous one
  3. verify that moving the cursor outside the modal will make the arrows disappear
  4. verify moving the cursor back into the modal will make the arrows appear
  5. verify modal header matches file name, and correct attachment is downloaded
  • Verify that no errors appear in the JS console

Offline tests

QA Steps

iOS / android

  1. tap on an image in chat and an attachment modal presents
  2. swipe left or right to change the attachment to the next or previous one
  3. tap on the modal to make the arrows on the sides appear or disappear
  4. tap on an arrow to change the attachment to the next or previous one
  5. verify attachment's name are displayed correctly in modal header

web / desktop

  1. click an image
  2. clicking an arrow will change the attachment to the next or previous one
  3. verify that moving the cursor outside the modal will make the arrows disappear
  4. verify moving the cursor back into the modal will make the arrows appear
  5. verify modal header matches file name, and correct attachment is downloaded
  • [x ] Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android / native
    • Android / Chrome
    • iOS / native
    • iOS / Safari
    • MacOS / Chrome / Safari
    • MacOS / Desktop
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is correct English and approved by marketing by adding the Waiting for Copy label for a copy review on the original GH to get the correct copy.
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG)
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • I have checked off every checkbox in the PR author checklist, including those that don't apply to this PR.

Screenshots/Videos

Web
web.mov
Mobile Web - Chrome
mweb.chrome.mov
Mobile Web - Safari
mweb.safari.mov
Desktop
desktop.mov
iOS
ios.mov
Android
Screen.Recording.2022-12-30.at.2.00.40.PM.MOV

@JediWattson
Copy link
Contributor Author

I set this branch up to get a signed commit in. I'll be looking this comment first and then I'll need to update the videos I made for the updated buttons. Also I think there's about 2 comments that I've responded to that I left unresolved, but the rest I either went with the suggested code or unchanged the code.

@JediWattson JediWattson marked this pull request as ready for review June 6, 2022 19:48
@JediWattson JediWattson requested a review from a team as a code owner June 6, 2022 19:48
@melvin-bot melvin-bot bot requested review from chiragsalian and removed request for a team June 6, 2022 19:48
@chiragsalian
Copy link
Contributor

Review paused until santhosh get's back from OOO. Adding him as reviewer so that he sees the PR once he's back.

Copy link
Collaborator

@Santhosh-Sellavel Santhosh-Sellavel left a comment

Choose a reason for hiding this comment

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

Thanks for the patience @JediWattson! Left some comments please address those questions and add code your suggestions as comments. Don't commit any changes.

}

/**
* increments or decrements the index to get another selected item
Copy link
Collaborator

Choose a reason for hiding this comment

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

The comment shouldn't be too technical.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How about: Changes the attachment shown in the modal

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ys sound better

Helps to navigate between next/previous attachments

Comment on lines 72 to 74
this.setState((prevState) => {
const attachments = prevState.attachments;
const page = prevState.page;
Copy link
Collaborator

Choose a reason for hiding this comment

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

could have just destructured attachments, page

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it, I was going with the idea that I couldn't destructure the state. I could just destructure the argument though?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this.setState(({attachments, page}) => { ...

Comment on lines 69 to 71
* @param {Boolean} shouldDecrement
*/
cycleThroughAttachments(shouldDecrement) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we avoid boolean shouldDecrement and have some better implementation or better naming.

Ex: Could've passed -1 for back & +1 right arrow to the method then just add it to the page to get the next index

Any thoughts @chiragsalian?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I like the idea of using calling the function with 1 and -1 here and call call the argument diff then add it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

cycleThroughAttachments(diff) {
    ...
    const nextIndex = page + diff;
    ... 
}

// jsx
<Button
    onPress={() => this.cycleThroughAttachments(1)} // or -1 for back
    ... // props
/>

Copy link
Contributor

@chiragsalian chiragsalian Jun 17, 2022

Choose a reason for hiding this comment

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

yeah i would do cycleThroughAttachments with param maybe deltaSlide containing values as +1 or -1 and then do,

const newIndex = page + deltaSlide;

@Santhosh-Sellavel
Copy link
Collaborator

@JediWattson From issue description #7862 (comment)

Expected Result:

  1. When the member is viewing the most recent attachment in the chat, there's only a left arrow icon on the attachment preview screen to navigate further back. Similarly, when the member is viewing the oldest attachment in the chat, there's only a right arrow to navigate forward.
  2. If the member is previewing an attachment that isn't the oldest or latest in the chat history, there will be both left/right arrow icon to navigate "forward" or "back" to the next attachment preview.
  3. On desktop/Web: The arrow can be clicked to navigate to the next attachment preview, or the left/right arrow keys on the keyboard can be used
  4. On mobile/mWeb: The arrow can be tapped or the member can swipe left/right on the preview to navigate to the next attachment preview depending on the direction
  5. On desktop/Web, the arrows are visible on hover. On mobile/mWeb, a single tap on the image hides/shows the arrows.

I believe PR covers only 1 & 2 what above 3, 4, 5.

@JediWattson
Copy link
Contributor Author

@JediWattson From issue description #7862 (comment)

Expected Result:

  1. When the member is viewing the most recent attachment in the chat, there's only a left arrow icon on the attachment preview screen to navigate further back. Similarly, when the member is viewing the oldest attachment in the chat, there's only a right arrow to navigate forward.
  2. If the member is previewing an attachment that isn't the oldest or latest in the chat history, there will be both left/right arrow icon to navigate "forward" or "back" to the next attachment preview.
  3. On desktop/Web: The arrow can be clicked to navigate to the next attachment preview, or the left/right arrow keys on the keyboard can be used
  4. On mobile/mWeb: The arrow can be tapped or the member can swipe left/right on the preview to navigate to the next attachment preview depending on the direction
  5. On desktop/Web, the arrows are visible on hover. On mobile/mWeb, a single tap on the image hides/shows the arrows.

I believe PR covers only 1 & 2 what above 3, 4, 5.

for 3 I would propose to add a listener to handle the arrow press. It would be added when the component is mounted:

   componentDidMount() {
        document.addEventListener('keydown', this.handleArrowPress)
    }

    componentWillUnmount() {
        document.removeEventListener('keydown', this.handleArrowPress)
    }

handleArrowPress will check the e.key and call cycleThroughAttachments

    /**
     * Listens for keyboard shortcuts and applies the action
     *
     * @param {Object} e
     */
    handleArrowPress(e) {
        if(e.key === "ArrowLeft" && !this.state.isBackDisabled) {
            this.cycleThroughAttachments(-1);
        }
        if(e.key === "ArrowRight" && !this.state.isForwardDisabled) {
            this.cycleThroughAttachments(1);
        }
    }
  1. I see a SwipeableView but I'm unsure how I want to handle the data change because I feel it's best like this:
  <SwipeableView>
    <AttachmentView sourceURL={sourceURL} file={this.state.file} />
  </SwipeableView>
  // ... <AttachmentCarousel 
  1. On mobile you want the arrows to initially appear then disappear onPress right? For desktop they would be visible onMouseOver?

@Santhosh-Sellavel
Copy link
Collaborator

On mobile you want the arrows to initially appear then disappear onPress right?

  1. On desktop/Web, the arrows are visible on hover. On mobile/mWeb, a single tap on the image hides/shows the arrows.

From 5 we can get the answer, we should toggle arrow visibility when tapping on the image.

But I'm not sure whether we should show or hide the arrows initially. @Expensify/design team please help us here.

cc: @shawnborton

@Santhosh-Sellavel
Copy link
Collaborator

@JediWattson Sounds good! Please make the suggested changes, let me know when changes are done.

@shawnborton
Copy link
Contributor

For mobile, I think it's okay if they are visible by default and then tapping the image hides them.

@JediWattson
Copy link
Contributor Author

I just got most of the changes here up. I just need to add the functionality for the arrows to show and not show

@Santhosh-Sellavel
Copy link
Collaborator

@JediWattson Any update on this?

@JediWattson
Copy link
Contributor Author

I'm finishing up the arrows today, and then possibly get into the swiping too. I can add new videos showing this this weekend too.

@Santhosh-Sellavel
Copy link
Collaborator

@JediWattson Further update on this?

@github-actions
Copy link
Contributor

github-actions bot commented Jul 19, 2022

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

@Santhosh-Sellavel
Copy link
Collaborator

@JediWattson You should use only one git account. Do not use multiple accounts. Can you revert & commit changes properly thanks!

@JediWattson
Copy link
Contributor Author

Will do, I think I've completed the requirements now too. Now it seems I just need to clean that up, and add some videos for swiping and toggling arrows

@JediWattson
Copy link
Contributor Author

I believe all I have left now is to make some videos showing the arrows show and not showing along with swiping and update the qa instructions

@Santhosh-Sellavel
Copy link
Collaborator

Good then,

  • Pull changes from the latest main
  • Update PR Description & videos

And let us know when PR is ready for review.

@Santhosh-Sellavel
Copy link
Collaborator

@JediWattson Bump!

@JediWattson
Copy link
Contributor Author

@Santhosh-Sellavel I got some new videos up to show the swiping in native apps. A couple things I really can't figure out are: in mobile browsers I'm unable to capture an event to toggle showing the arrows, and in a pdf I couldn't get a similar event so I left the arrows on there

@Santhosh-Sellavel
Copy link
Collaborator

A couple things I really can't figure out are: in mobile browsers I'm unable to capture an event to toggle showing the arrows, and in a pdf I couldn't get a similar event so I left the arrows on there

Sorry for the delay, are these both specific to mobile web alone?

@Santhosh-Sellavel
Copy link
Collaborator

@JediWattson bump!

@JediWattson
Copy link
Contributor Author

the arrows not toggling is specific to mobile browsers, but the pdf seems to be an issue for both mobile browsers and native

@JediWattson
Copy link
Contributor Author

I believe I got this 100% now! @Santhosh-Sellavel

Copy link
Collaborator

@Santhosh-Sellavel Santhosh-Sellavel left a comment

Choose a reason for hiding this comment

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

Comment on lines +14 to +15
this.debouncedConfigureImageSource = _.debounce(this.configureImageSource, 220);

Copy link
Collaborator

Choose a reason for hiding this comment

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

This is required only for attachments flow, should this debounce be set here?

As it add debounce all other views which uses this component

Copy link
Contributor

Choose a reason for hiding this comment

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

It seems fine to debounce these in the image component since the logic to configure the image source is in it already.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm i don't mind the debounce but can someone remind me why we need the debounce here? Is it because if the user clicks next rapidly we want to load the image properly or is there some other reason?

I'm mostly wondering if we can trigger the debounce immediately via,

this.debouncedConfigureImageSource = _.debounce(this.configureImageSource, 220, true);

So that non-attachments are not impacted and attachments should load faster without the delay. Wouldn't that work better?

Copy link
Contributor Author

@JediWattson JediWattson Mar 7, 2023

Choose a reason for hiding this comment

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

That could work if there’s a Boolean prop that would make that false for the attachment carousel

Copy link
Contributor

Choose a reason for hiding this comment

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

I tested this a bit more wondering if it's related to clicking next button rapidly or resizing and i could not reproduce either when I remove the debounce (tested on web and ios). Can we recheck if this debounce is necessary and if so maybe add a comment explaining why?

Copy link
Contributor

Choose a reason for hiding this comment

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

There should be no debounce

  1. It's a workaround
  2. From your explanation the change is only concerning the carousel - everything else would not use debounce (the same way the carousel will)

I've submitted a PR for RN web to our fork. If fixes some inconsistencies with the Image component. I think it would address the need for debounce as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That definitely tracks. I don't know if the way I'm going about it is the same as what you mentioned, but I was digging into this more and the crux of the problem is that getSize really shouldn't be used at all. In fact I managed to refine the Image component into a few lines of code.

function Image({ source, isAuthTokenRequired, ...props }) {   
    if (isAuthTokenRequired) {
        source.uri = addEncryptedAuthTokenToURL(source.uri);
    }
    
    // eslint-disable-next-line
    return <RNImage {...props} source={source} />;
}

There's some changes I had to make in a couple other places, but not too much is really changed. I'm now using onLoad to send the height and width which changes the arguments to the parent functions. Also I needed a check in the ImageView to make sure the url was correct before setting the scale.

I was wondering if all this could be a proposal for this issue because it does reduce the loading? I just need to clean up the code a bit to make a PR for it too.

Copy link
Contributor

@kidroca kidroca Mar 21, 2023

Choose a reason for hiding this comment

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

The custom onLoad with getSize was also a workaround, because at the time react-native-web did not return image dimensions with the onLoad callback prop

Our fork of RN web has a fix for this and I'm applying it to the Image component, but the PR is blocked ATM

(we already have the fix merged to our fork, so onLoad works, but the PR is blocked due to image headers issues - auth token would be placed in headers in the future)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kidroca it looks like a change for removing the debounce was merged which should resolve this thread. Was there anything else to consider or is this all set??

Copy link
Contributor

Choose a reason for hiding this comment

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

All good 👍

Copy link
Collaborator

@Santhosh-Sellavel Santhosh-Sellavel left a comment

Choose a reason for hiding this comment

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

Approving as this test wells and code LGTM. Image component shouldDebounceImmediate prop & testing as a follow-up as discussed internally!

@luacmartins
Copy link
Contributor

luacmartins commented Mar 8, 2023

We discussed this 1:1 and we think it's better to merge the PR and tackle the issues below as a follow up -- some of them might have been addressed already:

@luacmartins luacmartins merged commit cb2ba26 into Expensify:main Mar 8, 2023
@OSBotify
Copy link
Contributor

OSBotify commented Mar 8, 2023

✋ 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 Mar 9, 2023

🚀 Deployed to staging by https://github.com/luacmartins in version: 1.2.81-0 🚀

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

@OSBotify
Copy link
Contributor

🚀 Deployed to production by https://github.com/roryabraham in version: 1.2.81-1 🚀

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

@JmillsExpensify
Copy link

Awesome work getting this to production! I've been enjoying this one, really great improvement.

<View style={styles.imageModalImageCenterContainer}>
{this.state.source && this.state.shouldLoadAttachment && (
{this.state.reportID ? (
Copy link
Contributor

Choose a reason for hiding this comment

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

#15809 regression was caused by this PR. When user navigates to the details of a user through participants list of a group chat, the route contains the reportID and hence user avatar is displayed with <AttachmentCarousel> instead of <AttachmentView>.

@NikkiWines
Copy link
Contributor

👋 Hey all, dropping in to let you all know that tooltips weren't added for the < and > arrows when introducing this feature, resulting in this bug. Please keep in mind accessibility going forward and remember to add tooltips where appropriate! Thanks 🙇

@0xmiros
Copy link
Contributor

0xmiros commented May 3, 2023

Coming from #16558:
This PR unintentionally reverted #13077 (while fixing merge conflict maybe) so re-introduced #12777

@parasharrajat
Copy link
Member

I think we missed handling the password-protected PDF UI during this PR. Buttons are relatively big which covers the form. #15896

@sobitneupane
Copy link
Contributor

This issue was not handled in this PR. Image automatically changes when carousel is open and a new image is received in the chat.

@@ -276,14 +285,12 @@ class ImageView extends PureComponent {
>
<Image
source={{uri: this.props.url}}
isAuthTokenRequired={this.props.isAuthTokenRequired}
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems isAuthTokenRequired this was removed by mistake - this prop should always be forwarded to the image

style={this.state.zoomScale === 0 ? undefined : [

// Hide image until finished loading to prevent showing preview with wrong dimensions.
style={this.state.isLoading ? undefined : [
Copy link
Contributor

Choose a reason for hiding this comment

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

This minor issue was introduced by changes made in this PR. The issue is fixed by this PR by including zoomScale along with isLoading.

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.