Skip to content
Permalink
Browse files

Improve PageComponent.wrap() (#370)

  • Loading branch information...
eelco committed Jun 30, 2016
1 parent 340612e commit b0322414764b0458c9161e173605ede73b2a6c37
@@ -37,4 +37,3 @@ app.js
framer/images/*
framer/framer*.js
framer/framer*.js.map
imported
Binary file not shown.
@@ -0,0 +1,28 @@
[
{
"objectId": "41200C5F-397F-4ED6-BA30-E08AE1DD7F6C",
"kind": "group",
"name": "main",
"maskFrame": null,
"layerFrame": {
"x": 0,
"y": 0,
"width": 375,
"height": 1000
},
"visible": true,
"metadata": {
"opacity": 1
},
"image": {
"path": "images/Layer-main-ndeymdbd.png",
"frame": {
"x": 0,
"y": 0,
"width": 375,
"height": 1000
}
},
"children": []
}
]
@@ -0,0 +1,29 @@
window.__imported__ = window.__imported__ || {};
window.__imported__["test@2x/layers.json.js"] = [
{
"objectId": "41200C5F-397F-4ED6-BA30-E08AE1DD7F6C",
"kind": "group",
"name": "main",
"maskFrame": null,
"layerFrame": {
"x": 0,
"y": 0,
"width": 375,
"height": 1000
},
"visible": true,
"metadata": {
"opacity": 1
},
"image": {
"path": "images/Layer-main-ndeymdbd.png",
"frame": {
"x": 0,
"y": 0,
"width": 375,
"height": 1000
}
},
"children": []
}
]
@@ -140,7 +140,7 @@ class exports.ScrollComponent extends Layer
# call it yourself, but make sure you don't overdo it.

return unless @content

contentFrame = @calculateContentFrame()
@content.width = contentFrame.width
@content.height = contentFrame.height
@@ -228,9 +228,9 @@ class exports.ScrollComponent extends Layer
_.clone(@_contentInset)
set: (contentInset) ->
@_contentInset = Utils.rectZero(Utils.parseRect(contentInset))

return unless @content

# If we reset the content inset, we need to reset the content position
contentFrame = @calculateContentFrame()
contentFrame.x = contentFrame.x + @_contentInset.left
@@ -410,14 +410,19 @@ wrapComponent = (instance, layer, options = {correct:true}) ->

scroll = instance

# Do some special case handling for the PageComponent subclass
# as this function is outside of the class scope so we can’t simply
# override
isPageComponent = instance.constructor.name is "PageComponent"

# If we actually forgot to add a sub layer, so for example if
# there is just one layer and we want to make it scrollable we
# correct that here.

if options.correct is true
if layer.children.length is 0
if layer.children.length is 0 and not isPageComponent
wrapper = new Layer
wrapper.name = "ScrollComponent"
wrapper.name = instance.constructor.name
wrapper.frame = layer.frame
layer.parent = wrapper
layer.x = layer.y = 0
@@ -431,7 +436,9 @@ wrapComponent = (instance, layer, options = {correct:true}) ->

# Copy over the name, if we don't have it try to use the variable
# name from Framer Studio if it was given.
if layer.name and layer.name isnt ""
if isPageComponent
scroll.name = instance.constructor.name
else if layer.name and layer.name isnt ""
scroll.name = layer.name
else if layer.__framerInstanceInfo?.name
scroll.name = layer.__framerInstanceInfo.name
@@ -440,15 +447,15 @@ wrapComponent = (instance, layer, options = {correct:true}) ->
# background of the wrapper then the content.
# Note: I ran into a situation where this had a weird result, maybe
# we should revise this in the future.
if layer.image
if layer.image and not isPageComponent
scroll.image = layer.image
layer.image = null

# Set the original layer as the content layer for the scroll
if instance.constructor.name is "PageComponent"
for l in layer.children
scroll.addPage(l)
if isPageComponent
# Just add the layer as a page
scroll.addPage(layer)
else
# Set the original layer as the content layer for the scroll
scroll.setContentLayer(layer)

# https://github.com/motif/Company/issues/208

0 comments on commit b032241

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