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 <nahumhbl@gmail.com>

Co-authored-by: Elias Nahum <nahumhbl@gmail.com>
(cherry picked from commit 789cf9ab54)

Co-authored-by: Anurag Shivarathri <anurag6713@gmail.com>
This commit is contained in:
Mattermost Build 2021-10-18 20:23:24 +02:00 committed by GitHub
parent 0561e9a78b
commit 5a3c9839bf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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;
});
}
};