Skip to content
Browse files

add current page as snap option while swiping with page component

  • Loading branch information
J.P.P Treub J.P.P Treub
J.P.P Treub authored and J.P.P Treub committed Jul 21, 2015
1 parent a80a61c commit c181296cbabf41d432a5b90beadacf5778fae832
Empty file.
@@ -42,21 +42,25 @@ class exports.PageComponent extends ScrollComponent
@define "currentPage", get: -> _.last(@_previousPages)
@define "previousPage", get: -> @_previousPages[@_previousPages.length-2]

nextPage: (direction="right", currentPage=null) ->
nextPage: (direction="right", currentPage=null, withoutCurrentPage=true) ->

currentPage ?= @currentPage

# Figure out the point from where to look for next layers in a direction
point = {x:0, y:0}
point = Utils.framePointForOrigin(currentPage, @originX, @originY) if currentPage
if !withoutCurrentPage
point = {x:@scrollX + (@originX * @width), y:@scrollY + (@originY * @height)}

layers = @content.subLayersAbove(point, @originX, @originY) if direction in ["up", "top", "north"]
layers = @content.subLayersBelow(point, @originX, @originY) if direction in ["down", "bottom", "south"]
layers = @content.subLayersLeft(point, @originX, @originY) if direction in ["left", "west"]
layers = @content.subLayersRight(point, @originX, @originY) if direction in ["right", "east"]

# See if there is one close by that we should go to
layers = _.without(layers, currentPage)
if withoutCurrentPage
layers = _.without(layers, currentPage)

layers = Utils.frameSortByAbsoluteDistance(point, layers, @originX, @originY)

return _.first(layers)
@@ -166,7 +170,7 @@ class exports.PageComponent extends ScrollComponent

# Figure out which direction we are scrolling to and make a sorted list of
# layers on that side, sorted by absolute distance so we can pick the first.
nextPage = @nextPage(@direction, @_currentPage)
nextPage = @nextPage(@direction, @_currentPage, false)

# If not, we scroll to the closest layer that we have available, often the one
# that we are already at.

Some generated files are not rendered by default. Learn more.

0 comments on commit c181296

Please sign in to comment.
You can’t perform that action at this time.