-
Notifications
You must be signed in to change notification settings - Fork 0
/
image-view.js
88 lines (71 loc) · 2.04 KB
/
image-view.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
'use strict';
import React, {
StyleSheet,
Component,
requireNativeComponent,
PropTypes,
View
} from 'react-native';
import GPUCropView from './crop-view';
const viewPropTypes = View.propTypes;
export default class GPUImageView extends Component {
static propTypes = {
...viewPropTypes,
gpuImageId: PropTypes.string
};
static defaultProps = {
gpuImage: null
};
setNativeProps(props) {
const nativeProps = Object.assign({}, {
gpuImageId: this.getGPUImageId()
});
this.nativeView.setNativeProps(nativeProps);
}
componentWillReceiveProps(nextProps) {
const oldId = this.getGPUImageId();
const newId = nextProps.gpuImage ? nextProps.gpuImage.id : null;
if (oldId !== newId && oldId !== null) {
this.getGPUImage().releaseView();
}
}
componentWillUnmount() {
const gpuImage = this.getGPUImage();
gpuImage && gpuImage.releaseView();
}
render() {
const style = [styles.base, this.props.style];
const nativeProps = Object.assign({}, {
gpuImageId: this.getGPUImageId()
});
return (
<View style={style}>
<NativeGPUImageView ref={c => this.nativeView = c}
style={styles.child} {...nativeProps} />
{this.props.hasCropper && <GPUCropView ref={c => this.cropView = c} gpuImage={this.getGPUImage()} /> || null}
</View>
);
}
getGPUImage() {
return this.props.gpuImage;
}
getGPUImageId() {
return this.getGPUImage() ? this.getGPUImage().id : null;
}
executeCrop() {
this.cropView && this.cropView.crop();
}
}
const NativeGPUImageView = requireNativeComponent('RCTIONGPUImageView', GPUImageView);
const styles = StyleSheet.create({
base: {
},
child: {
position: 'absolute',
top: 0,
left: 0,
bottom: 0,
right: 0,
backgroundColor: '#00000000'
}
});