Skip to content

Commit

Permalink
Merge pull request RepairShopr#55 from Tom32i/master
Browse files Browse the repository at this point in the history
Made title label optional
  • Loading branch information
jedt authored Apr 4, 2017
2 parents d291176 + f285a19 commit dc36b82
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 37 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ class CustomComponent extends Component {
+ **showNativeButtons** : If this props is made to true, it will display the native buttons "Save" and "Reset".
+ **showTitleLabel** : If this props is made to true, it will display the "x_ _ _ _ _ _ _ _ _ _ _" placeholder indicating where to sign.
+ **viewMode** : "portrait" or "landscape" change the screen orientation based on boolean value
+ **maxSize** : sets the max size of the image maintains aspect ratio, default is 500
Expand Down Expand Up @@ -157,6 +159,7 @@ class RNSignatureExample extends Component {
onDragEvent={this._onDragEvent}
saveImageFileInExtStorage={false}
showNativeButtons={false}
showTitleLabel={false}
viewMode={"portrait"}/>
<View style={{ flex: 1, flexDirection: "row" }}>
Expand Down
1 change: 1 addition & 0 deletions SignatureCapture.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ SignatureCapture.propTypes = {
saveImageFileInExtStorage: PropTypes.bool,
viewMode: PropTypes.string,
showNativeButtons: PropTypes.bool,
showTitleLabel: PropTypes.bool,
maxSize:PropTypes.number
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class RSSignatureCaptureMainView extends LinearLayout implements OnClickL
Boolean saveFileInExtStorage = false;
String viewMode = "portrait";
Boolean showNativeButtons = true;
Boolean showTitleLabel = true;
int maxSize = 500;

public RSSignatureCaptureMainView(Context context, Activity activity) {
Expand Down
84 changes: 47 additions & 37 deletions ios/RSSignatureView.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ @implementation RSSignatureView {
BOOL _rotateClockwise;
BOOL _square;
BOOL _showNativeButtons;
BOOL _showTitleLabel;
}

@synthesize sign;
Expand All @@ -25,15 +26,16 @@ @implementation RSSignatureView {
- (instancetype)init
{
_showNativeButtons = YES;
_showTitleLabel = YES;
if ((self = [super init])) {
_border = [CAShapeLayer layer];
_border.strokeColor = [UIColor blackColor].CGColor;
_border.fillColor = nil;
_border.lineDashPattern = @[@4, @2];

[self.layer addSublayer:_border];
}

return self;
}

Expand All @@ -49,33 +51,35 @@ - (void)layoutSubviews
{
[super layoutSubviews];
if (!_loaded) {

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didRotate:)
name:UIDeviceOrientationDidChangeNotification object:nil];

_context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];

CGSize screen = self.bounds.size;

sign = [[PPSSignatureView alloc]
initWithFrame: CGRectMake(0, 0, screen.width, screen.height)
context: _context];
sign.manager = manager;

[self addSubview:sign];

if ( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ) {

titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.bounds.size.width, 24)];
[titleLabel setCenter:CGPointMake(self.bounds.size.width/2, self.bounds.size.height - 120)];

[titleLabel setText:@"x_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _"];
[titleLabel setLineBreakMode:NSLineBreakByClipping];
[titleLabel setTextAlignment: NSTextAlignmentCenter];
[titleLabel setTextColor:[UIColor colorWithRed:200/255.f green:200/255.f blue:200/255.f alpha:1.f]];
//[titleLabel setBackgroundColor:[UIColor greenColor]];
[sign addSubview:titleLabel];


if (_showTitleLabel) {
titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.bounds.size.width, 24)];
[titleLabel setCenter:CGPointMake(self.bounds.size.width/2, self.bounds.size.height - 120)];

[titleLabel setText:@"x_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _"];
[titleLabel setLineBreakMode:NSLineBreakByClipping];
[titleLabel setTextAlignment: NSTextAlignmentCenter];
[titleLabel setTextColor:[UIColor colorWithRed:200/255.f green:200/255.f blue:200/255.f alpha:1.f]];
//[titleLabel setBackgroundColor:[UIColor greenColor]];
[sign addSubview:titleLabel];
}

if (_showNativeButtons) {
//Save button
saveButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
Expand Down Expand Up @@ -105,17 +109,19 @@ - (void)layoutSubviews
}
}
else {

titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.bounds.size.height - 80, 24)];
[titleLabel setCenter:CGPointMake(40, self.bounds.size.height/2)];
[titleLabel setTransform:CGAffineTransformMakeRotation(DEGREES_TO_RADIANS(90))];
[titleLabel setText:@"x_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _"];
[titleLabel setLineBreakMode:NSLineBreakByClipping];
[titleLabel setTextAlignment: NSTextAlignmentLeft];
[titleLabel setTextColor:[UIColor colorWithRed:200/255.f green:200/255.f blue:200/255.f alpha:1.f]];
//[titleLabel setBackgroundColor:[UIColor greenColor]];
[sign addSubview:titleLabel];


