Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Extending ScrollComponent.wrap to (optionally) take constructor options.
- Loading branch information
|
@@ -376,12 +376,12 @@ class exports.ScrollComponent extends Layer |
|
|
############################################################## |
|
|
# Convenience function to make a single layer scrollable |
|
|
|
|
|
@wrap = (layer) -> |
|
|
@wrap = (layer, options = {}) -> |
|
|
|
|
|
# This function wraps the given layer into a scroll or page component. This is |
|
|
# great for importing from Sketch or Photoshop. |
|
|
|
|
|
scroll = new @ |
|
|
scroll = new @(options) |
|
|
|
|
|
for propKey in ["frame", "image", "name"] |
|
|
scroll[propKey] = layer[propKey] |
|
|
|
|
@@ -1,3 +1,5 @@ |
|
|
expect = chai.expect |
|
|
|
|
|
describe "ScrollComponent", -> |
|
|
|
|
|
it "should apply constructor options", -> |
|
@@ -12,4 +14,20 @@ describe "ScrollComponent", -> |
|
|
instance.scrollHorizontal.should.be.false |
|
|
|
|
|
copy = instance.copy() |
|
|
copy.scrollHorizontal.should.be.false
|
|
|
copy.scrollHorizontal.should.be.false |
|
|
|
|
|
describe "wrap", -> |
|
|
|
|
|
it "should forward constructor options", -> |
|
|
options = |
|
|
scrollVertical: false |
|
|
mouseWheelEnabled: true |
|
|
name: "is a name" |
|
|
|
|
|
# 'wrap' ports the 'name' of the layer onto the ScrollComponent |
|
|
layer = new Layer name: options.name |
|
|
layer.name.should.equal(options.name) |
|
|
|
|
|
scroller = ScrollComponent.wrap layer, options |
|
|
for key in _.keys options |
|
|
expect(scroller[key]).to.equal(options[key]) |