forked from prscX/react-native-photo-editor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.tsx
91 lines (85 loc) · 2.09 KB
/
App.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
import React, {Component} from 'react';
import {StyleSheet, Text, View, TouchableOpacity} from 'react-native';
import {Image} from 'react-native';
import PhotoEditor from 'react-native-photo-editor';
import RNFS from 'react-native-fs';
import RNFetchBlob from 'rn-fetch-blob';
type Props = {
path: string;
colors?: string[];
stickers?: string[];
hiddenControls?: string[];
onDone?: (e: any) => void;
onCancel?: (e: any) => void;
};
export default class App extends Component<Props> {
_onPress = () => {
PhotoEditor.Edit({
path: RNFS.DocumentDirectoryPath + '/photo.jpg',
stickers: [
'sticker0',
'sticker1',
'sticker2',
'sticker3',
'sticker4',
'sticker5',
'sticker6',
'sticker7',
'sticker8',
'sticker9',
'sticker10',
],
// hiddenControls: [
// 'clear',
// 'crop',
// 'draw',
// 'save',
// 'share',
// 'sticker',
// 'text',
// ],
colors: undefined,
onDone: () => {
console.log('on done');
},
onCancel: () => {
console.log('on cancel');
},
});
};
componentDidMount() {
let photoPath = RNFS.DocumentDirectoryPath + '/photo.jpg';
let binaryFile = Image.resolveAssetSource(require('./assets/photo.jpg'));
RNFetchBlob.config({fileCache: true})
.fetch('GET', binaryFile.uri)
.then((resp: {path: () => string}) => {
RNFS.moveFile(resp.path(), photoPath)
.then(() => {
console.log('FILE WRITTEN!');
})
.catch((err) => {
console.log(err.message);
});
})
.catch((err: {message: any}) => {
console.log(err.message);
});
}
render() {
return (
<View style={styles.container}>
<TouchableOpacity onPress={this._onPress}>
<Text>Click</Text>
</TouchableOpacity>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
});