forked from VGamezz19/react-native-sketch-draw
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
149 lines (133 loc) · 3.03 KB
/
index.js
File metadata and controls
149 lines (133 loc) · 3.03 KB
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import React, {Component} from 'react';
import PropTypes from 'prop-types';
import {
requireNativeComponent,
View,
PanResponder,
UIManager,
findNodeHandle,
ColorPropType,
} from 'react-native';
// so events are not bubbled to the top elements
let viewResponder = PanResponder.create({
onStartShouldSetPanResponder: (evt, gestureState) => true,
onStartShouldSetPanResponderCapture: (evt, gestureState) => true,
onMoveShouldSetPanResponder: (evt, gestureState) => true,
onMoveShouldSetPanResponderCapture: (evt, gestureState) => true,
onPanResponderTerminationRequest: (evt, gestureState) => {
return true;
},
onShouldBlockNativeResponder: (evt, gestureState) => false,
onPanResponderRelease: (evt, gestureState) => {},
onPanResponderTerminate: (evt, gestureState) => {},
});
class SketchView extends Component {
constructor(props) {
super(props);
this.onSaveSketch = this.onSaveSketch.bind(this);
this.onDrawSketch = this.onDrawSketch.bind(this);
}
onSaveSketch(event) {
if (!this.props.onSaveSketch) {
return;
}
this.props.onSaveSketch({
localFilePath: event.nativeEvent.localFilePath,
imageWidth: event.nativeEvent.imageWidth,
imageHeight: event.nativeEvent.imageHeight,
});
}
onDrawSketch(event) {
if (this.props.onDrawSketch) {
this.props.onDrawSketch({
stackCount: event.nativeEvent.stackCount,
});
}
}
render() {
return (
<RNSketchView
{...this.props}
onSaveSketch={this.onSaveSketch}
onDrawSketch={this.onDrawSketch}
{...viewResponder.panHandlers}
/>
);
}
clearSketch() {
UIManager.dispatchViewManagerCommand(
findNodeHandle(this),
'clearSketch',
[],
);
}
undoSketch() {
UIManager.dispatchViewManagerCommand(
findNodeHandle(this),
'undoSketch',
[],
);
}
saveSketch(format, quality) {
UIManager.dispatchViewManagerCommand(findNodeHandle(this), 'saveSketch', [
format || 'PNG',
quality || 100,
]);
}
commitSketch() {
UIManager.dispatchViewManagerCommand(
findNodeHandle(this),
'commitSketch',
[],
);
}
promptData() {
UIManager.dispatchViewManagerCommand(
findNodeHandle(this),
'promptData',
[],
);
}
}
SketchView.constants = {
toolType: {
pen: {
id: 0,
name: 'Pen',
},
eraser: {
id: 1,
name: 'Eraser',
},
rectangle: {
id: 2,
name: 'Rectangle',
},
arrow: {
id: 3,
name: 'Arrow',
},
text: {
id: 4,
name: 'Text',
},
},
};
SketchView.propTypes = {
...View.propTypes,
selectedTool: PropTypes.number,
toolColor: ColorPropType,
localSourceImagePath: PropTypes.string,
maxUndo: PropTypes.number,
onDrawSketch: PropTypes.func,
};
SketchView.defaultProps = {
maxUndo: 10,
};
let RNSketchView = requireNativeComponent('RNSketchView', SketchView, {
nativeOnly: {
onSaveSketch: true,
onDrawSketch: true,
},
});
export default SketchView;