Skip to content

Commit

Permalink
Merge pull request #116 from 6pm/master
Browse files Browse the repository at this point in the history
 Add strokeWidth support for Android. Update propTypes
  • Loading branch information
jedt authored Jan 23, 2018
2 parents 5f99394 + bd76b60 commit 473ccfa
Show file tree
Hide file tree
Showing 5 changed files with 196 additions and 13 deletions.
6 changes: 5 additions & 1 deletion SignatureCapture.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -21,6 +22,10 @@ public class RSSignatureCaptureViewManager extends ViewGroupManager<RSSignatureC
public static final String PROPS_VIEW_MODE = "viewMode";
public static final String PROPS_SHOW_NATIVE_BUTTONS="showNativeButtons";
public static final String PROPS_MAX_SIZE="maxSize";
public static final String PROPS_MIN_STROKE_WIDTH="minStrokeWidth";
public static final String PROPS_MAX_STROKE_WIDTH="maxStrokeWidth";
public static final String PROPS_STROKE_COLOR="strokeColor";
public static final String PROPS_BACKGROUND_COLOR="backgroundColor";

public static final int COMMAND_SAVE_IMAGE = 1;
public static final int COMMAND_RESET_IMAGE = 2;
Expand Down Expand Up @@ -70,6 +75,37 @@ public void setPropsWidth(RSSignatureCaptureMainView view, @Nullable Integer max
}
}

@ReactProp(name = PROPS_MIN_STROKE_WIDTH)
public void setPropsMinStrokeWidth(RSSignatureCaptureMainView view, @Nullable int minStrokeWidth) {
Log.d("minStrokeWidth:", ""+minStrokeWidth);
if(view!=null){
view.getSignatureView().setMinStrokeWidth(minStrokeWidth);
}
}

@ReactProp(name = PROPS_MAX_STROKE_WIDTH)
public void setPropsMaxStrokeWidth(RSSignatureCaptureMainView view, @Nullable int maxStrokeWidth) {
Log.d("maxStrokeWidth:", ""+maxStrokeWidth);
if(view!=null){
view.getSignatureView().setMaxStrokeWidth(maxStrokeWidth);
}
}

@ReactProp(name = PROPS_STROKE_COLOR)
public void setPropsStrokeColor(RSSignatureCaptureMainView view, @Nullable String color) {
Log.d("strokeColor:", ""+color);
if(view!=null){
view.getSignatureView().setStrokeColor(Color.parseColor(color));
}
}

@ReactProp(name = PROPS_BACKGROUND_COLOR)
public void setPropsBackgroundColor(RSSignatureCaptureMainView view, @Nullable String color) {
Log.d("backgroundColor:", ""+color);
if(view!=null){
view.getSignatureView().setBackgroundColor(Color.parseColor(color));
}
}

@Override
public RSSignatureCaptureMainView createViewInstance(ThemedReactContext context) {
Expand Down
119 changes: 119 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 473ccfa

Please sign in to comment.