react-native-signature-canvas icon indicating copy to clipboard operation
react-native-signature-canvas copied to clipboard

Load Base64 signature

Open ugar0ff opened this issue 3 years ago • 9 comments

Good Day! How I can load previous saved signature in Signature view?

ugar0ff avatar Jul 13 '21 11:07 ugar0ff

image dataURL

YanYuanFE avatar Jul 13 '21 14:07 YanYuanFE

Keep in mind if you have a base64 string of a random image, you'll need to prepend 'data:image/png;base64,' to the beginning of the dataURL value (i.e. dataURL=data:image/png;base64,${base64string})

leneti avatar Jul 13 '21 14:07 leneti

Thanks! It is work, but in code I have error: Снимок экрана от 2021-08-08 00-36-05

ugar0ff avatar Aug 07 '21 21:08 ugar0ff

I've amended it in my pull request. As soon as it's merged it should no longer be an issue

leneti avatar Aug 11 '21 08:08 leneti

I've amended it in my pull request. As soon as it's merged it should no longer be an issue

thanks, 4.3.0 released.

YanYuanFE avatar Aug 11 '21 09:08 YanYuanFE

hey, @YanYuanFE I am still struggling with setting the previous signature. I am able to set the previous signature one time but for next time for another user, it still not getting updated. there is a state passed to the prop dataURL. will you please help me with that? My local state is getting updated but not the signature screen.

YumTheDeathGod avatar Oct 22 '21 05:10 YumTheDeathGod

@YumTheDeathGod did you get the solution? Please help if you got that

SyedUmair282 avatar Feb 20 '22 15:02 SyedUmair282

dataURL is not working for android, it works for ios. Any resolution?

carlgrob517 avatar Mar 15 '22 07:03 carlgrob517

Hey @SyedUmair282 sorry for late reply! but still I will try to answer the question if someone else is needed. In my case I have used the useFocusEffect from @react-navigation/native with useCallback hook. These hooks will be executed whenever the component is in focus.

For your reference:

  useFocusEffect(
    useCallback(() => {
              webviewRef.current.injectJavaScript(
                getInjectableJSMessage({
                  message: casenote.formData.signature_data,
                  triggeredAt: new Date(),
                })
    }, [props])
  );

here weviewRef is ref of signature canvas. And with the help of getInjectableJSMessage prop of signature canvas injected that data stream (base64 data). Inside my source prop i have used a listner eg. :

                          document.addEventListener("message", handleEvent);
                                        function handleEvent(message) {                                            
                                            
                                            const sign_data = message;
                                            signaturePad.clear();
                                            if(sign_data.data.message.length > 0) {
                                                signaturePad.fromDataURL(sign_data.data.message, {
                                                    ratio: "350/70",
                                                    width: 350,
                                                    height: 70
                                                });                                          
                                            }
                                        }

Hope it will help someone.

YumTheDeathGod avatar Mar 18 '22 04:03 YumTheDeathGod