Skip to content

Commit

Permalink
Add AnimationBreak event
Browse files Browse the repository at this point in the history
An event that only emits when an animation is stopped before it fully finished.
  • Loading branch information
koenbok committed Nov 8, 2016
1 parent 7de77b6 commit 56a6d73
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion framer/Animation.coffee
Expand Up @@ -154,6 +154,7 @@ class exports.Animation extends BaseClass

# Add the callbacks
@on(Events.AnimationStart, @options.onStart) if _.isFunction(@options.onStart)
@on(Events.AnimationBreak, @options.onBreak) if _.isFunction(@options.onBreak)
@on(Events.AnimationStop, @options.onStop) if _.isFunction(@options.onStop)
@on(Events.AnimationEnd, @options.onEnd) if _.isFunction(@options.onEnd)

Expand Down Expand Up @@ -192,7 +193,7 @@ class exports.Animation extends BaseClass
@_delayTimer = null

@layer.context.removeAnimation(@)

@emit(Events.AnimationBreak) if emit
@emit(Events.AnimationStop) if emit
Framer.Loop.off("update", @_update)

Expand Down
1 change: 1 addition & 0 deletions framer/Events.coffee
Expand Up @@ -36,6 +36,7 @@ Events.Click = Events.TouchEnd

# Animation events
Events.AnimationStart = "start"
Events.AnimationBreak = "break"
Events.AnimationStop = "stop"
Events.AnimationEnd = "end"

Expand Down
10 changes: 10 additions & 0 deletions test/tests/LayerAnimationTest.coffee
Expand Up @@ -698,6 +698,16 @@ describe "LayerAnimation", ->
layer.x.should.eql 0
done()

it "should call break", (done) ->
layer = new Layer
layer.animate
x: 100
options:
time: 0.1
onBreak: ->
done()
layer.animateStop()

it "should call stop", (done) ->
layer = new Layer
layer.animate
Expand Down

0 comments on commit 56a6d73

Please sign in to comment.