-
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
|
@@ -82,7 +83,7 @@ export const SnapUIFooterButton: FunctionComponent< | |||
{...props} | |||
size={ButtonSize.Lg} | |||
block | |||
disabled={disabled} | |||
disabled={requireScroll ? !buttonsEnabled : 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.
Shouldn't the disabled
prop always take priority here?
disabled={requireScroll ? !buttonsEnabled : disabled} | |
disabled={disabled || (requireScroll && !buttonsEnabled)} |
let hasReachedBottom; | ||
switch (action.type) { | ||
case 'MANUAL_SCROLL': | ||
hasReachedBottom = state.hasReachedBottom || action.isAtBottom; |
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 don't think this needs to be a mutable variable.
}, [interfaceState?.content]); | ||
|
||
const requireScroll = useMemo( | ||
() => Boolean(content?.props?.children?.[1]?.props?.requireScroll), |
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 guaranteed to be the correct component?
? rawContent | ||
: Container({ children: rawContent }); | ||
}, [interfaceState?.content]); | ||
|
||
const requireScroll = useMemo( |
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 don't think this needs to be memoised.
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?
// 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?
contentBackgroundColor ?? | ||
mapToExtensionCompatibleColor(content?.props?.backgroundColor) ?? | ||
BackgroundColor.backgroundAlternative; | ||
const backgroundColor = useMemo( |
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.
Again doesn't feel like this needs to be memoised.
|
||
// The renderer should only have a footer if there is a default cancel action | ||
// or if the footer component has been used. | ||
const hasFooter = useMemo( |
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 here regarding memoisation.
expect(getByText('Foo')).toBeDefined(); | ||
expect(container).toMatchSnapshot(); | ||
}); | ||
describe('Basic Rendering', () => { |
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 change in nesting makes this diff very difficult to read. Maybe move it to a separate PR, and only add the required changes here?
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