Skip to content

Commit b76d7c6

Browse files
authored
Merge pull request #11 from psychobolt/rerender-unmount-support
Support child component re-render and unmounting
2 parents 8e21029 + 05b39da commit b76d7c6

2 files changed

Lines changed: 19 additions & 3 deletions

File tree

src/TransitionBase.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ import React, {Component} from 'react';
22

33
export class TransitionBase extends Component {
44
defer = [];
5+
mounted = false;
56

67
deferParent(func) {
78
this.defer.push(func);
89
}
910

1011
wrapChild(child) {
1112
return React.cloneElement(child, {
12-
parent: this.native,
13+
parent: this,
1314
onParentMount: this.deferParent.bind(this)
1415
});
1516
}
@@ -23,9 +24,20 @@ export class TransitionBase extends Component {
2324
}
2425

2526
mount() {
26-
if (this.props.onParentMount && this.props.parent)
27-
this.props.onParentMount(() => this.props.parent.add(this.native));
27+
if (this.props.parent)
28+
if (this.props.parent.mounted)
29+
this.props.parent.native.add(this.native);
30+
else if (this.props.onParentMount)
31+
this.props.onParentMount(() => this.props.parent.native.add(this.native));
2832

2933
this.defer.forEach(func => func());
34+
this.mounted = true;
35+
}
36+
37+
unmount() {
38+
if (this.props.parent)
39+
this.props.parent.native.remove(this.native);
40+
41+
this.mounted = false;
3042
}
3143
}

src/reactify.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,9 @@ export function reactify(component) {
1818
componentDidMount() {
1919
this.mount();
2020
}
21+
22+
componentWillUnmount() {
23+
this.unmount();
24+
}
2125
}
2226
}

0 commit comments

Comments
 (0)