-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathindex.js
111 lines (97 loc) · 2.68 KB
/
index.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/**
* Created by lvbingru on 6/21/16.
*/
// GPUImageView.js
import React, {
Component,
PropTypes,
} from 'react';
import {
requireNativeComponent, Platform, NativeModules, Image,
UIManager,
findNodeHandle,
} from 'react-native'
const GPUImageViewManager = NativeModules.GPUImageViewManager;
class GPUImageView extends Component {
onCaptureDone = (ev) => {
const capturing = this.capturing;
this.capturing = null;
capturing && capturing.resolve(ev.nativeEvent);
};
onCaptureFailed = ev => {
const capturing = this.capturing;
this.capturing = null;
capturing && capturing.reject(new Error(ev.nativeEvent.message));
};
render() {
if (Platform.OS === 'ios') {
return <RCTGPUImageView {...this.props} />;
}
else {
var source = this.props.source;
var loadingIndicatorSource = this.props.loadingIndicatorSource;
// As opposed to the ios version, here it render `null`
// when no source or source.uri... so let's not break that.
if (source && source.uri === '') {
console.warn('source.uri should not be an empty string');
}
if (source && source.uri) {
var style = this.props.style;
var {onLoadStart, onLoad, onLoadEnd} = this.props;
var nativeProps = {...this.props,
style,
shouldNotifyLoadEvents: !!(onLoadStart || onLoad || onLoadEnd),
src: source.uri,
loadingIndicatorSrc: loadingIndicatorSource ? loadingIndicatorSource.uri : null,
onCaptureDone: this.onCaptureDone,
onCaptureFailed: this.onCaptureFailed,
};
return <RCTGPUImageView {...nativeProps} />;
}
else {
return null
}
}
}
capture() {
if (Platform.OS === 'ios'){
return GPUImageViewManager.capture(findNodeHandle(this));
}
if (this.capturing) {
return Promise.reject('isCapturing');
}
UIManager.dispatchViewManagerCommand(
findNodeHandle(this),
UIManager.RCTGPUImageView.Commands.capture,
null
);
return new Promise((resolve, reject)=>{
this.capturing = {resolve, reject};
});
}
}
GPUImageView.propTypes = {
filters: PropTypes.array,
onGetSize : PropTypes.func,
...Image.propTypes,
};
var cfg = {
nativeOnly: {
},
};
if (Platform.OS === 'android') {
cfg.nativeOnly = {
...cfg.nativeOnly,
src: true,
loadingIndicatorSrc: true,
defaultImageSrc: true,
imageTag: true,
progressHandlerRegistered: true,
shouldNotifyLoadEvents: true,
onCaptureDone: true,
onCaptureFailed: true,
onGetSize : true,
}
}
var RCTGPUImageView = requireNativeComponent('RCTGPUImageView', GPUImageView, cfg)
module.exports = GPUImageView;