-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Popover: fix and improve opening animation, use framer motion #43186
Conversation
Size Change: -88 B (0%) Total Size: 1.24 MB
ℹ️ View Unchanged
|
d4ee91e
to
c4bd972
Compare
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.
Looks really good. Code seems solid.
I noticed a potential issue—in the testing environment (localhost:8889 when using wp-env), the 'Gutenberg Test Plugin, Disables the CSS animations' plugin is used to disable animations. It makes puppeteer end to end tests more stable, since that library doesn't do auto-waiting like playwright does.
In this PR popover animations still seem to be active.
Good find! I'll have a look and report back (also curious to see if this issue affects other |
As I suspected, all @talldan , we could treat that as a separate issue and move ahead with this PR — what do you think? |
77ca5a1
to
710dd04
Compare
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.
LGTM, nice work!
…clarity around poopover positioning
f892602
to
65d458f
Compare
What?
Tracked in #42770
After the regression introduced by #40740, this PR aims at restoring (and improving) the
Popover
's opening animationWhy?
#40740 introduces a few big changes to
Popover
— in particular, it introduced a newplacement
prop (that should replace the legacyposition
prop). Alongside theplacement
prop, #40470 introduced two new functions:positionToPlacement
: a function to "convert"position
values toplacement
valuesplacementToAnimationOrigin
: a function to associate an animation origin, given theplacement
This refactor caused the popover to animate unexpectedly (i.e. from the from animation origin (example).
Furthermore, as I looked into solving this issue, I noticed that
Popover
still relied on theanimate
component, which was supposed to be deprecated already some time ago (see #27390).Finally, I also noticed that the
Popover
was animating even when in its expanded mode, which is supposed to occupy the full screen on mobile — I believe that animating a piece of UI as big as the whole screen with a translate/scale animation could be excessive.How?
framer-motion
(instead of theanimate
component) for thePopover
's animationanimate
component:0.1s
cubic-bezier(0, 0, 0.2, 1)
x
andy
axis)0
to1
opacity)animate
property, the popover won't animate when in its expanded state (on mobile). This change was caused by two reasons:placement
— even if the placement isn't really taken into account in the expanded state (the popover is full screen)placement
and/or is less overwhelming visually.placementToAnimationOrigin
logic, using a lookup table instead of hard-to-read logic for the animation originpositionToPlacement
andplacementToAnimationOrigin
to a separateutils.js
filepositionToPlacement
function and the variable parts of theplacementToAnimationOrigin
functionTesting Instructions
For ease of debug, the animation duration can be changes like so:
Storybook
Open Storybook and play around with the
Popover
examples. In particular:placement
value, the popover animates from the correct animation originanimate
prop is set tofalse
expandOnMobile
prop is set totrue
and the popover is rendered in mobile viewports (even if theanimate
prop is set totrue
)prefers-reduced-motion
flag is set by the user (even if theanimate
prop is set totrue
)In the editor
Do a sanity check across the editor and make sure that the popover behaves (and animates when necessary) as expected
Known issues
#42770 has a list of known issues.
Specifically to testing for animation origin, it is possible that the
positionToPlacement
function introduced in #40740 is not converting the position 100% correctly. For the sake of this PR's scope, we should focus on theplacement
to animation origin logic (theposition
toplacement
logic can be tackled separately).Screenshots or screencast
Storybook (normal speed), this PR:
popover-animation.mp4
Storybook (slower speed), this PR:
popover-animation.mp4
Editor (normal speed),
trunk
:popover-animation-editor-trunk.mp4
Editor (normal speed), this PR:
popover-animation-editor-pr.mp4