forked from prscX/react-native-photo-editor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.tsx
104 lines (97 loc) · 2.87 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
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
import { NativeModules } from 'react-native'
const { RNPhotoEditor } = NativeModules
type Language = {
doneTitle?: string
saveTitle?: string
clearAllTitle?: string
cameraTitle?: string
galleryTitle?: string
uploadDialogTitle?: string
uploadPickerTitle?: string
directoryCreateFail?: string
accessMediaPermissionsMsg?: string
continueTxt?: string
notNow?: string
mediaAccessDeniedMsg?: string
saveImageSucceed?: string
eraserTitle?: string
}
export interface PhotoEditorProps {
path: string
colors?: string[]
stickers?: string[]
hiddenControls?: ('text' | 'clear' | 'draw' | 'save' | 'share' | 'sticker' | 'crop')[]
languages: Language
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'
],
languages: {
doneTitle: 'Done',
saveTitle: 'Save',
clearAllTitle: 'Clear all',
cameraTitle: 'Camera',
galleryTitle: 'Gallery',
uploadDialogTitle: 'Upload Image',
uploadPickerTitle: 'Select Picture',
directoryCreateFail: 'Failed to create directory',
accessMediaPermissionsMsg: 'To attach photos, we need to access media on your device',
continueTxt: 'Continue',
notNow: 'NOT NOW',
mediaAccessDeniedMsg: 'You denied storage access, no photos will be added.',
saveImageSucceed: 'Image saved',
eraserTitle: 'Eraser'
}
}
static Edit({
stickers,
hiddenControls,
colors,
languages,
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
}
if (languages !== undefined) {
languages = { ...this.defaultProps.languages, ...languages }
} else {
languages = this.defaultProps.languages
}
RNPhotoEditor.Edit(
{ colors, hiddenControls, stickers, languages, ...props },
(imagePath: string) => {
onDone && onDone(imagePath)
},
(resultCode: number) => {
onCancel && onCancel(resultCode)
}
)
}
}