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

removeEventListener() #86

Open
myselfyy opened this issue Nov 1, 2018 · 11 comments
Open

removeEventListener() #86

myselfyy opened this issue Nov 1, 2018 · 11 comments

Comments

@myselfyy
Copy link

myselfyy commented Nov 1, 2018

Hello, iddan, when I unMount my component, I get the error : "ExceptionsManager.js:65 Error: Image must be initialized with a Canvas instance".I think we should remove the Image load listener when I unmount the component in the ComponentWillUnMount function, but I dot't know how to do it,please give me a favor,thanks a lot!

@iddan
Copy link
Owner

iddan commented Nov 2, 2018

Hey! Can you share your code so I could give an advice?

@myselfyy
Copy link
Author

myselfyy commented Nov 5, 2018

Yes!
The code is :

componentWillUnmount() {
       this.image.removeEventListener('load', this.renderImage);
       // window.removeEventListener('load', this.handleImageRect);
   }
   handleImageRect = (canvas) => {
       this.image = new CanvasImage(canvas);
       canvas.width = 312;
       canvas.height = 413;
       const context = canvas.getContext('2d');
       const that = this;
       this.image.src = 'https://image.freepik.com/free-vector/unicorn-background-design_1324-79.jpg';
       this.image.addEventListener('load', () => {
           context.drawImage(this.image, 0, 0, 312, 413);
           context.fillStyle = 'black';
           context.font = 13 + 'px PingFangSC-Regular';
           context.fillText('二零一八年 九月', 22, 30);
           context.font = 62 + 'px Didot';
           context.fillText('28', 22, 90);
           context.font = 62 + 'px Didot';
           context.fillText('一', 22, 150);
           context.font = 13 + 'px PingFangSC-Regular';
           context.fillText('我的金额:320', 22, 180);
           context.font = 13 + 'px PingFangSC-Regular';
           context.fillText('这是一条签语,预计可以放下二十八个汉字', 22, 300);
           context.font = 13 + 'px PingFangSC-Regular';
           context.fillText('---作者', 250, 330);
           const that = this;
           console.log('888', this.image);
           canvas.toDataURL('image/png').then((testImg) => {
               this.setState({
                   testImg: testImg
               })
           })
       });
   }
   render() {
       return <Canvas ref={this.handleImageRect} />
   }

11
22

when click the topLeft button , componentUnmounted, but the 'load' listener is always presence

@iddan
Copy link
Owner

iddan commented Nov 5, 2018

It seems like removeEventListener() implementation is missing. It should be added here:

target.prototype.addEventListener = function(type, callback) {

@iddan iddan added the bug label Nov 5, 2018
@iddan iddan changed the title ExceptionsManager.js:65 Error: Image must be initialized with a Canvas instance removeEventListener is not implemented Nov 5, 2018
@iddan iddan changed the title removeEventListener is not implemented removeEventListener() Nov 5, 2018
@myselfyy
Copy link
Author

myselfyy commented Nov 5, 2018

OK, thanks a lot!
When do you update the removeEventListener function?

@iddan
Copy link
Owner

iddan commented Nov 6, 2018

I'm not available to do this currently but very willing to guide for a PR.

@myselfyy
Copy link
Author

myselfyy commented Nov 9, 2018

OK!
Tanks a lot!

@SiJieMa
Copy link

SiJieMa commented Jan 8, 2019

I had the same problem.

@SiJieMa
Copy link

SiJieMa commented Jan 9, 2019

Hi iddan!You write so cool code ,but I can't understand it quickly.
My question is: Why is the component uninstalled and canvas. JS still running?
I hope you can solve this removeEventListene() bug.THANKS!

@iddan
Copy link
Owner

iddan commented Jan 9, 2019

Hey SiJieMa, thank you for using React Native Canvas. Currently, the implementation misses a definition for the removeEventListener(). To implement it you should mimic the implementation of addEventListener(). As said before: I'm not available to do this currently but very willing to guide for a PR.

@SiJieMa
Copy link

SiJieMa commented Jan 10, 2019

Okay, I'll try to solve this problem these days.

@sergey-kompaniets
Copy link

sergey-kompaniets commented Jul 3, 2019

@myselfyy, @SiJieMa, How did you solve this problem?

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

No branches or pull requests

4 participants