Skip to content

Instantly share code, notes, and snippets.

@lonekorean
Last active March 3, 2018 13:58
Show Gist options
  • Save lonekorean/85f5712f3da634453c847276db1160d8 to your computer and use it in GitHub Desktop.
Save lonekorean/85f5712f3da634453c847276db1160d8 to your computer and use it in GitHub Desktop.
Paint worklet for placeholder box that uses input properties
class PlaceholderBoxPropsPainter {
static get inputProperties() {
return ['border-top-width', 'border-top-color'];
}
paint(ctx, size, props) {
// default values
ctx.lineWidth = 2;
ctx.strokeStyle = '#666';
// set line width to top border width (if exists)
let borderTopWidthProp = props.get('border-top-width');
if (borderTopWidthProp) {
ctx.lineWidth = borderTopWidthProp.value;
}
// set stroke style to top border color (if exists)
let borderTopColorProp = props.get('border-top-color');
if (borderTopColorProp) {
ctx.strokeStyle = borderTopColorProp.toString();
}
// same drawing code as before goes here...
}
}
registerPaint('placeholder-box-props', PlaceholderBoxPropsPainter);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment