diff --git a/SignatureCapture.js b/SignatureCapture.js index ec53631c..4a903f93 100644 --- a/SignatureCapture.js +++ b/SignatureCapture.js @@ -97,7 +97,11 @@ SignatureCapture.propTypes = { showBorder: PropTypes.bool, showNativeButtons: PropTypes.bool, showTitleLabel: PropTypes.bool, - maxSize:PropTypes.number + maxSize:PropTypes.number, + minStrokeWidth: PropTypes.number, + maxStrokeWidth: PropTypes.number, + strokeColor: PropTypes.string, + backgroundColor: PropTypes.string }; var RSSignatureView = requireNativeComponent('RSSignatureView', SignatureCapture, { diff --git a/android/src/main/java/com/rssignaturecapture/RSSignatureCaptureMainView.java b/android/src/main/java/com/rssignaturecapture/RSSignatureCaptureMainView.java index ec5bccd4..3dff8bc1 100644 --- a/android/src/main/java/com/rssignaturecapture/RSSignatureCaptureMainView.java +++ b/android/src/main/java/com/rssignaturecapture/RSSignatureCaptureMainView.java @@ -59,6 +59,10 @@ public RSSignatureCaptureMainView(Context context, Activity activity) { ViewGroup.LayoutParams.MATCH_PARENT)); } + public RSSignatureCaptureView getSignatureView() { + return signatureView; + } + public void setSaveFileInExtStorage(Boolean saveFileInExtStorage) { this.saveFileInExtStorage = saveFileInExtStorage; } diff --git a/android/src/main/java/com/rssignaturecapture/RSSignatureCaptureView.java b/android/src/main/java/com/rssignaturecapture/RSSignatureCaptureView.java index 35f42efb..6d7c255d 100644 --- a/android/src/main/java/com/rssignaturecapture/RSSignatureCaptureView.java +++ b/android/src/main/java/com/rssignaturecapture/RSSignatureCaptureView.java @@ -51,7 +51,8 @@ public class RSSignatureCaptureView extends View { private Canvas mSignatureBitmapCanvas = null; private SignatureCallback callback; private boolean dragged = false; - private int SCROLL_THRESHOLD = 50; + private boolean multipleTouchDragged = false; + private int SCROLL_THRESHOLD = 5; public interface SignatureCallback { void onDragged(); @@ -197,6 +198,18 @@ private void ensureSignatureBitmap() { } } + public void setMinStrokeWidth(int minStrokeWidth) { + mMinWidth = minStrokeWidth; + } + + public void setMaxStrokeWidth(int maxStrokeWidth) { + mMaxWidth = maxStrokeWidth; + } + + public void setStrokeColor(int color) { + mPaint.setColor(color); + } + private float strokeWidth(float velocity) { return Math.max(mMaxWidth / (velocity + 1), mMinWidth); } @@ -226,35 +239,42 @@ private ControlTimedPoints calculateCurveControlPoints(TimedPoint s1, TimedPoint @Override public boolean onTouchEvent(MotionEvent event) { - if (!isEnabled()) + if (!isEnabled() || event.getPointerCount() > 1 || (multipleTouchDragged && event.getAction() != MotionEvent.ACTION_UP)) { + multipleTouchDragged = true; return false; + } float eventX = event.getX(); float eventY = event.getY(); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: + mLastTouchX = eventX; + mLastTouchY = eventY; getParent().requestDisallowInterceptTouchEvent(true); mPoints.clear(); mPath.moveTo(eventX, eventY); - mLastTouchX = eventX; - mLastTouchY = eventY; addPoint(new TimedPoint(eventX, eventY)); case MotionEvent.ACTION_MOVE: + if((Math.abs(mLastTouchX - eventX) < SCROLL_THRESHOLD || Math.abs(mLastTouchY - eventY) < SCROLL_THRESHOLD) && dragged) { + return false; + } resetDirtyRect(eventX, eventY); addPoint(new TimedPoint(eventX, eventY)); - if((Math.abs(mLastTouchX - eventX) > SCROLL_THRESHOLD || Math.abs(mLastTouchY - eventY) > SCROLL_THRESHOLD)){ - dragged = true; - } + dragged = true; break; case MotionEvent.ACTION_UP: - resetDirtyRect(eventX, eventY); - addPoint(new TimedPoint(eventX, eventY)); - getParent().requestDisallowInterceptTouchEvent(true); - setIsEmpty(false); - sendDragEventToReact(); + if(mPoints.size() >= 3) { + resetDirtyRect(eventX, eventY); + addPoint(new TimedPoint(eventX, eventY)); + getParent().requestDisallowInterceptTouchEvent(true); + setIsEmpty(false); + sendDragEventToReact(); + } + dragged = false; + multipleTouchDragged = false; break; default: diff --git a/android/src/main/java/com/rssignaturecapture/RSSignatureCaptureViewManager.java b/android/src/main/java/com/rssignaturecapture/RSSignatureCaptureViewManager.java index 9c7ff180..0dea9149 100644 --- a/android/src/main/java/com/rssignaturecapture/RSSignatureCaptureViewManager.java +++ b/android/src/main/java/com/rssignaturecapture/RSSignatureCaptureViewManager.java @@ -1,6 +1,7 @@ package com.rssignaturecapture; import android.util.Log; +import android.graphics.Color; import com.facebook.infer.annotation.Assertions; import com.facebook.react.bridge.ReactApplicationContext; @@ -21,6 +22,10 @@ public class RSSignatureCaptureViewManager extends ViewGroupManager