Skip to content

Commit

Permalink
Merge pull request #314 from Jyrno42/interactionmanager
Browse files Browse the repository at this point in the history
Create interaction handle during animation
  • Loading branch information
JesperLekland committed Apr 12, 2019
2 parents 41883ca + 1122de9 commit 56b781f
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/animated-path.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { Component } from 'react'
import { InteractionManager } from 'react-native'
import PropTypes from 'prop-types'
import { Path } from 'react-native-svg'
import * as interpolate from 'd3-interpolate-path'
Expand Down Expand Up @@ -33,12 +34,16 @@ class AnimatedPath extends Component {

componentWillUnmount() {
cancelAnimationFrame(this.animation)
this._clearInteraction()
}

_animate(start) {
cancelAnimationFrame(this.animation)
this.animation = requestAnimationFrame((timestamp) => {
if (!start) {
this._clearInteraction()
this.handle = InteractionManager.createInteractionHandle()

start = timestamp
}

Expand All @@ -50,6 +55,7 @@ class AnimatedPath extends Component {
// Just to be safe set our final value to the new graph path.
this.component.setNativeProps({ d: this.newD })
// Stop our animation loop.
this._clearInteraction()
return
}

Expand All @@ -67,6 +73,13 @@ class AnimatedPath extends Component {
})
}

_clearInteraction() {
if (this.handle) {
InteractionManager.clearInteractionHandle(this.handle)
this.handle = null
}
}

render() {
return (
<Path
Expand Down

0 comments on commit 56b781f

Please sign in to comment.