From 5a3c9839bfe56710c09b05a571dda9beedeb3f2b Mon Sep 17 00:00:00 2001 From: Mattermost Build Date: Mon, 18 Oct 2021 20:23:24 +0200 Subject: [PATCH] MM-39348 CRT crash (#5759) (#5761) * 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 (cherry picked from commit 789cf9ab5409ee3797d5c5682088958609f4ff8f) Co-authored-by: Anurag Shivarathri --- 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; }); } };