From 789cf9ab5409ee3797d5c5682088958609f4ff8f Mon Sep 17 00:00:00 2001 From: Anurag Shivarathri Date: Mon, 18 Oct 2021 22:56:33 +0530 Subject: [PATCH] MM-39348 CRT crash (#5759) * Cancelling animation frame on unmounting the component * avoid calling cancel animation twice * Update app/components/post_draft/post_draft.js Co-authored-by: Elias Nahum Co-authored-by: Elias Nahum --- app/components/post_draft/post_draft.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/app/components/post_draft/post_draft.js b/app/components/post_draft/post_draft.js index 036b2cf94..0a4b1744b 100644 --- a/app/components/post_draft/post_draft.js +++ b/app/components/post_draft/post_draft.js @@ -41,6 +41,9 @@ export default class PostDraft extends PureComponent { componentWillUnmount() { EventEmitter.off(UPDATE_NATIVE_SCROLLVIEW, this.updateNativeScrollView); + if (this.resetScrollView) { + cancelAnimationFrame(this.resetScrollView); + } } handleInputQuickAction = (value) => { @@ -51,9 +54,10 @@ export default class PostDraft extends PureComponent { updateNativeScrollView = (scrollViewNativeID) => { if (this.keyboardTracker?.current && this.props.scrollViewNativeID === scrollViewNativeID) { - const resetScrollView = requestAnimationFrame(() => { - this.keyboardTracker.current.resetScrollView(scrollViewNativeID); - cancelAnimationFrame(resetScrollView); + this.resetScrollView = requestAnimationFrame(() => { + this.keyboardTracker.current?.resetScrollView(scrollViewNativeID); + cancelAnimationFrame(this.resetScrollView); + this.resetScrollView = null; }); } };