-
-
Notifications
You must be signed in to change notification settings - Fork 31.7k
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
[Drawer] Open/close animation easing and timing (#6059) #6066
Conversation
@@ -93,6 +98,8 @@ export default class Drawer extends Component { | |||
children, | |||
className, | |||
docked, | |||
enterTransitionDuration, |
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.
Didnt want to duplicate theese durations here (from Slider), but it turned out, Modal needs this durations to properly show/hide himself
7a58cfe
to
4b747a7
Compare
Changed easing and duration according to spec, and solved premature modal dialog closing during animation duration
4b747a7
to
1ffac61
Compare
@@ -15,6 +15,19 @@ export const easing = { | |||
sharp: 'cubic-bezier(0.4, 0.0, 0.6, 1)', | |||
}; | |||
|
|||
// Follow https://material.io/guidelines/motion/duration-easing.html#duration-easing-common-durations |
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.
Created some constants for transition durations, but on second thought, i think theese should be subject of customization/theme somehow - even documentation gives different durations for different devices (pc, tablet, mobile, watches)
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.
Cool PR! Thanks for working on that.
I think that we miss some test. But otherwise, it's almost good to be merged 👍 .
src/Drawer/Drawer.js
Outdated
<Modal | ||
{...containerProps} | ||
show={open} | ||
backdropTransitionDuration={open ? enterTransitionDuration : leaveTransitionDuration} |
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 would reverse the order to allow high customization power.
+ backdropTransitionDuration={open ? enterTransitionDuration : leaveTransitionDuration}
+ {...containerProps}
+ show={open}
src/transitions/Slide.js
Outdated
@@ -82,14 +85,17 @@ export default class Slide extends Component { | |||
handleEntering = (element) => { | |||
const { transitions } = this.context.theme; | |||
element.style.transition = transitions.create('transform', | |||
`${this.props.transitionDuration}ms`); | |||
`${this.props.enterTransitionDuration}ms`, undefined, easing.easeOut); |
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 undefined
for 0ms
?
I'm wondering if we should change the API. That makes me think of https://twitter.com/brian_d_vaughn/status/828507525469253632.
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.
So, i am thinking of something this:
//all defaults are as now, all, 0ms, ...
transitions.create({
properties: 'transform', // String/Array
duration: transitions.durations.enteringScreen, // Number - nobody will use anything else than ms anyway
delay: ... //as above
easing: transitions.easing.easeOut, // String, probably some check if it is from standard functions?
});
Where that easing/duration constants would be best to obtain from context theme rather that from static import, since i suspect it would be appealing to change timings according to user agent (mobile/pc, ...)
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.
So, i am thinking of something this:
That's what I have in mind too 👍 . But that's out of the scope of this PR.
src/transitions/Slide.js
Outdated
element.style.transform = 'translate3d(0, 0, 0)'; | ||
if (this.props.onEntering) { | ||
this.props.onEntering(element); | ||
} | ||
}; | ||
|
||
handleExiting = (element) => { | ||
const { transitions } = this.context.theme; | ||
element.style.transition = transitions.create('transform', | ||
`${this.props.leaveTransitionDuration}ms`, undefined, easing.sharp); |
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, 0ms
would probably be more explicit.
changes after CR
added some tests
added tests. Will try to devise some API for that animation later, for this PR i left it as '0ms' since there are other usages to refactor. Will check that new API with you before refactor for sure 👍 |
src/Drawer/Drawer.spec.js
Outdated
}); | ||
|
||
it('should be passed to to Modal\'s backdropTransitionDuration when open=true', () => { | ||
const wrapper = shallow(<Drawer |
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.
We rather use that line break pattern.
const wrapper = shallow(
<Drawer
open
/>
);
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.
Sorry, was confused by eslint comma-dangle rule there, seemed to be a bit weird.
src/Drawer/Drawer.spec.js
Outdated
enterTransitionDuration={enterDuration} | ||
leaveTransitionDuration={leaveDuration} | ||
/>); | ||
assert.strictEqual(wrapper.find(Modal).prop('backdropTransitionDuration'), enterDuration); |
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.
Any though on .prop('backdropTransitionDuration')
vs.props().backdropTransitionDuration
?
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 preference, maybe later one is a bit more friendly towards editor's intellisense? Anyway, changed as requested
Changed easing and duration according to spec, and solved premature modal dialog closing during animation duration.
Fixes #6059