Skip to content

Commit

Permalink
Fix directionLock issues on mobile
Browse files Browse the repository at this point in the history
  • Loading branch information
Koen Bok committed Apr 2, 2015
1 parent 9da6ec3 commit 705a6d1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
15 changes: 9 additions & 6 deletions framer/LayerDraggable.coffee
Expand Up @@ -370,11 +370,14 @@ class exports.LayerDraggable extends BaseClass
@_directionLockEnabledX = Math.abs(correctedDelta.y) > @directionLockThreshold.y
@_directionLockEnabledY = Math.abs(correctedDelta.x) > @directionLockThreshold.x

xSlightlyPreferred = Math.abs(correctedDelta.y) > @directionLockThreshold.y / 2
ySlightlyPreferred = Math.abs(correctedDelta.x) > @directionLockThreshold.x / 2
# TODO: This wasn't working as advertised. We shouls have a way to scroll diagonally
# if we were sort of moving into both directions equally.

# Allow locking in both directions at the same time
@_directionLockEnabledX = @_directionLockEnabledY = true if (xSlightlyPreferred and ySlightlyPreferred)
# xSlightlyPreferred = Math.abs(correctedDelta.y) > @directionLockThreshold.y / 2
# ySlightlyPreferred = Math.abs(correctedDelta.x) > @directionLockThreshold.x / 2

# # Allow locking in both directions at the same time
# @_directionLockEnabledX = @_directionLockEnabledY = true if (xSlightlyPreferred and ySlightlyPreferred)

if @_directionLockEnabledX or @_directionLockEnabledY
@emit Events.DirectionLockDidStart,
Expand Down Expand Up @@ -427,8 +430,8 @@ class exports.LayerDraggable extends BaseClass

_onSimulationStep: (axis, state) =>

return if axis is "x" and (@_directionLockEnabledX or @horizontal is false)
return if axis is "y" and (@_directionLockEnabledY or @vertical is false)
return if axis is "x" and @horizontal is false
return if axis is "y" and @vertical is false

# The simulation state has x as value, it can look confusing here
# as we're working with x and y.
Expand Down
8 changes: 7 additions & 1 deletion test/studio/PageComponentLockDirection.framer/app.coffee
Expand Up @@ -8,7 +8,7 @@ page = new PageComponent
page.scrollVertical = false
page.directionLock = true

for index in [0..8]
for index in [0..2]

pageContent = new ScrollComponent
width: page.width
Expand All @@ -20,6 +20,9 @@ for index in [0..8]
pageContent.scrollHorizontal = false
pageContent.directionLock = true

page.on Events.DirectionLockDidStart, (direction) ->
print "pageContent.DirectionLockDidStart", direction

rows = 10
gutter = 2
height = 200
Expand All @@ -39,3 +42,6 @@ for index in [0..8]
"text-align": "center"
"line-height": "#{cellLayer.height}px"


page.on Events.DirectionLockDidStart, (direction) ->
print "page.DirectionLockDidStart", direction

0 comments on commit 705a6d1

Please sign in to comment.