From 67a518f33ba2eb86e5f79fc072a9671d92788537 Mon Sep 17 00:00:00 2001 From: Pierre Michel Date: Tue, 30 May 2023 07:58:18 -0600 Subject: [PATCH 1/4] Fix the spinner showing when uploading twice the same image on android Signed-off-by: Pierre Michel --- src/components/ImageWithSizeCalculation.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/components/ImageWithSizeCalculation.js b/src/components/ImageWithSizeCalculation.js index dbb5f6f3ead8..c0a8bb14997d 100644 --- a/src/components/ImageWithSizeCalculation.js +++ b/src/components/ImageWithSizeCalculation.js @@ -39,6 +39,7 @@ class ImageWithSizeCalculation extends PureComponent { this.state = { isLoading: false, + loadedSucessfully: false, }; this.imageLoadingStart = this.imageLoadingStart.bind(this); @@ -52,7 +53,10 @@ class ImageWithSizeCalculation extends PureComponent { } imageLoadingStart() { - this.setState({isLoading: true}); + //Fix the spinner showing when uploading twice the same image on android #17480 + if(!this.state.loadedSucessfully){ + this.setState({isLoading: true}); + } } imageLoadingEnd() { @@ -60,6 +64,7 @@ class ImageWithSizeCalculation extends PureComponent { } imageLoadedSuccessfully(event) { + this.setState({loadedSucessfully: true}); this.props.onMeasure({ width: event.nativeEvent.width, height: event.nativeEvent.height, From 38594e6060b25e5b43beacbe04f9bd57f322f17f Mon Sep 17 00:00:00 2001 From: Pierre Michel Date: Tue, 30 May 2023 08:29:47 -0600 Subject: [PATCH 2/4] Fix lint issues Signed-off-by: Pierre Michel --- src/components/ImageWithSizeCalculation.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/components/ImageWithSizeCalculation.js b/src/components/ImageWithSizeCalculation.js index c0a8bb14997d..427316bfa998 100644 --- a/src/components/ImageWithSizeCalculation.js +++ b/src/components/ImageWithSizeCalculation.js @@ -53,10 +53,11 @@ class ImageWithSizeCalculation extends PureComponent { } imageLoadingStart() { - //Fix the spinner showing when uploading twice the same image on android #17480 - if(!this.state.loadedSucessfully){ - this.setState({isLoading: true}); + // Fix the spinner showing when uploading twice the same image on android #17480 + if (this.state.loadedSucessfully) { + return; } + this.setState({isLoading: true}); } imageLoadingEnd() { From f044a6aa90da1f89f4506c577fcfaf6e4a70aefd Mon Sep 17 00:00:00 2001 From: Pierre Michel Date: Wed, 31 May 2023 18:39:31 -0600 Subject: [PATCH 3/4] We don't need to use state here Signed-off-by: Pierre Michel --- src/components/ImageWithSizeCalculation.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/components/ImageWithSizeCalculation.js b/src/components/ImageWithSizeCalculation.js index 427316bfa998..5d874e2d3f45 100644 --- a/src/components/ImageWithSizeCalculation.js +++ b/src/components/ImageWithSizeCalculation.js @@ -39,7 +39,6 @@ class ImageWithSizeCalculation extends PureComponent { this.state = { isLoading: false, - loadedSucessfully: false, }; this.imageLoadingStart = this.imageLoadingStart.bind(this); @@ -54,7 +53,7 @@ class ImageWithSizeCalculation extends PureComponent { imageLoadingStart() { // Fix the spinner showing when uploading twice the same image on android #17480 - if (this.state.loadedSucessfully) { + if (this.isLoaded) { return; } this.setState({isLoading: true}); @@ -65,7 +64,7 @@ class ImageWithSizeCalculation extends PureComponent { } imageLoadedSuccessfully(event) { - this.setState({loadedSucessfully: true}); + this.isLoaded = true; this.props.onMeasure({ width: event.nativeEvent.width, height: event.nativeEvent.height, From 6531b00d934c65ed33d3bb9359465bc601836ae7 Mon Sep 17 00:00:00 2001 From: Pierre Michel Date: Thu, 1 Jun 2023 10:39:15 -0500 Subject: [PATCH 4/4] Update src/components/ImageWithSizeCalculation.js Co-authored-by: Aimane Chnaif <96077027+aimane-chnaif@users.noreply.github.com> --- src/components/ImageWithSizeCalculation.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/ImageWithSizeCalculation.js b/src/components/ImageWithSizeCalculation.js index 5d874e2d3f45..0f5cbf3d1e51 100644 --- a/src/components/ImageWithSizeCalculation.js +++ b/src/components/ImageWithSizeCalculation.js @@ -52,7 +52,7 @@ class ImageWithSizeCalculation extends PureComponent { } imageLoadingStart() { - // Fix the spinner showing when uploading twice the same image on android #17480 + // Return early if the image has already loaded (this can happen when uploading the same image twice on Android) if (this.isLoaded) { return; }