-
Notifications
You must be signed in to change notification settings - Fork 5.1k
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
feat: Add logic for new requireScroll
prop for Snap Footer
component
#29863
base: main
Are you sure you want to change the base?
Conversation
CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes. |
Builds ready [fb1ef7c]
Page Load Metrics (1814 ± 116 ms)
Bundle size diffs
|
Builds ready [22be388]
Page Load Metrics (1687 ± 87 ms)
Bundle size diffs
|
ui/components/app/snaps/snap-ui-renderer/components/avatar-icon.ts
Outdated
Show resolved
Hide resolved
}, [rawContent, scrollState, scrollArrow, requireScroll]); | ||
}; | ||
|
||
const LoadingSpinner = memo(function LoadingSpinner() { |
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 is this moved out?
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.
For readability
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.
and memoizing because it's static no need to re-create on every render
Builds ready [995774c]
Page Load Metrics (1716 ± 89 ms)
Bundle size diffs
|
Builds ready [f7bac01]
Page Load Metrics (1708 ± 47 ms)
Bundle size diffs
|
…r performance, updated useScrollRequired with callback option, added requireScroll tests
Builds ready [1697674]
Page Load Metrics (1613 ± 66 ms)
Bundle size diffs
|
ui/components/app/snaps/snap-ui-footer-button/snap-ui-footer-button.tsx
Outdated
Show resolved
Hide resolved
return; | ||
} | ||
|
||
const isActuallyAtBottom = |
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.
Is this different from useScrollRequired
's hasScrolledToBottomState
? Can we deduplicate?
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, I don't think that hook should even export isScrolledToBottom
or hasScrolledToBottomState
tbh, that calculation should happen in the component itself because it sets state too early in the hook.
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.
I'm not sure I understand. It seems like we're duplicating a lot of logic here, can we update the hook instead?
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.
The hook is used in a lot of places, it'll blow the scope of this PR up if I make a major change to the hook. I made as much changes as possible to it without possibly breaking anything elsewhere.
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.
I'm still trying to understand why we actually need all this code. The useScrollRequired
hook has a property that indicates if the user has scrolled to the bottom already, which seems to work fine in existing implementations. Can you explain why all this code is necessary, and why we can't simply rely on useScrollRequired
?
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.
Hmm so I was definitely experiencing flickering issues before, it was most likely something else that was causing it. I re-factored to just use the hook: 355fe1e. Updating the tests in another commit.
// Prevent multiple clicks | ||
if (isProgrammaticScrollRef.current) { | ||
return; | ||
} | ||
isProgrammaticScrollRef.current = true; |
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 is this a ref? Is this necessary in the first place?
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.
Glad you questioned this, made me refactor things a little. Removed the reducer state and simplified the scroll handler. The ref is needed for the scroll to bottom function, I don't want to use state to set a flag and cause an unnecessary re-render.
ui/components/app/snaps/snap-ui-renderer/snap-ui-renderer.test.js
Outdated
Show resolved
Hide resolved
Builds ready [3b460ca]
Page Load Metrics (1773 ± 94 ms)
Bundle size diffs
|
ui/components/app/snaps/snap-ui-renderer/snap-ui-renderer.test.js
Outdated
Show resolved
Hide resolved
Builds ready [f6ba4c5]
Page Load Metrics (1656 ± 66 ms)
Bundle size diffs
|
Builds ready [355fe1e]
Page Load Metrics (1995 ± 121 ms)
Bundle size diffs
|
Builds ready [8e0b3d7]
Page Load Metrics (2270 ± 165 ms)
Bundle size diffs
|
}); | ||
|
||
const shouldShowArrow = useMemo(() => { | ||
if (!requireScroll || isScrolledToBottom || hasScrolledToBottom) { |
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 need this first if
if we return false at the end anyways ?
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.
Yeah you're right that we don't need the first if, but not because there's a false return at the end, but because we're already using requireScroll
as a condition in snap-ui-interface
. If that requireScroll
wasn't there then removing this would break things.
{requireScroll && showArrow && ( | ||
<AvatarIcon | ||
iconName={IconName.Arrow2Down} | ||
data-testid="snap-ui-renderer__scroll-button" | ||
backgroundColor={BackgroundColor.infoDefault} | ||
color={IconColor.primaryInverse} | ||
className="snap-ui-renderer__scroll-button" | ||
onClick={scrollToBottom} | ||
style={{ | ||
cursor: 'pointer', | ||
position: 'absolute', | ||
left: 0, | ||
right: 0, | ||
marginLeft: 'auto', | ||
marginRight: 'auto', | ||
zIndex: 'auto', | ||
bottom: '84px', | ||
}} | ||
/> | ||
)} |
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 have to define this inside the context provider ? This seems not ideal
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.
what is your suggestion?
Builds ready [0191696]
Page Load Metrics (2675 ± 604 ms)
Bundle size diffs
|
Description
Write a short description of the changes included in this pull request, also include relevant motivation and context. Have in mind the following questions:
requireScroll
.requireScroll
prop in their footers. The prop ensures that the footer buttons are disabled until the snap ui content has been viewed. This prop also means that a scroll arrow is displayed based on theisScrolledToBottom
prop.Related issues
Fixes: MetaMask/snaps#3021
Manual testing steps
Screenshots/Recordings
After
Screen.Recording.2025-02-05.at.12.46.34.PM.mov
Pre-merge author checklist
Pre-merge reviewer checklist