Skip to content

Commit

Permalink
Merge pull request #7 from emilpalsson/issue5-fix
Browse files Browse the repository at this point in the history
Issue5 fix
  • Loading branch information
nicolasdelfino committed Sep 30, 2017
2 parents a66752b + e212c90 commit c83f988
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 15 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ defaultAnimation // optional
{...data}
wrapperType='div' // optional ul or whatever, defaults to div
onClick={this.onClick.bind(this)} // optional
enableClickDuringAnimation //optional, boolean (default false)
onMount={this.onMountComplete.bind(this)} // optional
onUnmount={this.onUnmountComplete.bind(this)}> // optional
<YourComponent {...data.content} />
Expand Down
2 changes: 1 addition & 1 deletion dist/react-metro.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 5 additions & 12 deletions src/MetroHoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,6 @@ import { TweenMax } from 'gsap'

const MetroHoc = Component =>
class MetroContainer extends React.Component {
constructor(props) {
super(props)
this.state = {
animating: false
}
}

// longest animation in sequence
getLongestAnimationInSequence(io) {
return Math.max(
Expand Down Expand Up @@ -45,7 +38,7 @@ const MetroHoc = Component =>
componentWillEnter(callback) {
const el = this.container

this.setState({ animating: true })
this.props.sequence[this.props.itemIndex].animating = true
TweenMax.fromTo(
el,
this.props.animation.in.time,
Expand All @@ -62,9 +55,9 @@ const MetroHoc = Component =>
'in'
)
) {
this.setState({ animating: false })
this.props.onMount && this.props.onMount()
}
this.props.sequence[this.props.itemIndex].animating = false
callback()
}
}
Expand All @@ -80,7 +73,7 @@ const MetroHoc = Component =>
fullSequenceDuration -
(this.props.animation.out.time + this.props.animation.out.delay)

this.setState({ animating: true })
this.props.sequence[this.props.itemIndex].animating = true
TweenMax.fromTo(
el,
this.props.animation.out.time,
Expand All @@ -98,9 +91,9 @@ const MetroHoc = Component =>
'out'
)
) {
this.setState({ animating: false })
this.props.onUnmount && this.props.onUnmount()
}
this.props.sequence[this.props.itemIndex].animating = false
callback()
}, leftOver * 1000)
}
Expand All @@ -116,7 +109,7 @@ const MetroHoc = Component =>
</this.props.wrapperType>
) : (
<div ref={c => (this.container = c)}>
<Component {...this.props} animating={this.state.animating} />
<Component {...this.props} />
</div>
)
}
Expand Down
5 changes: 3 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,15 @@ const metroAnimation = MetroHoc(
return (
<div
onClick={() => {
const animating = this.props.sequence.some(s => s.animating)
if (
this.props.onClick &&
(!this.props.animating || this.props.enableClickDuringAnimation)
(!animating || this.props.enableClickDuringAnimation)
) {
this.props.onClick(
this.props.content,
this.props.itemIndex,
this.props.animating
animating
)
}
}}
Expand Down

0 comments on commit c83f988

Please sign in to comment.