Skip to content

Commit 84c10f6

Browse files
authored
Merge pull request #57 from elderstudios/animation-memory-leak-fix
Fixed memory leak caused by animation, MORE
2 parents 4d8ec67 + 0fe6668 commit 84c10f6

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

index.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,14 @@ export default class Toast extends Component {
4444
text: text,
4545
});
4646

47-
Animated.timing(
47+
this.animation = Animated.timing(
4848
this.state.opacityValue,
4949
{
5050
toValue: this.props.opacity,
5151
duration: this.props.fadeInDuration,
5252
}
53-
).start(() => {
53+
)
54+
this.animation.start(() => {
5455
this.isShow = true;
5556
if(duration !== DURATION.FOREVER) this.close();
5657
});
@@ -64,13 +65,14 @@ export default class Toast extends Component {
6465
if (!this.isShow && !this.state.isShow) return;
6566
this.timer && clearTimeout(this.timer);
6667
this.timer = setTimeout(() => {
67-
Animated.timing(
68+
this.animation = Animated.timing(
6869
this.state.opacityValue,
6970
{
7071
toValue: 0.0,
7172
duration: this.props.fadeOutDuration,
7273
}
73-
).start(() => {
74+
)
75+
this.animation.start(() => {
7476
this.setState({
7577
isShow: false,
7678
});
@@ -83,6 +85,7 @@ export default class Toast extends Component {
8385
}
8486

8587
componentWillUnmount() {
88+
this.animation && this.animation.stop()
8689
this.timer && clearTimeout(this.timer);
8790
}
8891

0 commit comments

Comments
 (0)