-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
94 lines (86 loc) · 1.78 KB
/
App.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
93
94
import React, { Component } from 'react';
import {
StyleSheet,
Text,
Dimensions,
View,
Image,
TouchableOpacity,
} from 'react-native';
import ImageCrop from 'react-native-image-crop';
const WINDOW_WIDTH = Dimensions.get('window').width;
const WINDOW_HEIGHT = Dimensions.get('window').height;
const styles = StyleSheet.create({
container: {
flex: 1,
},
button: {
padding: 10,
position: 'absolute',
top: 20,
right: 10,
backgroundColor: '#fff',
},
imageCropContainer: {
flex: 1,
backgroundColor: '#000',
},
});
export default class App extends Component {
constructor(props) {
super(props);
this.state = {
croppedImage: null,
croppedImageRatio: 1,
};
}
onButtonPress() {
this.imageCrop.crop().then((uri) => {
Image.getSize(uri, (width, height) => {
this.setState({
croppedImageRatio: (height / width),
croppedImage: { uri },
});
}, () => {});
});
}
render() {
if (this.state.croppedImage) {
return (
<Image
source={this.state.croppedImage}
resizeMode="stretch"
style={
(this.state.croppedImageRatio <= 1) ? ({
width: WINDOW_WIDTH,
height: WINDOW_WIDTH * this.state.croppedImageRatio,
}) : ({
width: WINDOW_HEIGHT / this.state.croppedImageRatio,
height: WINDOW_HEIGHT,
})
}
/>
);
}
return (
<View style={styles.container}>
<View style={styles.imageCropContainer}>
<ImageCrop
ref={(c) => { this.imageCrop = c; }}
cropWidth={500}
cropHeight={500}
source={{
uri: 'https://c1.staticflickr.com/9/8073/28582653114_d154039cb9_k.jpg',
}}
/>
</View>
<TouchableOpacity
style={styles.button}
onPress={() => this.onButtonPress()}
>
<Text>Crop</Text>
</TouchableOpacity>
</View>
);
}
}