Divide by zero bug
Aryk opened this issue · comments
If you open the cropper before the image is fully loaded in, you will get this error.
It's because you are dividing zero by zero.
this.actualSize = {
width: 0,
height: 0,
}
You set that on constructor...so if that doesn't get changed, things will blow up.
Basically you can't launch the cropper until +onConvertImageToEditableSize+ finishes...
So I had to fix it by:
// @aryk I direct copy/paste from the library except for one line added...
async onConvertImageToEditableSize() {
// @ts-ignore
const { photo: { uri: rawUri } } = this.props;
RNImage.getSize(rawUri, async (imgW, imgH) => {
// @ts-ignore
const { convertedWidth, convertedheight } = this.onGetCorrectSizes(imgW, imgH);
const { uri, width: w, height } = await ImageManipulator.manipulateAsync(rawUri,
[
{
resize: {
width: convertedWidth,
height: convertedheight,
},
},
]);
// @ts-ignore
this.setState({
uri,
});
// @ts-ignore
this.actualSize.width = w;
// @ts-ignore
this.actualSize.height = height;
// @ts-ignore
if (this.props.onReady) this.props.onReady(); // this line added
}, handleError);
}
Excuse the Typescript ignores...
Basically I added:
if (this.props.onReady) this.props.onReady(); // this line added
So I put a callback that lets me know when I can actually launch the cropper...there is a 2 second delay about...
I am trying to open the cropper by default without click on the crop button.. I am getting the same error.
if (this.props.onReady) this.props.onReady(); // this line added
I have added this line but this is not working. Is there any way to open the dragable cropper by default?
oh, I made mine open the cropper by default, I don't remember well how I did it, but you can take a look here. Hope this helps