Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can’t set ShapePath to type `Custom` #466

Open
KevinGutowski opened this Issue Apr 13, 2019 · 1 comment

Comments

Projects
None yet
3 participants
@KevinGutowski
Copy link
Contributor

commented Apr 13, 2019

let sketch = require('sketch’)
let ShapePath = sketch.ShapePath
const test = new ShapePath({
  shapeType: ShapePath.ShapeType.Custom
})
console.log(test.shapeType)
// returns 'Rectangle’ not 'Custom'

Moreover, the documentation is incorrect https://developer.sketch.com/reference/api/#create-a-new-shapepath

const shapePath = new ShapePath({
  name: 'my shape path',
  shapePath: ShapePath.ShapeType.Oval,
})

// should be

const shapePath = new ShapePath({
  name: 'my shape path',
  shapeType: ShapePath.ShapeType.Oval,
})

Updated the documentation in #467


More info on ShapePath

Looks like if a ShapeType is set to Custom then it gets defaulted to Rectangle. This isn’t good if you want to try and make a Line object.

const ShapeTypeMapReverse = {
  Rectangle: MSRectangleShape,
  Oval: MSOvalShape,
  Polygon: MSPolygonShape,
  Star: MSStarShape,
  Triangle: MSTriangleShape,
  Custom: MSRectangleShape, // we are just going to default to Rectangle here
}

However, even if you were able to change this and get the ShapeType to custom Custom it still doesn’t quite behave like a line that you draw with the line tool. Here is an example where I try to do that:

let shapePathLayer = MSShapePathLayer.alloc().init()
let myLine = sketch.fromNative(shapePathLayer)
console.log(myLine.shapeType)
// 'Custom'
myLine.name = 'myLine'
myLine.frame = new Rectangle(0,0,40,100)
myLine.style = { borders: ['#FF0000'] }
myLine.points = [{ point: { x: 0, y: 0 }},{ point: { x: 1, y: 1 }}]
myLine.parent = myArtboard

Currently, the workaround that I have with creating a line is this:

var path = NSBezierPath.bezierPath()
path.moveToPoint(NSMakePoint(10,10))
path.lineToPoint(NSMakePoint(400,200))
var nativeLine = MSShapeGroup.layerWithPath(MSPath.pathWithBezierPath(path))

let lineShape = sketch.fromNative(nativeLine)
let line = lineShape.layers[0]
line.parent = myArtboard
line.style = { borders: ['#FF0000'] }
@mathieudutour

This comment has been minimized.

Copy link
Contributor

commented Apr 15, 2019

So you can create an object that behave like a Line this this:

let myLine = new sketch.ShapePath({
  name: 'myLine',
  frame: {x: 10, y: 0, width: 40, height: 100},
  style: { borders: ['#FF0000'] },
  points: [{ point: { x: 0, y: 0 }, pointType: 'Straight'}, { point: { x: 1, y: 1 }, pointType: 'Straight'}],
  parent: myArtboard,
  closed: false
})

It will show the wrong ShapeType for now but will behave correctly. Note the pointType and closed property.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.