From 97742c2eaf7b2463ccd54ff02c7556bbf79d55d9 Mon Sep 17 00:00:00 2001 From: Robert Grigorian <35215781+therobertgrigorian@users.noreply.github.com> Date: Mon, 3 Oct 2022 12:55:13 +0300 Subject: [PATCH] get rid of crashes on remove the listener (#83) --- Swiper.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Swiper.js b/Swiper.js index 53f7c76c..a93ec1c0 100644 --- a/Swiper.js +++ b/Swiper.js @@ -1,5 +1,5 @@ import React, { Component } from 'react' -import { PanResponder, Text, View, Dimensions, Animated } from 'react-native' +import { PanResponder, Text, View, Dimensions, Animated, InteractionManager } from 'react-native' import PropTypes from 'prop-types' import isEqual from 'lodash/isEqual' @@ -82,9 +82,11 @@ class Swiper extends Component { componentWillUnmount = () => { this._mounted = false - this.state.pan.x.removeAllListeners() - this.state.pan.y.removeAllListeners() - this.dimensionsChangeSubscription.remove() + InteractionManager.runAfterInteractions(() => { + this.state.pan.x.removeAllListeners() + this.state.pan.y.removeAllListeners() + this.dimensionsChangeSubscription?.remove() + }) } getCardStyle = () => {