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
Add media query hooks and animation to snackbar notices #15908
Conversation
I didn't add any dependency to |
Thanks for follow-up, it makes a lot of sense. I really like how |
This is excellent. The modal slides in from the bottom, and does a simple fade out on removal. Here's a (slightly slowed down) GIF of the animation: It respects the reduce motion media query too, and just appears/disappears in that case: The only issue I'm seeing occurs when there are multiple notices, and the bottommost ones are dismissed first: The notices near the top slide down as you'd expect, but they do a little pause before they settle into place at the very bottom. Is there anything we can do to eliminate that? |
* | ||
* @return {boolean} Reduced motion preference value. | ||
*/ | ||
const useReducedMotion = |
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 should come in handy.
* @param {string} query Media Query. | ||
* @return {boolean} return value of the media query. | ||
*/ | ||
export default function useMediaQuery( query ) { |
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.
How would we handle these for mobile native conceptually?
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.
That's a good question, I think Mobile shouldn't really care about that hook. Ultimately, this hook might not be used directly by component. instead we'd use higher-level ones that can be "forked" by mobile for example useReducedMotion
can be adapted for mobile.
await next( { height: 0 } ); | ||
}, | ||
config: { tension: 300 }, | ||
immediate: isReducedMotion, |
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 wonder if we should wrap around react-spring primitives and offer this by default.
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. Because there is not a unique hook for react spring animations so basically this means creating a custom hook for each one of the react-spring hooks.
4533fe1
to
eb44d7f
Compare
Pushed some updates here:
What do you all think? What's remaining here. |
I'm unable to look right at this moment, but it sounds like the change from rendering on the GPU (which happens when you use translate) to rendering on the CPU (default state). This is usually mostly visible in Safari. If this is the case, keeping the item on the GPU forever should fix it, and can be done be applying The only thing to be mindful of is that this can cause some trickiness when overflow is involved, and even then it's rare. |
@jasmussen Actually, I think it's if something happens when the DOM element containing the snackbar gets removed from the DOM. Before its removal, it is supposed to have a height of |
I'd appreciate reviews and ✅ if you think it's all good. |
@youknowriad — I think I found a quick fix to this one. Setting the I am seeing this PR crash GB in Safari — not sure if that's just a problem on my end. Here's the error I'm seeing. |
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 have just a few non-blocking comments (note this was a code review only, I did not test this).
<div | ||
className="components-snackbar-list__notice-container" | ||
ref={ ( ref ) => ref && refMap.set( notice, ref ) } | ||
> |
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 an additional nested div? Could the props and ref just be added to the <animated.div>
component?
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.
No we can't, that was my original ideal but the way this animation work required the animation divs to be adjacent without any margin between them (otherwise the animation is not smooth on removal, there's a jump) and it also requires that the height of the animated div is equal to the snackbar + the margin between two snackbars and without the inner div it's impossible to do because of the "margin-collapsing"
|
||
// Hooks | ||
export { default as useMediaQuery } from './hooks/use-media-query'; | ||
export { default as useReducedMotion } from './hooks/use-reduced-motion'; |
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.
Nice little bit of cleanup here 👍
@@ -44,6 +44,7 @@ | |||
"re-resizable": "^4.7.1", | |||
"react-click-outside": "^3.0.0", | |||
"react-dates": "^17.1.1", | |||
"react-spring": "^8.0.20", |
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 react-spring
something we might consider adding as a library in WP core? I imagine a number of plugin/theme author's might use it as well (I'm currently using it for a block I'm developing).
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 personally worry about adding this kind of libs as WP core libs because of the breaking changes they might introduce. For the moment I think it's small enough to "allow it" to be duplicated but I think that's a good question and we should probably have some defined guidelines to answer it.
@kjellr Good find. Both are fixed now. |
Excellent — just tested and confirmed. This should be ready to 🚢 from a design perspective! |
This PR adds some animation to snackbar notices. It uses
react-spring
to do so and it introduces new React hooks:useMediaQuery
anduseReducedMotion
in order to disable the animation if the reduced motion preference is enabled.Testing instructions