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

[HOLD for payment 2022-04-27] [$500] Pdf preview is not in centered - reported by @thesahindia #8127

Closed
mvtglobally opened this issue Mar 14, 2022 · 31 comments
Assignees
Labels
Awaiting Payment Auto-added when associated PR is deployed to production Daily KSv2 Reviewing Has a PR in review

Comments

@mvtglobally
Copy link

mvtglobally commented Mar 14, 2022

If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!


Action Performed:

  1. Go to Chat
  2. Try sending the pdf given in thread
  3. See if it's in center

Expected Result:

Preview should be in center.

Actual Result:

Preview is not in centered

Workaround:

unknown

Platform:

Where is this issue occurring?

  • Web
  • iOS
  • Android
  • Desktop App
  • Mobile Web

Version Number: 1.1.42-3
Reproducible in staging?: Y
Reproducible in production?: Y
Email or phone of affected tester (no customers):
Logs: https://stackoverflow.com/c/expensify/questions/4856
Notes/Photos/Videos: Any additional supporting documentation
Screenshot 2022-03-02 at 12.16.41 AM.pdf
Screenshot_2022_0302_001857
Screenshot_20220302_002001

Issue reported by: @thesahindia
Slack conversation: https://expensify.slack.com/archives/C01GTK53T8Q/p1646160975698469

Job Post: https://www.upwork.com/jobs/~0154111729e0a5dbd4

View all open jobs on GitHub

@mvtglobally mvtglobally added AutoAssignerTriage Auto assign issues for triage to an available triage team member Daily KSv2 labels Mar 14, 2022
@MelvinBot
Copy link

Triggered auto assignment to @kevinksullivan (AutoAssignerTriage), see https://stackoverflow.com/c/expensify/questions/4749 for more details.

@MelvinBot MelvinBot removed the AutoAssignerTriage Auto assign issues for triage to an available triage team member label Mar 14, 2022
@botify botify removed the Daily KSv2 label Mar 14, 2022
@MelvinBot MelvinBot added the Weekly KSv2 label Mar 14, 2022
@MelvinBot
Copy link

Triggered auto assignment to Contributor-plus team member for initial proposal review - @Santhosh-Sellavel (Exported)

@MelvinBot MelvinBot added the Help Wanted Apply this label when an issue is open to proposals by contributors label Mar 14, 2022
@MelvinBot
Copy link

Triggered auto assignment to @luacmartins (Exported), see https://stackoverflow.com/c/expensify/questions/7972 for more details.

@kevinksullivan
Copy link
Contributor

@thesahindia please apply when you get a chance!

@kevinksullivan kevinksullivan changed the title Pdf preview is not in centered - reported by @thesahindia [$500] Pdf preview is not in centered - reported by @thesahindia Mar 22, 2022
@kevinksullivan
Copy link
Contributor

Price doubled.

@MelvinBot MelvinBot removed the Overdue label Mar 22, 2022
@metehanozyurt
Copy link
Contributor

metehanozyurt commented Mar 27, 2022

Proposal

Cause

View doesn't center its children. Simple because it has no proper styling.

Solution

  1. We should get total height of the loaded pages at onLoadSuccess callback of the Page component:
onPageLoadSuccess = (index) => {  
    if (index + 1 === this.state.numPages) {  
        const canvasElements = document.getElementsByClassName('react-pdf__Page__canvas');  
  
        let totalHeight = 0;
          
        // I edit this because getting error when using forEach
        //canvasElements.forEach((ce) => {  
        //    totalHeight += parseInt(ce.style.height, 10);  
        // });  
        for (let counter = 0; counter < canvasElements.length; counter++) {
              totalHeight += parseInt(canvasElements[counter].style.height, 10);
        }
  
        this.setState({canvasHeight: totalHeight});  
    }  
}
  1. We should get the container height at onLayout callback of the View component:
onLayout = (event) => {  
    if (!(  
        this.state.windowWidth !== event.nativeEvent.layout.width  
  && this.state.windowHeight !== event.nativeEvent.layout.height  
  )) {  
        return;  
    }  
  
    this.setState({windowWidth: event.nativeEvent.layout.width, windowHeight: event.nativeEvent.layout.height});  
}
  1. We should calculate the view style before render if total height of the pages smaller than container height:
const smallCanvasStyle = (this.state.windowHeight > this.state.canvasHeight) ? {  
    //marginTop: ((this.state.windowHeight - this.state.canvasHeight) / 2) - 10,  
    //marginBottom: ((this.state.windowHeight - this.state.canvasHeight) / 2) - 10,  
    alignItems: 'center',
} : {};
  1. We should pass the calculated style to the View:
<View  
  style={[styles.PDFView, this.props.style, smallCanvasStyle]}  
    onLayout={this.onLayout}  
>
20220328_013327.mp4

@luacmartins
Copy link
Contributor

@metehanozyurt It seems like the gray background was modified in your solution. According to the original posting, only the preview content should be affected. I think the solution here is as simple as adding alignItems: 'center' to the PDFView class.

@Santhosh-Sellavel
Copy link
Collaborator

Thanks, @luacmartins. I'll review this again tomorrow.

@metehanozyurt Please add an updated proposal address this one #8127 (comment)

@metehanozyurt
Copy link
Contributor

Thanks, @Santhosh-Sellavel. Thank you for correcting me @luacmartins. My solution regarding marginTop and marginBottom is not as good as @luacmartins' which is more accurate for smaller PDF sizes.

However if alignItems: 'center' is added after line 1690, it looks like as the following;

App/src/styles/styles.js

Lines 1682 to 1691 in 9c50db7

PDFView: {
flex: 1,
backgroundColor: themeColors.modalBackground,
width: '100%',
height: '100%',
flexDirection: 'row',
justifyContent: 'center',
overflow: 'hidden',
overflowY: 'auto',
},

It works flawlessly for PDFs with smaller sizes but if Big PDF Size is selected, the result is not perfect as the prior.

20220328_231652.mp4

So, if my proposal is edited as below, it seems to be working well.

const smallCanvasStyle = (this.state.windowHeight > this.state.canvasHeight) ? {  
    marginTop: ((this.state.windowHeight - this.state.canvasHeight) / 2) - 10,  
    marginBottom: ((this.state.windowHeight - this.state.canvasHeight) / 2) - 10,  
} : {};

TO

const smallCanvasStyle = (this.state.windowHeight > this.state.canvasHeight) ? {  
    alignItems: 'center',
} : {};

After @luacmartins' suggestion, it looks like as the following:

20220328_231812.mp4

@kevinksullivan
Copy link
Contributor

Proposal in review

@Santhosh-Sellavel
Copy link
Collaborator

Reviewing this 👀

@Santhosh-Sellavel
Copy link
Collaborator

@metehanozyurt is this your updated proposal?

@Santhosh-Sellavel
Copy link
Collaborator

Santhosh-Sellavel commented Mar 30, 2022

@metehanozyurt

For smaller pdf, it works well but for bigger pdf, the start of the pdf is not displayed.

Screen.Recording.2022-03-30.at.11.37.24.PM.mov

cc: @luacmartins

@luacmartins
Copy link
Contributor

I wonder if there's a css only solution for this, since that would be much simpler than playing around with the screen/item sizes.

@Santhosh-Sellavel
Copy link
Collaborator

Yep would be nice & clean!

@metehanozyurt
Copy link
Contributor

metehanozyurt commented Mar 31, 2022

@metehanozyurt

For smaller pdf, it works well but for bigger pdf, the start of the pdf is not displayed.

Screen.Recording.2022-03-30.at.11.37.24.PM.mov
cc: @luacmartins

Thanks for response @Santhosh-Sellavel. You are absolutely right @luacmartins. If I find it, I will definitely write it down.

Did you edit this file @Santhosh-Sellavel ?

App/src/styles/styles.js

Lines 1682 to 1691 in 9c50db7

PDFView: {
flex: 1,
backgroundColor: themeColors.modalBackground,
width: '100%',
height: '100%',
flexDirection: 'row',
justifyContent: 'center',
overflow: 'hidden',
overflowY: 'auto',
},

because if you add alignItems: 'center' this line looks like that.

If yes, can you please delete that line and try again? According to my proposal it should work like the video below. Thanks.

20220328_231812.mp4

@Santhosh-Sellavel
Copy link
Collaborator

Santhosh-Sellavel commented Mar 31, 2022

Did you edit this file @Santhosh-Sellavel ?

App/src/styles/styles.js

Lines 1682 to 1691 in 9c50db7

PDFView: {
flex: 1,
backgroundColor: themeColors.modalBackground,
width: '100%',
height: '100%',
flexDirection: 'row',
justifyContent: 'center',
overflow: 'hidden',
overflowY: 'auto',
},

because if you add alignItems: 'center' this line looks like that.

No, I didn’t @metehanozyurt

@luacmartins
Copy link
Contributor

You are absolutely right @luacmartins. If I find it, I will definitely write it down.

