From 34a9612a8bb2bf9895bf6c53862d75dd7873b438 Mon Sep 17 00:00:00 2001 From: psychobolt Date: Sat, 30 Sep 2017 08:14:46 -0700 Subject: [PATCH 1/2] Support parent rerender and child unmount --- src/TransitionBase.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/TransitionBase.js b/src/TransitionBase.js index 5fcb1be..f4df7ea 100644 --- a/src/TransitionBase.js +++ b/src/TransitionBase.js @@ -2,6 +2,7 @@ import React, {Component} from 'react'; export class TransitionBase extends Component { defer = []; + mounted = false; deferParent(func) { this.defer.push(func); @@ -9,7 +10,7 @@ export class TransitionBase extends Component { wrapChild(child) { return React.cloneElement(child, { - parent: this.native, + parent: this, onParentMount: this.deferParent.bind(this) }); } @@ -23,9 +24,20 @@ export class TransitionBase extends Component { } mount() { - if (this.props.onParentMount && this.props.parent) - this.props.onParentMount(() => this.props.parent.add(this.native)); + if (this.props.parent) + if (this.props.parent.mounted) + this.props.parent.native.add(this.native); + else if (this.props.onParentMount) + this.props.onParentMount(() => this.props.parent.native.add(this.native)); this.defer.forEach(func => func()); + this.mounted = true; + } + + unmount() { + if (this.props.parent) + this.props.parent.native.remove(this.native); + + this.mounted = false; } } From 05b39daed096ff50e3d869c3b68e591a5e30b38c Mon Sep 17 00:00:00 2001 From: psychobolt Date: Sat, 30 Sep 2017 08:21:24 -0700 Subject: [PATCH 2/2] support unmount for reactify --- src/reactify.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/reactify.js b/src/reactify.js index 29c946d..dc53596 100644 --- a/src/reactify.js +++ b/src/reactify.js @@ -18,5 +18,9 @@ export function reactify(component) { componentDidMount() { this.mount(); } + + componentWillUnmount() { + this.unmount(); + } } }