Skip to content

Commit

Permalink
Merge pull request #291 from koenbok/gestures
Browse files Browse the repository at this point in the history
Gestures refactor to layer.gestures
  • Loading branch information
koenbok committed Jan 17, 2016
2 parents 27b7647 + a93c529 commit 42de49f
Show file tree
Hide file tree
Showing 42 changed files with 821 additions and 273 deletions.
9 changes: 9 additions & 0 deletions framer/Context.coffee
Expand Up @@ -89,6 +89,7 @@ class exports.Context extends BaseClass
@_layers = _.without(@_layers, layer)

resetLayers: ->
@resetGestures()
@_layers = []
@_layerCounter = 0

Expand Down Expand Up @@ -141,6 +142,14 @@ class exports.Context extends BaseClass
@_intervals.map(window.clearInterval) if @_intervals
@_intervals = []

# Gestures
resetGestures: ->
return unless @_layers
for layer in @_layers
if layer._gestures
layer._gestures.destroy()

return

##############################################################
# Run
Expand Down
11 changes: 2 additions & 9 deletions framer/DOMEventManager.coffee
Expand Up @@ -9,21 +9,14 @@ EventManagerIdCounter = 0
class DOMEventManagerElement extends EventEmitter

constructor: (@element) ->
@_elementGestureManager = new GestureManagerElement(@element)

addListener: (eventName, listener, capture=false) ->
super(eventName, listener)
if Events.isGestureEvent eventName
@_elementGestureManager.addEventListener(eventName, listener, capture)
else
@element.addEventListener(eventName, listener)
@element.addEventListener(eventName, listener, false)

removeListener: (eventName, listener) ->
super(eventName, listener)
if Events.isGestureEvent eventName
@_elementGestureManager.removeEventListener(eventName, listener)
else
@element.removeEventListener(eventName, listener)
@element.removeEventListener(eventName, listener, false)

# Keep the DOM API working
addEventListener: @::addListener
Expand Down
49 changes: 0 additions & 49 deletions framer/Events.coffee
Expand Up @@ -35,62 +35,13 @@ Events.AnimationDidStart = "start"
Events.AnimationDidStop = "stop"
Events.AnimationDidEnd = "end"

# Gesture events
_gestures = []

# Pan
_gestures.push Events.Pan = "pan" # This event includes all the other Pan events
_gestures.push Events.PanStart = "panstart"
_gestures.push Events.PanMove = "panmove"
_gestures.push Events.PanEnd = "panend"
_gestures.push Events.PanCancel = "pancancel"
_gestures.push Events.PanLeft = "panleft"
_gestures.push Events.PanRight = "panright"
_gestures.push Events.PanUp = "panup"
_gestures.push Events.PanDown = "pandown"

# Pinch
_gestures.push Events.Pinch = "pinch" # This event includes all the other Pinch events
_gestures.push Events.PinchStart = "pinchstart"
_gestures.push Events.PinchMove = "pinchmove"
_gestures.push Events.PinchEnd = "pinchend"
_gestures.push Events.PinchCancel = "pinchcancel"
_gestures.push Events.PinchIn = "pinchin"
_gestures.push Events.PinchOut = "pinchout"

# Press
_gestures.push Events.Press = "press"
_gestures.push Events.PressUp = "pressup"

# Rotate
_gestures.push Events.Rotate = "rotate" # This event includes all the other Rotate events
_gestures.push Events.RotateStart = "rotatestart"
_gestures.push Events.RotateMove = "rotatemove"
_gestures.push Events.RotateEnd = "rotateend"
_gestures.push Events.RotateCancel = "rotatecancel"

# Swipe
_gestures.push Events.Swipe = "swipe"
_gestures.push Events.SwipeLeft = "swipeleft"
_gestures.push Events.SwipeRight = "swiperight"
_gestures.push Events.SwipeUp = "swipeup"
_gestures.push Events.SwipeDown = "swipedown"

# Tap
_gestures.push Events.Tap = "tap"
_gestures.push Events.SingleTap = "singletap"
_gestures.push Events.DoubleTap = "doubletap"

# Scroll events
Events.Scroll = "scroll"

# Image events
Events.ImageLoaded = "load"
Events.ImageLoadError = "error"

Events.isGestureEvent = (eventName) ->
return eventName in _gestures

# Extract touch events for any event
Events.touchEvent = (event) ->
touchEvent = event.touches?[0]
Expand Down
1 change: 1 addition & 0 deletions framer/Framer.coffee
Expand Up @@ -10,6 +10,7 @@ Framer.Layer = (require "./Layer").Layer
Framer.BackgroundLayer = (require "./BackgroundLayer").BackgroundLayer
Framer.VideoLayer = (require "./VideoLayer").VideoLayer
Framer.Events = (require "./Events").Events
Framer.Gestures = (require "./Gestures").Gestures
Framer.Animation = (require "./Animation").Animation
Framer.AnimationGroup = (require "./AnimationGroup").AnimationGroup
Framer.Screen = (require "./Screen").Screen
Expand Down

0 comments on commit 42de49f

Please sign in to comment.