forked from RepairShopr/react-native-signature-capture
-
Notifications
You must be signed in to change notification settings - Fork 4
/
SignatureCapture.js
82 lines (70 loc) · 1.9 KB
/
SignatureCapture.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
'use strict';
var ReactNative = require('react-native');
var React = require('react');
var PropTypes = require('prop-types');
var {
requireNativeComponent,
View,
UIManager,
DeviceEventEmitter
} = ReactNative;
class SignatureCapture extends React.Component {
constructor() {
super();
this.onSave = this.onSave.bind(this);
this.onDrag = this.onDrag.bind(this);
}
onSave(event) {
if (!this.props.onSaveEvent) {
return;
}
this.props.onSaveEvent({
pathName: event.pathName,
encoded: event.nativeEvent.encoded,
});
}
onDrag(event) {
if (!this.props.onDragEvent) {
return;
}
this.props.onDragEvent({
dragged: event.dragged
});
}
render() {
return (
<RSSignatureView {...this.props} onSave={this.onSave} onDrag={this.onDrag} />
);
}
saveImage() {
UIManager.dispatchViewManagerCommand(
ReactNative.findNodeHandle(this),
UIManager.RSSignatureView.Commands.saveImage,
[],
);
}
resetImage() {
UIManager.dispatchViewManagerCommand(
ReactNative.findNodeHandle(this),
UIManager.RSSignatureView.Commands.resetImage,
[],
);
}
}
SignatureCapture.propTypes = {
...View.propTypes,
rotateClockwise: PropTypes.bool,
square: PropTypes.bool,
saveImageFileInExtStorage: PropTypes.bool,
viewMode: PropTypes.string,
showBorder: PropTypes.bool,
showNativeButtons: PropTypes.bool,
showTitleLabel: PropTypes.bool,
maxSize:PropTypes.number,
onSaveEvent: PropTypes.func,
onDragEvent: PropTypes.func,
};
var RSSignatureView = requireNativeComponent('RSSignatureView', SignatureCapture, {
nativeOnly: { onSave: true, onDrag: true }
});
module.exports = SignatureCapture;