-
Notifications
You must be signed in to change notification settings - Fork 153
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
Not work on android #371
Comments
news? |
any update? |
Not wroked for me because my signature canva was wrap into touchablewithoutfeedback |
I was running into the same issue using RN 0.76.5 with the new arch enabled. The problem also relies on
Here is the solution, first add a safe check to I created the following diff with
diff --git a/node_modules/react-native-signature-canvas/h5/js/app.js b/node_modules/react-native-signature-canvas/h5/js/app.js
index e4690cd..8f16939 100755
--- a/node_modules/react-native-signature-canvas/h5/js/app.js
+++ b/node_modules/react-native-signature-canvas/h5/js/app.js
@@ -22,12 +22,22 @@ export default `
imgData && signaturePad.fromData(imgData);
}
+ function safePostMessage(data) {
+ setTimeout(() => {
+ if (window.ReactNativeWebView && window.ReactNativeWebView.postMessage) {
+ window.ReactNativeWebView.postMessage(data);
+ } else if (window.postMessage) {
+ window.postMessage(data);
+ }
+ }, 0)
+ }
+
window.onresize = resizeCanvas;
resizeCanvas();
signaturePad = new SignaturePad(canvas, {
- onBegin: () => window.ReactNativeWebView.postMessage("BEGIN"),
- onEnd: () => window.ReactNativeWebView.postMessage("END"),
+ onBegin: () => safePostMessage("BEGIN"),
+ onEnd: () => safePostMessage("END"),
penColor: '<%penColor%>',
backgroundColor: '<%backgroundColor%>',
dotSize: <%dotSize%>,
@@ -37,50 +47,50 @@ export default `
function clearSignature () {
signaturePad.clear();
- window.ReactNativeWebView.postMessage("CLEAR");
+ safePostMessage("CLEAR");
}
function undo() {
signaturePad.undo();
- window.ReactNativeWebView.postMessage("UNDO");
+ safePostMessage("UNDO");
}
function redo() {
signaturePad.redo();
- window.ReactNativeWebView.postMessage("REDO");
+ safePostMessage("REDO");
}
function changePenColor(color) {
signaturePad.penColor = color;
- window.ReactNativeWebView.postMessage("CHANGE_PEN");
+ safePostMessage("CHANGE_PEN");
}
function changePenSize(minW, maxW) {
signaturePad.minWidth = minW;
signaturePad.maxWidth = maxW;
- window.ReactNativeWebView.postMessage("CHANGE_PEN_SIZE");
+ safePostMessage("CHANGE_PEN_SIZE");
}
function getData () {
var data = signaturePad.toData();
- window.ReactNativeWebView.postMessage(JSON.stringify(data));
+ safePostMessage(JSON.stringify(data));
}
function draw() {
signaturePad.draw();
- window.ReactNativeWebView.postMessage("DRAW");
+ safePostMessage("DRAW");
}
function erase() {
signaturePad.erase();
- window.ReactNativeWebView.postMessage("ERASE");
+ safePostMessage("ERASE");
}
function cropWhitespace(url) {
var myImage = new Image();
myImage.crossOrigin = "Anonymous";
myImage.onload = function(){
- window.ReactNativeWebView.postMessage(removeImageBlanks(myImage)); //Will return cropped image data
+ safePostMessage(removeImageBlanks(myImage)); //Will return cropped image data
}
myImage.src = url;
@@ -170,10 +180,10 @@ export default `
function readSignature() {
if (signaturePad.isEmpty()) {
- window.ReactNativeWebView.postMessage("EMPTY");
+ safePostMessage("EMPTY");
} else {
var url = signaturePad.toDataURL('<%imageType%>');
- trimWhitespace? cropWhitespace(url): window.ReactNativeWebView.postMessage(url);
+ trimWhitespace ? cropWhitespace(url) : safePostMessage(url);
if (autoClear) signaturePad.clear();
}
}
diff --git a/node_modules/react-native-signature-canvas/index.js b/node_modules/react-native-signature-canvas/index.js
index 7f9f0e8..12ab8af 100644
--- a/node_modules/react-native-signature-canvas/index.js
+++ b/node_modules/react-native-signature-canvas/index.js
@@ -50,20 +50,20 @@ const SignatureView = forwardRef(
minWidth = 0.5,
maxWidth = 2.5,
nestedScrollEnabled = false,
- showsVerticalScrollIndicator= true,
- onOK = () => {},
- onEmpty = () => {},
- onClear = () => {},
- onUndo = () => {},
- onRedo = () => {},
- onDraw = () => {},
- onErase = () => {},
- onGetData = () => {},
- onChangePenColor = () => {},
- onChangePenSize = () => {},
- onBegin = () => {},
- onEnd = () => {},
- onLoadEnd = () => {},
+ showsVerticalScrollIndicator = true,
+ onOK = () => { },
+ onEmpty = () => { },
+ onClear = () => { },
+ onUndo = () => { },
+ onRedo = () => { },
+ onDraw = () => { },
+ onErase = () => { },
+ onGetData = () => { },
+ onChangePenColor = () => { },
+ onChangePenSize = () => { },
+ onBegin = () => { },
+ onEnd = () => { },
+ onLoadEnd = () => { },
overlayHeight = 0,
overlayWidth = 0,
overlaySrc = null,
@@ -258,13 +258,22 @@ const SignatureView = forwardRef(
console.warn("WebView error: ", nativeEvent);
const handleLoadEnd = () => {
- setLoading(false);
- onLoadEnd();
+ setLoading(false);
+ onLoadEnd();
}
+ // Patch to force reload the webview when using the new arch when the component has already been mount before.
+ // It solves the infinite loading indicator issue.
+ const [key, setKey] = useState(new Date().getTime());
+
+ useEffect(() => {
+ setKey(new Date().getTime());
+ }, []);
+
return (
<View style={[styles.webBg, style]}>
<WebView
+ key={`signature-screen-${key}`}
bounces={false}
style={[webviewContainerStyle]}
scrollEnabled={scrollable}
Lastly, patch the
diff --git a/node_modules/react-native-webview/android/src/main/java/com/reactnativecommunity/webview/RNCWebView.java b/node_modules/react-native-webview/android/src/main/java/com/reactnativecommunity/webview/RNCWebView.java
index 31cf298..af8b2a3 100644
--- a/node_modules/react-native-webview/android/src/main/java/com/reactnativecommunity/webview/RNCWebView.java
+++ b/node_modules/react-native-webview/android/src/main/java/com/reactnativecommunity/webview/RNCWebView.java
@@ -449,7 +455,7 @@ public class RNCWebView extends WebView implements LifecycleEventListener {
@JavascriptInterface
public void postMessage(String message) {
if (mWebView.getMessagingEnabled()) {
- mWebView.onMessage(message, mWebView.getUrl());
+ post(() -> mWebView.onMessage(message, mWebView.getUrl()));
} else {
FLog.w(TAG, "ReactNativeWebView.postMessage method was called but messaging is disabled. Pass an onMessage handler to the WebView.");
}
|
I'm using RN 0.76.7 and react-native-webview 13.13.2 works perfectly without applying this patch. (tested on android only) |
same not working, previously working |
@next6leo a mi se soluciono actualizando la lib de react native web view, ya que subieron una version con un error |
@davidgvf what webview version? |
With this version for me its fix "react-native-webview": "13.13.2" |
thanks @davidgvf i try install see |
When you swipe to make the signature, it only draws a dot
RN version 0.76.1
react-native-signature-canvas version 4.7.2
The text was updated successfully, but these errors were encountered: