forked from EllipApp/react-native-signature-capture
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSignatureCapture.js
92 lines (79 loc) · 2.49 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
83
84
85
86
87
88
89
90
91
92
"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.onChange = this.onChange.bind(this);
this.subscriptions = [];
}
onChange(event) {
if (event.nativeEvent.pathName) {
if (!this.props.onSaveEvent) {
return;
}
this.props.onSaveEvent({
pathName: event.nativeEvent.pathName,
encoded: event.nativeEvent.encoded,
});
}
if (event.nativeEvent.dragged) {
if (!this.props.onDragEvent) {
return;
}
this.props.onDragEvent({
dragged: event.nativeEvent.dragged,
});
}
}
componentDidMount() {
if (this.props.onSaveEvent) {
let sub = DeviceEventEmitter.addListener("onSaveEvent", this.props.onSaveEvent);
this.subscriptions.push(sub);
}
if (this.props.onDragEvent) {
let sub = DeviceEventEmitter.addListener("onDragEvent", this.props.onDragEvent);
this.subscriptions.push(sub);
}
}
componentWillUnmount() {
this.subscriptions.forEach(sub => sub.remove());
this.subscriptions = [];
}
render() {
return <RSSignatureView {...this.props} onChange={this.onChange} />;
}
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,
showTitleLabel: PropTypes.bool,
maxSize: PropTypes.number,
minStrokeWidth: PropTypes.number,
maxStrokeWidth: PropTypes.number,
strokeColor: PropTypes.string,
backgroundColor: PropTypes.string,
};
var RSSignatureView = requireNativeComponent("RSSignatureView", SignatureCapture, {
nativeOnly: {onChange: true},
});
module.exports = SignatureCapture;