From ddc7a04f370dd4029364d8a1dc725ac272cf8d31 Mon Sep 17 00:00:00 2001 From: Alex Beaman Date: Wed, 3 Aug 2022 12:48:37 +0200 Subject: [PATCH 1/3] Retry undim animation --- src/components/OpacityView.js | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/components/OpacityView.js b/src/components/OpacityView.js index 162aa6fa585e..66d99dc99bcd 100644 --- a/src/components/OpacityView.js +++ b/src/components/OpacityView.js @@ -21,6 +21,7 @@ class OpacityView extends React.Component { constructor(props) { super(props); this.opacity = new Animated.Value(1); + this.undim = this.undim.bind(this); } componentDidUpdate(prevProps) { @@ -33,14 +34,25 @@ class OpacityView extends React.Component { } if (prevProps.shouldDim && !this.props.shouldDim) { - Animated.timing(this.opacity, { - toValue: 1, - duration: 50, - useNativeDriver: true, - }).start(); + this.undim() } } + undim() { + Animated.timing(this.opacity, { + toValue: 1, + duration: 50, + useNativeDriver: true, + }).start(({finished}) => { + // If animation doesn't finish because Animation.stop was called + // (e.g. because it was interrupted by a gesture or another animation), + // restart animation so we always make sure the component gets completely shown. + if (!finished) { + this.undim(); + } + }); + } + render() { return ( Date: Wed, 3 Aug 2022 12:48:56 +0200 Subject: [PATCH 2/3] Add semicolon --- src/components/OpacityView.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/OpacityView.js b/src/components/OpacityView.js index 66d99dc99bcd..867d936631e8 100644 --- a/src/components/OpacityView.js +++ b/src/components/OpacityView.js @@ -34,7 +34,7 @@ class OpacityView extends React.Component { } if (prevProps.shouldDim && !this.props.shouldDim) { - this.undim() + this.undim(); } } From b216e4dc3bc6fdc272088bf17f9143d434afaf5c Mon Sep 17 00:00:00 2001 From: Alex Beaman Date: Wed, 3 Aug 2022 12:49:22 +0200 Subject: [PATCH 3/3] Prefer early return --- src/components/OpacityView.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/components/OpacityView.js b/src/components/OpacityView.js index 867d936631e8..9b6ebcc018b4 100644 --- a/src/components/OpacityView.js +++ b/src/components/OpacityView.js @@ -47,9 +47,10 @@ class OpacityView extends React.Component { // If animation doesn't finish because Animation.stop was called // (e.g. because it was interrupted by a gesture or another animation), // restart animation so we always make sure the component gets completely shown. - if (!finished) { - this.undim(); + if (finished) { + return; } + this.undim(); }); }