if (_showTitleLabel) {
titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.bounds.size.height - 80, 24)];
[titleLabel setCenter:CGPointMake(40, self.bounds.size.height/2)];
[titleLabel setTransform:CGAffineTransformMakeRotation(DEGREES_TO_RADIANS(90))];
[titleLabel setText:@"x_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _"];
[titleLabel setLineBreakMode:NSLineBreakByClipping];
[titleLabel setTextAlignment: NSTextAlignmentLeft];
[titleLabel setTextColor:[UIColor colorWithRed:200/255.f green:200/255.f blue:200/255.f alpha:1.f]];
//[titleLabel setBackgroundColor:[UIColor greenColor]];
[sign addSubview:titleLabel];
}

if (_showNativeButtons) {
//Save button
saveButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
Expand Down Expand Up @@ -144,7 +150,7 @@ - (void)layoutSubviews
[sign addSubview:clearButton];
}
}

}
_loaded = true;
_border.path = [UIBezierPath bezierPathWithRect:self.bounds].CGPath;
Expand All @@ -163,6 +169,10 @@ - (void)setShowNativeButtons:(BOOL)showNativeButtons {
_showNativeButtons = showNativeButtons;
}

- (void)setShowTitleLabel:(BOOL)showTitleLabel {
_showTitleLabel = showTitleLabel;
}

-(void) onSaveButtonPressed {
[self saveImage];
}
Expand All @@ -171,32 +181,32 @@ -(void) saveImage {
saveButton.hidden = YES;
clearButton.hidden = YES;
UIImage *signImage = [self.sign signatureImage: _rotateClockwise withSquare:_square];

saveButton.hidden = NO;
clearButton.hidden = NO;

NSError *error;

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths firstObject];
NSString *tempPath = [documentsDirectory stringByAppendingFormat:@"/signature.png"];

//remove if file already exists
if ([[NSFileManager defaultManager] fileExistsAtPath:tempPath]) {
[[NSFileManager defaultManager] removeItemAtPath:tempPath error:&error];
if (error) {
NSLog(@"Error: %@", error.debugDescription);
}
}

// Convert UIImage object into NSData (a wrapper for a stream of bytes) formatted according to PNG spec
NSData *imageData = UIImagePNGRepresentation(signImage);
BOOL isSuccess = [imageData writeToFile:tempPath atomically:YES];
if (isSuccess) {
NSFileManager *man = [NSFileManager defaultManager];
NSDictionary *attrs = [man attributesOfItemAtPath:tempPath error: NULL];
//UInt32 result = [attrs fileSize];

NSString *base64Encoded = [imageData base64EncodedStringWithOptions:0];
[self.manager publishSaveImageEvent: tempPath withEncoded:base64Encoded];
}
Expand Down
1 change: 1 addition & 0 deletions ios/RSSignatureViewManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ @implementation RSSignatureViewManager
RCT_EXPORT_VIEW_PROPERTY(rotateClockwise, BOOL)
RCT_EXPORT_VIEW_PROPERTY(square, BOOL)
RCT_EXPORT_VIEW_PROPERTY(showNativeButtons, BOOL)
RCT_EXPORT_VIEW_PROPERTY(showTitleLabel, BOOL)


-(dispatch_queue_t) methodQueue
Expand Down

0 comments on commit dc36b82

Please sign in to comment.