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

Signature_pad Problem in Mobile #318

Closed
amine-damani opened this issue Nov 10, 2017 · 17 comments
Closed

Signature_pad Problem in Mobile #318

amine-damani opened this issue Nov 10, 2017 · 17 comments

Comments

@amine-damani
Copy link

Hello, I have made an Web site by using your library, so I would like to say Thank u for making this library.
Now the problem is that when we draw signature and move finger up or down, out of pad the signature is
removed

@szimek
Copy link
Owner

szimek commented Nov 10, 2017

I'm not 100% sure why it happens, but most likely you're listening to resize event, right? You can add some logging there to see if it's fired when you scroll the screen.

If it is fired on scroll, then you can listen to other events like orientationchange, which won't be triggered when scrolling. Or you can check the solution proposed here: https://stackoverflow.com/a/24212316/261673.

Let me know if it helps.

@amine-damani
Copy link
Author

not in resize, i draw signature and move finger up or down, out of pad the signature is removed.
Look this : https://youtu.be/k-W2Y4KKU04

@szimek
Copy link
Owner

szimek commented Nov 10, 2017

But the code in the demo page is listening to resize event and when it happens it resizes the canvas, which causes it be cleared.

You can fix it in these 2 ways I mentioned:

  • listen to orientationchange event instead of resize
  • check if width has actually changed when resize even is fired and don't do anything if it hasn't

@amine-damani
Copy link
Author

Thank you @szimek for your help
it's work fine. 👍

@santosh-btc
Copy link

@zoldek As I understand, as per the docs browser will clear the canvas on resize event automatically. Now even i have replaced the resize with orientationchange it is still not working. I doubt that when we scroll up in mobile it actually move the address bar in and which could fire the resize event, is it possible?

It's not working for me on iPhone 7+, can you please put some more light what steps you followed to fix this?

@szimek
Copy link
Owner

szimek commented Nov 16, 2017

@santosh-btc Could you add console.log call to your resize or orientationchange event handler and see to see if it's triggered when scrolling? This should tell you when your handler is executed.

@santosh-btc
Copy link

@szimek "resize" event execute when scrolling.

@szimek
Copy link
Owner

szimek commented Nov 16, 2017

@santosh-btc So if orientationchange event is not fired on scrolling, move your canvas resize logic there. It should fix your problem.

@ParthBarot-BoTreeConsulting

@szimek I think what @santosh-btc is mentioning is related to the other library which we are using for ReactJS frontend. It is mentioned there that A signature pad implementation for react., but when we reviewed the internal code we found it is not using your library.

Though, if you have any suggestions on it, would be great. I have raised an issue in there.

@amine-damani
Copy link
Author

Hi @santosh-btc
Try this :

var windowWidth = $(window).width();
$(window).resize(function(){
if ($(window).width() != windowWidth) {
window.onresize = resizeCanvas;
resizeCanvas();
}
});
window.orientation = resizeCanvas;
resizeCanvas();

It works for me
when you in the phone listen to orientationchange
when you in the desktop listen to onresize

@ParthBarot-BoTreeConsulting

@zoldek Yep, got the same thing, updated the other issue as well. Basically now we need to identify if the device is mobile or not. Can we do that just by window.width and comparing it against actual device sizes?

@amine-damani
Copy link
Author

@ParthBarot-BoTreeConsulting what's your problem exactly ?

@ParthBarot-BoTreeConsulting
Copy link

ParthBarot-BoTreeConsulting commented Nov 17, 2017

@zoldek The problem is, I need my ReactJS app to work diff. in Web vs Mobile, and I am using https://github.com/blackjk3/react-signature-pad . - As you mentioned it needs to register for diff. events. I am thinking of doing it by checking the window width, like,

...
if(window.width() > 300){ //This will be compared with multiple screen width/height sizes to ensure its web.
  window.addEventListener('resize', function(){ ... });
} else {
    window.addEventListener('orientationchange', function(){ ... });
}

Any ideas?

@amine-damani
Copy link
Author

amine-damani commented Nov 17, 2017

if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
window.addEventListener('orientationchange', function(){ ... });
}
else {
window.addEventListener('resize', function(){ ... });
}

@karan4364
Copy link

@zoldek Thanks. Your solution is worked for me. You saved my day.

@thienban
Copy link

thienban commented Sep 14, 2018

Hi, I'm using React JS for a Mobile App,
My issue is to display the Image from toDataURL.
I trigger the addEventListener in componentDidMount and Remove event listener in componentWillUnmount
But, it doesn't change anything.

componentDidMount() { if(canvas != null){ window.addEventListener('orientationchange', resizeCanvas(canvas)); } } componentWillUnmount() { if(canvas != null){ window.addEventListener('orientationchange', resizeCanvas(canvas)); } }

My images
signature1
signature2

Can you explain how to trigger the addEventListener ? please SOLVED

I solved by :

componentDidUpdate() {
canvas = document.querySelector("canvas");
if(canvas) {
signaturePad = new SignaturePad(canvas);
window.addEventListener('orientationchange', this.resizeCanvas(canvas));
if(this.state.isSigning) {
if(this.state.signatureImage)
signaturePad.fromData(this.state.signatureImage);
}
}
}

@Satya3999
Copy link

Hello there!

I'm using your library to create a signature on my website and retrieving the data in CRM. Everything works fine except for signature pad JavaScript is creating too many characters when I sign the form using my mobile application, which is in turn causing some performance issues when submitting the form, is there any way that I can reduce/restrict the number of character created by signature pad when using it in mobile application.

Thanks,
Satya

@UziTech UziTech closed this as completed Jun 18, 2021
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

8 participants