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

Have the option of making the sketchfield resize on other events than window resize #7

Closed
FerusAndBeyond opened this issue Sep 24, 2016 · 5 comments

Comments

@FerusAndBeyond
Copy link

I wanted to have a resizable sketch field but when I resize it (change height and width props of SketchField) the canvas stays the same size. To make it work I had to manually trigger the resize event of window. Like this:

    componentDidUpdate: function () {
        var sketch = this.refs.sketch;
        var style = this.props.style;
        if (style.width !== sketch._canvas.clientWidth || style.height !== sketch._canvas.clientHeight) {
            window.dispatchEvent(new Event("resize"));
        }
    },
@tbolis
Copy link
Owner

tbolis commented Sep 29, 2016

Dear @FerusAndBeyond thank you for your input, I have resolved the issue by adding controlled properties width and height, please check if possible and let me know if it is ok, you can see the example page as well.

@tbolis tbolis closed this as completed Sep 29, 2016
@FerusAndBeyond
Copy link
Author

FerusAndBeyond commented Sep 29, 2016

Changing width and height works perfectly now, thanks! Though unless I did something wrong I noticed 2 issues when height and width are not specified. The height is set to 512 by this statement:

let canvasDivStyle = Object.assign({}, style ? style : {}, width ? {width: width} : {}, height ? {height: height} : {height: 512});

Changing {height:512} to {} removed this issue. Also in the configuration options it says if you leave height/width empty it will scale to parent but that does not seem to be the case for me.

@tbolis
Copy link
Owner

tbolis commented Sep 29, 2016

Yes you are right, I have added a reasonable default value for height, I will correct the documentation. The other option would be to leave it blank and will automatically scale to parent height as well, but this would mean that to use the component you would have to be careful to strictly define the parent height.
Besides you can achieve the controlled width and height by supporting it with your own code as a controlled component (with higher order composition etc.)

Hope it helps

@FerusAndBeyond
Copy link
Author

Yes I understand, I was just confused by the documentation.

@tbolis
Copy link
Owner

tbolis commented Sep 29, 2016

Cool thx, hope you like the new feature/bug fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants