-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
refactor: migrate PDFView/index.js to function component #36809
Conversation
@ishpaul777 Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button] |
friendly bump |
reviewing today 👀 |
Reviewer Checklist
Screenshots/VideosAndroid: Nativenot applicable Android: mWeb ChromeScreen.Recording.2024-03-03.at.6.10.41.AM.moviOS: Nativenot applicable iOS: mWeb SafariScreen.Recording.2024-03-03.at.6.04.47.AM.movMacOS: Chrome / SafariUntitled-1.movMacOS: DesktopScreen.Recording.2024-03-03.at.6.17.46.AM.mov |
This comment was marked as outdated.
This comment was marked as outdated.
const [isKeyboardOpen, setIsKeyboardOpen] = useState(false); | ||
const prevWindowHeight = usePrevious(windowHeight); | ||
|
||
useEffect(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we even need this in a useEffect if this runs only on first render?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why?
src/components/PDFView/index.js
Outdated
} | ||
} | ||
// eslint-disable-next-line react-hooks/exhaustive-deps |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why this rule disabled ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This effect has an additional dependency: toggleKeyboardOnSmallScreens
. This method depends on isSmallScreenWidth
and onToggleKeyboard
. We need to prevent this effect from running when they are changed. That's the reason
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lets add a comment for explaination 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
return actualHeight; | ||
}, | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
[numPages, calculatePageWidth], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we need numPages
as dependency?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually we should have pageViewports
as its dependency.
But pageViewports
is an object(array) and changed every time the document is loaded. Having it as a state and specifying as the dependency of this method would re-render the component every time the document is loaded and would cause the component infinite re-render. And having this as a ref wouldn't change the calculatePageWidth
method after the document is loaded.
As you can see, pageViewports
and numPages
are set when the document is loaded, but numPages
is a scalar value and not changed as long as the document is not changed. So specifying this as a dependency instead of pageViewports
would prevent the infinite re-render. And when the document is changed, it would change as well
This is the reason I added numPages
as a dependency instead of pageViewports
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lets add a comment here also
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
Overall looks great, some minor comments for clarifications @s-alves10 |
i'll take another look over the weekend |
@ishpaul777 friendly bump |
Can you please merge main, review comments have been addressed 👍 I'll work on checklist and videos |
Please take a look again @ishpaul777 |
I will complete this today @s-alves10 |
@s-alves10 I found while adjusting window width, the pages has a lot of space between them can you give a quick look to see if this comes from this PR (becuase i can't repro on staging) Screen.Recording.2024-02-27.at.6.13.08.PM-1.mov |
Let me check @ishpaul777 |
I can reproduce this issue on staging bandicam.2024-02-27.23-30-22-679.mp4 |
I've fixed the above errors related to password. Please take a look |
Can you please take a look again? @ishpaul777 |
Thanks for your patience @s-alves10 I'll priortize the review for tomorrow ending my day for today 🙇♂️ |
src/components/PDFView/index.js
Outdated
// Use window height changes to toggle the keyboard. To maintain keyboard state | ||
// on all platforms we also use focus/blur events. So we need to make sure here | ||
// that we avoid redundant keyboard toggling. | ||
// Minus 100px is needed to make sure that when the internet connection is | ||
// disabled in android chrome and a small 'No internet connection' text box appears, | ||
// we do not take it as a sign to open the keyboard |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why comment is removed ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just add the missing comment back rest LGTM 👍
const ratioWidth = this.props.maxCanvasWidth / width; | ||
const ratioArea = Math.sqrt(this.props.maxCanvasArea / nbPixels); | ||
const ratio = Math.min(ratioHeight, ratioArea, ratioWidth); | ||
const getDevicePixelRatio = useCallback( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we move this function outside? So we don't have to memoize it? And just pass it the props it needs to do the calculations as arguments?
* It depends on a screen size. Also, the app should take into account the page borders. | ||
* @returns {Number} | ||
*/ | ||
const calculatePageWidth = useCallback(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same question here. Can we move it outside the component function?
calculatePageHeight(pageIndex) { | ||
if (this.state.pageViewports.length === 0 || _.some(this.state.pageViewports, (viewport) => !viewport)) { | ||
Log.warn('Dev error: calculatePageHeight() in PDFView called too early'); | ||
const calculatePageHeight = useCallback( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same question about this function.
@ishpaul777 can you re-review and then ping me again when you're ready for me to take another look? |
sure i'll ping 👍, @s-alves10 Can you address @puneetlath review comments |
@s-alves10 Any updates? |
@s-alves10 will you be able to take this to the finish line? If we don't hear back by tomorrow I'm going to proceed with hiring someone else. |
@puneetlath |
Sorry to hear that @s-alves10 😞 |
@puneetlath Can we close this PR/ or add a hold in title so this dont fall overdue in K2 |
Good call. Closing it out and putting the issue on hold. |
Details
Migrate PDFView/index.js to function component
Fixed Issues
$ #16186
PROPOSAL: #16186 (comment)
Tests
Offline tests
QA Steps
PR Author Checklist
### Fixed Issues
section aboveTests
sectionOffline steps
sectionQA steps
sectiontoggleReport
and notonIconClick
)myBool && <MyComponent />
.src/languages/*
files and using the translation methodWaiting for Copy
label for a copy review on the original GH to get the correct copy.STYLE.md
) were followedAvatar
, I verified the components usingAvatar
are working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG)
)Avatar
is modified, I verified thatAvatar
is working as expected in all cases)Design
label so the design team can review the changes.ScrollView
component to make it scrollable when more elements are added to the page.main
branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTest
steps.Screenshots/Videos
Android: Native
16186_android_native.mp4
Android: mWeb Chrome
16186_android_chrome.mp4
iOS: Native
16186_ios_native.mp4
iOS: mWeb Safari
16186_ios_safari.mp4
MacOS: Chrome / Safari
16186_mac_chrome.mp4
MacOS: Desktop
16186_mac_desktop.mp4