Thanks @metehanozyurt! I think it's worth exploring a css only solution before we introduce more complex logic. Let me know if you come up with anything.

@metehanozyurt
Copy link
Contributor

metehanozyurt commented Mar 31, 2022

Thank you @luacmartins and @Santhosh-Sellavel. I think i found the css change we need. Can you please check my solution. Only We need to change like this. Thank you so much for your kind words and encouragements 🙏 .

PDFView: {
        display: 'grid',
        backgroundColor: themeColors.modalBackground,
        width: '100%',
        height: '100%',
        justifyContent: 'center',
        overflow: 'hidden',
        overflowY: 'auto',
        alignItems: 'center',
    },
20220401_000954.mp4

@luacmartins
Copy link
Contributor

@metehanozyurt Nice one! I tested in all platforms and that seemed to fix the issue in all of them! I thought that display: grid wasn't supported in native devices, but that property seems to only affect web/desktop anyways as the solution works on native without display: grid. @Santhosh-Sellavel any comments on the proposed solution?

@Santhosh-Sellavel
Copy link
Collaborator

@luacmartins Solution seems to be working! But wondering why display: grid is needed here?

@metehanozyurt how does display: grid addresses the issue?

@metehanozyurt
Copy link
Contributor

Thank you @luacmartins and @Santhosh-Sellavel. My first approach was as follows. I want to implement "justify-content" in small pdf sizes. but I don't need this setting for large pdf sizes. According to the this URL grid offers me this opportunity.

Maybe this URL can be answer about addresses the issue. Like you, I have doubts that it is the only solution.

@Santhosh-Sellavel
Copy link
Collaborator

Santhosh-Sellavel commented Apr 1, 2022

@luacmartins
Let's go with the @metehanozyurt proposal here! I don't see any downside here.
🎀 👀 🎀 C+ reviewed

With a couple of suggestions.

@luacmartins
Copy link
Contributor

Agreed! Your solution looks good @metehanozyurt!

As for @Santhosh-Sellavel suggestions, I would not add display: grid to display utilities though, since it's not supported by RN - https://github.com/Expensify/App/blob/main/src/styles/utilities/display.js#L4-L6.

@MelvinBot MelvinBot removed the Help Wanted Apply this label when an issue is open to proposals by contributors label Apr 1, 2022
@MelvinBot
Copy link

📣 @metehanozyurt You have been assigned to this job by @luacmartins!
Please apply to this job in Upwork and leave a comment on the Github issue letting us know when we can expect a PR to be ready for review 🧑‍💻
Keep in mind: Code of Conduct | Contributing 📖

@kevinksullivan
Copy link
Contributor

@metehanozyurt apply to the job when you get a chance. Thanks!

@Santhosh-Sellavel
Copy link
Collaborator

As for @Santhosh-Sellavel suggestions, I would not add display: grid to display utilities though, since it's not supported by RN - https://github.com/Expensify/App/blob/main/src/styles/utilities/display.js#L4-L6.

Nice catch @luacmartins , yes adding there could create some unnescessary confusion.

But the reason behind the suggestion is to use display: gridonly for web/desktop.

cc: @metehanozyurt

@luacmartins
Copy link
Contributor

PR was merged. Not overdue.

@melvin-bot melvin-bot bot added Weekly KSv2 Awaiting Payment Auto-added when associated PR is deployed to production and removed Weekly KSv2 labels Apr 20, 2022
@melvin-bot melvin-bot bot changed the title [$500] Pdf preview is not in centered - reported by @thesahindia [HOLD for payment 2022-04-27] [$500] Pdf preview is not in centered - reported by @thesahindia Apr 20, 2022
@melvin-bot
Copy link

melvin-bot bot commented Apr 20, 2022

The solution for this issue has been 🚀 deployed to production 🚀 in version 1.1.55-2 and is now subject to a 7-day regression period 📆. Here is the list of pull requests that resolve this issue:

If no regressions arise, payment will be issued on 2022-04-27. 🎊

@melvin-bot melvin-bot bot added Daily KSv2 and removed Weekly KSv2 labels Apr 26, 2022
@kevinksullivan
Copy link
Contributor

@Santhosh-Sellavel and @thesahindia paid.

@metehanozyurt can you accept the offer so i can finish payment for you? Thanks!

@kevinksullivan
Copy link
Contributor

All set, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting Payment Auto-added when associated PR is deployed to production Daily KSv2 Reviewing Has a PR in review
Projects
None yet
Development

No branches or pull requests

7 participants