-
Notifications
You must be signed in to change notification settings - Fork 244
/
index.tsx
64 lines (58 loc) · 1.55 KB
/
index.tsx
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
import { NativeModules } from 'react-native'
const { RNPhotoEditor } = NativeModules
export interface PhotoEditorProps {
path: string
colors?: string[]
stickers?: string[]
hiddenControls?: ('text' | 'clear' | 'draw' | 'save' | 'share' | 'sticker' | 'crop')[]
onDone?: (imagePath: string) => void
onCancel?: (resultCode: number) => void
}
export default class PhotoEditor {
private static defaultProps = {
stickers: [],
hiddenControls: [],
colors: [
'#000000',
'#808080',
'#a9a9a9',
'#FFFFFE',
'#0000ff',
'#00ff00',
'#ff0000',
'#ffff00',
'#ffa500',
'#800080',
'#00ffff',
'#a52a2a',
'#ff00ff'
]
}
static Edit({
stickers,
hiddenControls,
colors,
onDone,
onCancel,
...props
}: PhotoEditorProps) {
if (stickers === undefined) {
stickers = this.defaultProps.stickers
}
if (hiddenControls === undefined) {
hiddenControls = this.defaultProps.hiddenControls
}
if (colors === undefined) {
colors = this.defaultProps.colors
}
RNPhotoEditor.Edit(
{ colors, hiddenControls, stickers, ...props },
(imagePath: string) => {
onDone && onDone(imagePath)
},
(resultCode: number) => {
onCancel && onCancel(resultCode)
}
)
}
}