-
Notifications
You must be signed in to change notification settings - Fork 734
Drawer - Remove UNSAFE method #945
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
Conversation
src/components/drawer/Swipeable.tsx
Outdated
if (this._shouldUpdateAnimatedEvent()) { | ||
this._updateAnimatedEvent(this.props, this.state); | ||
} |
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 don't trigger updates or animations from the render
method.
There're other lifecycle methods for that..
Why don't keep this logic in componentDidUpdate
?
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 is not triggering animation, it just updates the variables and it happens only once, after the first render and before the second one that is triggered by a 'setState' in the 'onLayout'. If I'll move it to the 'componentDidUpdate' it won't take effect since it will happen after the second render, and since I can't trigger render in 'componentDidUpdate' from obvious reasons...
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 think there's fundamental issue with the component and maybe it's a good opportunity to refactor it a little.
This hack doesn't feel unnatural to React ecosystem.
Currently we store derived animated values in the class instance (this._transX
, this._showLeftAction
, this._leftActionTranslate
, etc..)
This forces us to store these values at the right moment so it will take into account when the next render happens.
What if instead of sorting these values we'll just implement methods that return the derived animated value separately.
For instance, we'll have a method for getTransX
and getShowLeftAction
and so on..
This way I believe the values should by dynamic and always derive from current state/props and might reduce us some unnecessary code
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.
Love it. Thanks. Done.
src/components/drawer/Swipeable.tsx
Outdated
this.prevProps = prevProps; | ||
this.prevState = prevState; |
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 storing these?
Why not just have the check here..
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 need to check after the first render
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.
See my other comment, this may be redundant.
…native-ui-lib into infra/Swipeable_remove_UNSAFE
Description
Swipeable - Remove 'UNSAFE_componentWillUpdate' method.
Changelog
Drawer - Swipeable - Remove UNSAFE method.