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

support React-Native setState for strokeColor, backgroundColor, rotateClockWise #284

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
14 changes: 12 additions & 2 deletions android/src/main/java/com/rssignaturecapture/RSSignatureCaptureMainView.java
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.rssignaturecapture;

import android.graphics.Matrix;
import android.util.Log;
import android.view.ViewGroup;
import com.facebook.react.modules.core.DeviceEventManagerModule;
Expand Down Expand Up @@ -197,8 +198,17 @@ public Bitmap getResizedBitmap(Bitmap image) {
height = maxSize;
width = (int) (height * bitmapRatio);
}

return Bitmap.createScaledBitmap(image, width, height, true);
Bitmap resizedBitmap = Bitmap.createScaledBitmap(image, width, height, true);

if (this.signatureView.getRotateClockwise()){
Matrix matrix = new Matrix();
// 正数顺时针,负数逆时针
matrix.postRotate(-90);
Bitmap rotatedBitmap = Bitmap.createBitmap(resizedBitmap, 0, 0, resizedBitmap.getWidth(), resizedBitmap.getHeight(), matrix, true);
return rotatedBitmap;
}else{
return resizedBitmap;
}
}


Expand Down
Empty file.
11 changes: 11 additions & 0 deletions android/src/main/java/com/rssignaturecapture/RSSignatureCaptureView.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public class RSSignatureCaptureView extends View {
private boolean dragged = false;
private boolean multipleTouchDragged = false;
private int SCROLL_THRESHOLD = 5;
private boolean rotateClockwise = false;

public interface SignatureCallback {
void onDragged();
Expand Down Expand Up @@ -214,6 +215,16 @@ private float strokeWidth(float velocity) {
return Math.max(mMaxWidth / (velocity + 1), mMinWidth);
}

public void setRotateClockWise(boolean newRotateClockwise){
rotateClockwise = newRotateClockwise;
}

public boolean getRotateClockwise(){
return rotateClockwise;
}



private ControlTimedPoints calculateCurveControlPoints(TimedPoint s1, TimedPoint s2, TimedPoint s3) {
float dx1 = s1.x - s2.x;
float dy1 = s1.y - s2.y;
Expand Down
9 changes: 9 additions & 0 deletions android/src/main/java/com/rssignaturecapture/RSSignatureCaptureViewManager.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class RSSignatureCaptureViewManager extends ViewGroupManager<RSSignatureC
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 String PROPS_ROTATE_CLOCK_WISE = "rotateClockwise";

public static final int COMMAND_SAVE_IMAGE = 1;
public static final int COMMAND_RESET_IMAGE = 2;
Expand Down Expand Up @@ -114,6 +115,14 @@ public void setPropsBackgroundColor(RSSignatureCaptureMainView view, @Nullable S
}
}

@ReactProp(name = PROPS_ROTATE_CLOCK_WISE)
public void setRotateClockWise(RSSignatureCaptureMainView view, @Nullable boolean rotateClockwise){
Log.d("setRotateClockWise:", ""+rotateClockwise);
if (view != null){
view.getSignatureView().setRotateClockWise(rotateClockwise);
}
}

@Override
public RSSignatureCaptureMainView createViewInstance(ThemedReactContext context) {
Log.d("React"," View manager createViewInstance:");
Expand Down
Empty file modified android/src/main/java/com/rssignaturecapture/utils/Bezier.java
100644 → 100755
Empty file.
Empty file.
Empty file.
1 change: 1 addition & 0 deletions ios/PPSSignatureView.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
@interface PPSSignatureView : GLKView

@property (assign, nonatomic) UIColor *strokeColor;
@property (assign, nonatomic) UIColor *backgroundColor;
@property (assign, nonatomic) BOOL hasSignature;
@property (strong, nonatomic) UIImage *signatureImage;
@property (nonatomic, strong) RSSignatureViewManager *manager;
Expand Down
6 changes: 6 additions & 0 deletions ios/RSSignatureView.m
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,16 @@ - (void)setShowTitleLabel:(BOOL)showTitleLabel {

- (void)setBackgroundColor:(UIColor*)backgroundColor {
_backgroundColor = backgroundColor;
if (sign){
sign.backgroundColor = backgroundColor;
}
}

- (void)setStrokeColor:(UIColor*)strokeColor {
_strokeColor = strokeColor;
if (sign){
sign.strokeColor = strokeColor;
}
}

-(void) onSaveButtonPressed {
Expand Down