-
Notifications
You must be signed in to change notification settings - Fork 171
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
How to handle onEnter / onExit animations? #138
Comments
I prefer to use |
@gucheen how did you use it exactly? I found that UPDATE: I tried reversing it and the lower-level |
@jcrben Exactly. react-portal remove the container div instead of PseudoModal, so the leaving animation will not be triggered. |
In theory changing state in the import React, { PureComponent, PropTypes } from 'react';
import ReactDOM from 'react-dom';
import Portal from 'react-portal';
import $ from 'jquery';
const ANIMATION_END_EVENTS = 'webkitAnimationEnd oanimationend oAnimationEnd msAnimationEnd animationend';
export default class PortalWrapper extends PureComponent {
static propTypes = {
children: PropTypes.node.isRequired,
button: PropTypes.node.isRequired
};
constructor() {
super();
this.state = {
open: false,
openPortal: false
};
this._onToggle = ::this._onToggle;
this._onOpen = ::this._onOpen;
this._onClose = ::this._onClose;
}
_onToggle() {
const { open } = this.state;
if (open) {
this._onClose();
}
else {
this._onOpen();
}
}
_onOpen() {
this.setState({ open: true, openPortal: true });
}
_onClose() {
const node = ReactDOM.findDOMNode(this.refs.child);
$(node).on(ANIMATION_END_EVENTS, () => {
this.setState({ openPortal: false }); // TODO: ensure the event is discarded on umount
});
this.setState({ open: false });
}
render() {
const { children, button } = this.props;
const { open, openPortal } = this.state;
const props = {
open, onOpen: this._onOpen, onClose: this._onClose, onToggle: this._onToggle
};
return (
<div>
{React.cloneElement(button, props)}
<Portal isOpened={openPortal}>
{React.cloneElement(children, { ...props, ref: 'child' })}
</Portal>
</div>
);
}
} Not thoroughly tested yet, would probably want to add the removal of the animation listener on umount. Usage: (Imagine PortalChild.scss having a
|
Hey, please check the new major version of react-portal: #157 It's React v16 only since its uses the new official Portal API. There is the first beta released and I would like to get your feedback. I don't have bandwidth to maintain v3 which is very different and full of hacks. I am happy to discuss this with v4 in mind. If this is still a problem, please re-open/update the issue. Thanks. |
I'm trying to attach intro / exit transitions to my modals but have some difficulties. I'm only able to use onOpen to determine whether a Modal is active (and connecting that info to a redux store app-wide).
Is there a way to trigger transitions into and out of a modal appearance while preserving everything else?
Here is an example of how I'm calling a modal from a top container:
The text was updated successfully, but these errors were encountered: