Skip to content

Commit

Permalink
remove Dimensions listener on unmount
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Petrov committed Feb 20, 2019
1 parent 571681d commit a359ddc
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions Swiper.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class Swiper extends Component {
this._mounted = false
this.state.pan.x.removeAllListeners()
this.state.pan.y.removeAllListeners()
Dimensions.removeEventListener('change', this.onDimensionsChange)
}

getCardStyle = () => {
Expand All @@ -110,9 +111,7 @@ class Swiper extends Component {

initializeCardStyle = () => {
// this.forceUpdate()
Dimensions.addEventListener('change', () => {
this.forceUpdate()
})
Dimensions.addEventListener('change', this.onDimensionsChange)
}

initializePanResponder = () => {
Expand Down Expand Up @@ -144,6 +143,10 @@ class Swiper extends Component {
return { dx, dy }
}

onDimensionsChange = () => {
this.forceUpdate()
}

onPanResponderMove = (event, gestureState) => {
this.props.onSwiping(this._animatedValueX, this._animatedValueY)

Expand Down

0 comments on commit a359ddc

Please sign in to comment.