@plusscommunities/pluss-core-app 1.8.1 → 1.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
2
2
|
|
|
3
3
|
import React, { Component } from 'react';
|
|
4
|
-
import { View, Animated, StyleSheet } from 'react-native';
|
|
4
|
+
import { View, Image, Animated, StyleSheet } from 'react-native';
|
|
5
5
|
import { connect } from 'react-redux';
|
|
6
6
|
import moment from 'moment';
|
|
7
7
|
import { findLandmarkRange, getScaledOffset, get300, detectFaces } from '../helper';
|
|
@@ -12,20 +12,32 @@ class AutoOffsetImage extends Component {
|
|
|
12
12
|
super(props);
|
|
13
13
|
|
|
14
14
|
_defineProperty(this, "onLoad", event => {
|
|
15
|
-
if (event.nativeEvent.source.uri
|
|
16
|
-
//unblur
|
|
15
|
+
if (event.nativeEvent.source.uri !== this.props.uri) {
|
|
17
16
|
this.setState({
|
|
18
|
-
|
|
17
|
+
imageSource: this.props.uri
|
|
19
18
|
});
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
19
|
+
} // if (event.nativeEvent.source.uri === this.props.uri && !this.state.imageLoaded) {
|
|
20
|
+
// //unblur
|
|
21
|
+
// this.setState({
|
|
22
|
+
// imageLoaded: true,
|
|
23
|
+
// });
|
|
24
|
+
// Animated.sequence([
|
|
25
|
+
// Animated.delay(200),
|
|
26
|
+
// Animated.timing(this.state.blurRadius, {
|
|
27
|
+
// toValue: 0,
|
|
28
|
+
// duration: 500,
|
|
29
|
+
// useNativeDriver: false,
|
|
30
|
+
// }),
|
|
31
|
+
// ]).start();
|
|
32
|
+
// }
|
|
33
|
+
|
|
26
34
|
});
|
|
27
35
|
|
|
28
36
|
_defineProperty(this, "positionImage", async () => {
|
|
37
|
+
if (this.state.disabled) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
|
|
29
41
|
try {
|
|
30
42
|
const startTime = moment().valueOf();
|
|
31
43
|
let cachedValues; // check local cache
|
|
@@ -116,7 +128,8 @@ class AutoOffsetImage extends Component {
|
|
|
116
128
|
height: this.props.height
|
|
117
129
|
},
|
|
118
130
|
blurRadius: new Animated.Value(100),
|
|
119
|
-
imageSource: get300(this.props.uri)
|
|
131
|
+
imageSource: get300(this.props.uri),
|
|
132
|
+
disabled: true
|
|
120
133
|
};
|
|
121
134
|
}
|
|
122
135
|
|
|
@@ -131,6 +144,19 @@ class AutoOffsetImage extends Component {
|
|
|
131
144
|
}
|
|
132
145
|
|
|
133
146
|
render() {
|
|
147
|
+
if (this.state.disabled) {
|
|
148
|
+
return /*#__PURE__*/React.createElement(Image, {
|
|
149
|
+
source: {
|
|
150
|
+
uri: this.state.imageSource
|
|
151
|
+
},
|
|
152
|
+
style: [styles.container, styles.staticImage, {
|
|
153
|
+
width: this.props.width,
|
|
154
|
+
height: this.props.height
|
|
155
|
+
}, this.props.style],
|
|
156
|
+
onLoad: this.onLoad
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
|
|
134
160
|
return /*#__PURE__*/React.createElement(View, {
|
|
135
161
|
style: [styles.container, {
|
|
136
162
|
width: this.props.width,
|
|
@@ -157,6 +183,9 @@ const styles = StyleSheet.create({
|
|
|
157
183
|
top: 0,
|
|
158
184
|
left: 0,
|
|
159
185
|
resizeMode: 'cover'
|
|
186
|
+
},
|
|
187
|
+
staticImage: {
|
|
188
|
+
resizeMode: 'cover'
|
|
160
189
|
}
|
|
161
190
|
});
|
|
162
191
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["AutoOffsetImage.js"],"names":["React","Component","View","Animated","StyleSheet","connect","moment","findLandmarkRange","getScaledOffset","get300","detectFaces","saveImagePosition","AutoOffsetImage","constructor","props","event","nativeEvent","source","uri","state","imageLoaded","setState","sequence","delay","timing","blurRadius","toValue","duration","useNativeDriver","start","startTime","valueOf","cachedValues","imagePositions","response","stringActions","getString","encodeURIComponent","data","e","console","log","faces","image","_","isEmpty","add","timestamp","targetWidth","width","targetHeight","height","scaledOffset","landmarkStart","end","landmarkEnd","bounds","imageBounds","offset","y","Math","max","paddingFactor","x","imageStyle","top","left","imageSource","endTime","Value","componentDidMount","positionImage","componentDidUpdate","prevProps","render","styles","container","style","onLoad","children","create","overflow","position","resizeMode","mapStateToProps","media","positions","autoOffsetImage"],"mappings":";;AAAA,OAAOA,KAAP,IAAgBC,SAAhB,QAAiC,OAAjC;AACA,SAASC,IAAT,EAAeC,QAAf,EAAyBC,UAAzB,QAA2C,cAA3C;AACA,SAASC,OAAT,QAAwB,aAAxB;AACA,OAAOC,MAAP,MAAmB,QAAnB;AACA,SAASC,iBAAT,EAA4BC,eAA5B,EAA6CC,MAA7C,EAAqDC,WAArD,QAAwE,WAAxE;AACA,SAASC,iBAAT,QAAkC,YAAlC;;AAEA,MAAMC,eAAN,SAA8BX,SAA9B,CAAwC;AACtCY,EAAAA,WAAW,CAACC,KAAD,EAAQ;AACjB,UAAMA,KAAN;;AADiB,oCAyBVC,KAAK,IAAI;AAChB,UAAIA,KAAK,CAACC,WAAN,CAAkBC,MAAlB,CAAyBC,GAAzB,KAAiC,KAAKJ,KAAL,CAAWI,GAA5C,IAAmD,CAAC,KAAKC,KAAL,CAAWC,WAAnE,EAAgF;AAC9E;AACA,aAAKC,QAAL,CAAc;AACZD,UAAAA,WAAW,EAAE;AADD,SAAd;AAGAjB,QAAAA,QAAQ,CAACmB,QAAT,CAAkB,CAChBnB,QAAQ,CAACoB,KAAT,CAAe,GAAf,CADgB,EAEhBpB,QAAQ,CAACqB,MAAT,CAAgB,KAAKL,KAAL,CAAWM,UAA3B,EAAuC;AACrCC,UAAAA,OAAO,EAAE,CAD4B;AAErCC,UAAAA,QAAQ,EAAE,GAF2B;AAGrCC,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OAFV;AAGE,MAAA,KAAK,EAAE,CAACQ,MAAM,CAAChC,KAAR,EAAe,KAAKxB,KAAL,CAAW6C,UAA1B,CAHT;AAIE,MAAA,MAAM,EAAE,KAAKc;AAJf,MAVF,EAgBG,KAAKhE,KAAL,CAAWiE,QAhBd,CADF;AAoBD;;AAnJqC;;AAsJxC,MAAMJ,MAAM,GAAGvE,UAAU,CAAC4E,MAAX,CAAkB;AAC/BJ,EAAAA,SAAS,EAAE;AACTK,IAAAA,QAAQ,EAAE;AADD,GADoB;AAI/BtC,EAAAA,KAAK,EAAE;AACLuC,IAAAA,QAAQ,EAAE,UADL;AAELjB,IAAAA,GAAG,EAAE,CAFA;AAGLC,IAAAA,IAAI,EAAE,CAHD;AAILiB,IAAAA,UAAU,EAAE;AAJP;AAJwB,CAAlB,CAAf;;AAYA,MAAMC,eAAe,GAAGjE,KAAK,IAAI;AAC/B,SAAO;AACLc,IAAAA,cAAc,EAAEd,KAAK,CAACkE,KAAN,CAAYC;AADvB,GAAP;AAGD,CAJD;;AAMA,MAAMC,eAAe,GAAGlF,OAAO,CAAC+E,eAAD,EAAkB;AAAEzE,EAAAA;AAAF,CAAlB,CAAP,CAAgDC,eAAhD,CAAxB;AACA,SAAS2E,eAAe,IAAI3E,eAA5B","sourcesContent":["import React, { Component } from 'react';\nimport { View, Animated, StyleSheet } from 'react-native';\nimport { connect } from 'react-redux';\nimport moment from 'moment';\nimport { findLandmarkRange, getScaledOffset, get300, detectFaces } from '../helper';\nimport { saveImagePosition } from '../actions';\n\nclass AutoOffsetImage extends Component {\n constructor(props) {\n super(props);\n\n this.paddingFactor = this.props.paddingFactor || 0.1;\n\n this.state = {\n imageStyle: {\n width: this.props.width,\n height: this.props.height,\n },\n blurRadius: new Animated.Value(100),\n imageSource: get300(this.props.uri),\n };\n }\n\n componentDidMount() {\n this.positionImage();\n }\n\n componentDidUpdate(prevProps) {\n if (prevProps.uri !== this.props.uri || prevProps.height !== this.props.height || prevProps.width !== this.props.width) {\n this.positionImage();\n }\n }\n\n onLoad = event => {\n if (event.nativeEvent.source.uri === this.props.uri && !this.state.imageLoaded) {\n //unblur\n this.setState({\n imageLoaded: true,\n });\n Animated.sequence([\n Animated.delay(200),\n Animated.timing(this.state.blurRadius, {\n toValue: 0,\n duration: 500,\n useNativeDriver: false,\n }),\n ]).start();\n }\n };\n\n positionImage = async () => {\n try {\n const startTime = moment().valueOf();\n\n let cachedValues;\n // check local cache\n if (this.props.imagePositions && this.props.imagePositions[this.props.uri]) {\n cachedValues = this.props.imagePositions[this.props.uri];\n }\n // check remote cache\n if (!cachedValues) {\n try {\n const response = await stringActions.getString('plussSpace', `imagefaces_${encodeURIComponent(this.props.uri)}`);\n cachedValues = response.data;\n } catch (e) {\n console.log('errored from cache');\n }\n // run face detection locally\n if (\n !cachedValues ||\n !cachedValues.faces ||\n !cachedValues.image ||\n (_.isEmpty(cachedValues.faces) &&\n moment()\n .add(-1, 'w')\n .valueOf() > moment(cachedValues.timestamp).valueOf())\n ) {\n cachedValues = await detectFaces(this.props.uri);\n }\n this.props.saveImagePosition(this.props.uri, cachedValues);\n }\n\n const image = await findLandmarkRange(this.props.uri, {\n targetWidth: this.props.width,\n targetHeight: this.props.height,\n cachedValues,\n });\n const scaledOffset = getScaledOffset(image.width, image.height, this.props.width, this.props.height);\n\n const { start: landmarkStart, end: landmarkEnd } = image;\n const { bounds: imageBounds, offset, width, height } = scaledOffset;\n\n if (landmarkStart.y < imageBounds.start.y) {\n // move up\n offset.y = -Math.max(landmarkStart.y - this.props.height * this.paddingFactor, 0); // move top to 5% above start of landmark\n } else if (landmarkEnd.y > imageBounds.end.y) {\n // move down\n offset.y = -Math.max(landmarkEnd.y + this.props.height * this.paddingFactor - this.props.height, 0); // move bottom to 5% below end of landmark\n }\n\n if (landmarkStart.x < imageBounds.start.x) {\n // move right\n offset.x = -Math.max(landmarkStart.x - this.props.width * this.paddingFactor, 0); // move left edge to 5% left of start of landmark\n } else if (landmarkEnd.x > imageBounds.end.x) {\n // move left\n offset.x = -Math.max(landmarkEnd.x + this.props.width * this.paddingFactor - this.props.width, 0); // move right edge to 5% left of end of landmark\n }\n\n this.setState({\n imageStyle: {\n width,\n height,\n top: offset.y,\n left: offset.x,\n },\n imageSource: this.props.uri,\n });\n\n const endTime = moment().valueOf();\n if (endTime - startTime < 500) {\n Animated.timing(this.state.blurRadius, {\n toValue: 0,\n duration: 0,\n useNativeDriver: false,\n }).start();\n }\n } catch (e) {\n this.setState({\n imageSource: this.props.uri,\n });\n }\n };\n\n render() {\n return (\n <View\n style={[\n styles.container,\n {\n width: this.props.width,\n height: this.props.height,\n },\n this.props.style,\n ]}\n >\n <Animated.Image\n blurRadius={this.state.blurRadius}\n source={{ uri: this.state.imageSource }}\n style={[styles.image, this.state.imageStyle]}\n onLoad={this.onLoad}\n />\n {this.props.children}\n </View>\n );\n }\n}\n\nconst styles = StyleSheet.create({\n container: {\n overflow: 'hidden',\n },\n image: {\n position: 'absolute',\n top: 0,\n left: 0,\n resizeMode: 'cover',\n },\n});\n\nconst mapStateToProps = state => {\n return {\n imagePositions: state.media.positions,\n };\n};\n\nconst autoOffsetImage = connect(mapStateToProps, { saveImagePosition })(AutoOffsetImage);\nexport { autoOffsetImage as AutoOffsetImage };\n"]}
|
|
1
|
+
{"version":3,"sources":["AutoOffsetImage.js"],"names":["React","Component","View","Image","Animated","StyleSheet","connect","moment","findLandmarkRange","getScaledOffset","get300","detectFaces","saveImagePosition","AutoOffsetImage","constructor","props","event","nativeEvent","source","uri","setState","imageSource","state","disabled","startTime","valueOf","cachedValues","imagePositions","response","stringActions","getString","encodeURIComponent","data","e","console","log","faces","image","_","isEmpty","add","timestamp","targetWidth","width","targetHeight","height","scaledOffset","start","landmarkStart","end","landmarkEnd","bounds","imageBounds","offset","y","Math","max","paddingFactor","x","imageStyle","top","left","endTime","timing","blurRadius","toValue","duration","useNativeDriver","Value","componentDidMount","positionImage","componentDidUpdate","prevProps","render","styles","container","staticImage","style","onLoad","children","create","overflow","position","resiz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M,CAACrC,KAAR,EAAe,KAAKf,KAAL,CAAWqC,UAA1B,CAHT;AAIE,MAAA,MAAM,EAAE,KAAKmB;AAJf,MAVF,EAgBG,KAAK/D,KAAL,CAAWgE,QAhBd,CADF;AAoBD;;AA7KqC;;AAgLxC,MAAML,MAAM,GAAGrE,UAAU,CAAC2E,MAAX,CAAkB;AAC/BL,EAAAA,SAAS,EAAE;AACTM,IAAAA,QAAQ,EAAE;AADD,GADoB;AAI/B5C,EAAAA,KAAK,EAAE;AACL6C,IAAAA,QAAQ,EAAE,UADL;AAELtB,IAAAA,GAAG,EAAE,CAFA;AAGLC,IAAAA,IAAI,EAAE,CAHD;AAILsB,IAAAA,UAAU,EAAE;AAJP,GAJwB;AAU/BP,EAAAA,WAAW,EAAE;AACXO,IAAAA,UAAU,EAAE;AADD;AAVkB,CAAlB,CAAf;;AAeA,MAAMC,eAAe,GAAG9D,KAAK,IAAI;AAC/B,SAAO;AACLK,IAAAA,cAAc,EAAEL,KAAK,CAAC+D,KAAN,CAAYC;AADvB,GAAP;AAGD,CAJD;;AAMA,MAAMC,eAAe,GAAGjF,OAAO,CAAC8E,eAAD,EAAkB;AAAExE,EAAAA;AAAF,CAAlB,CAAP,CAAgDC,eAAhD,CAAxB;AACA,SAAS0E,eAAe,IAAI1E,eAA5B","sourcesContent":["import React, { Component } from 'react';\nimport { View, Image, Animated, StyleSheet } from 'react-native';\nimport { connect } from 'react-redux';\nimport moment from 'moment';\nimport { findLandmarkRange, getScaledOffset, get300, detectFaces } from '../helper';\nimport { saveImagePosition } from '../actions';\n\nclass AutoOffsetImage extends Component {\n constructor(props) {\n super(props);\n\n this.paddingFactor = this.props.paddingFactor || 0.1;\n\n this.state = {\n imageStyle: {\n width: this.props.width,\n height: this.props.height,\n },\n blurRadius: new Animated.Value(100),\n imageSource: get300(this.props.uri),\n disabled: true,\n };\n }\n\n componentDidMount() {\n this.positionImage();\n }\n\n componentDidUpdate(prevProps) {\n if (prevProps.uri !== this.props.uri || prevProps.height !== this.props.height || prevProps.width !== this.props.width) {\n this.positionImage();\n }\n }\n\n onLoad = event => {\n if (event.nativeEvent.source.uri !== this.props.uri) {\n this.setState({\n imageSource: this.props.uri,\n });\n }\n // if (event.nativeEvent.source.uri === this.props.uri && !this.state.imageLoaded) {\n // //unblur\n // this.setState({\n // imageLoaded: true,\n // });\n // Animated.sequence([\n // Animated.delay(200),\n // Animated.timing(this.state.blurRadius, {\n // toValue: 0,\n // duration: 500,\n // useNativeDriver: false,\n // }),\n // ]).start();\n // }\n };\n\n positionImage = async () => {\n if (this.state.disabled) {\n return;\n }\n try {\n const startTime = moment().valueOf();\n\n let cachedValues;\n // check local cache\n if (this.props.imagePositions && this.props.imagePositions[this.props.uri]) {\n cachedValues = this.props.imagePositions[this.props.uri];\n }\n // check remote cache\n if (!cachedValues) {\n try {\n const response = await stringActions.getString('plussSpace', `imagefaces_${encodeURIComponent(this.props.uri)}`);\n cachedValues = response.data;\n } catch (e) {\n console.log('errored from cache');\n }\n // run face detection locally\n if (\n !cachedValues ||\n !cachedValues.faces ||\n !cachedValues.image ||\n (_.isEmpty(cachedValues.faces) &&\n moment()\n .add(-1, 'w')\n .valueOf() > moment(cachedValues.timestamp).valueOf())\n ) {\n cachedValues = await detectFaces(this.props.uri);\n }\n this.props.saveImagePosition(this.props.uri, cachedValues);\n }\n\n const image = await findLandmarkRange(this.props.uri, {\n targetWidth: this.props.width,\n targetHeight: this.props.height,\n cachedValues,\n });\n const scaledOffset = getScaledOffset(image.width, image.height, this.props.width, this.props.height);\n\n const { start: landmarkStart, end: landmarkEnd } = image;\n const { bounds: imageBounds, offset, width, height } = scaledOffset;\n\n if (landmarkStart.y < imageBounds.start.y) {\n // move up\n offset.y = -Math.max(landmarkStart.y - this.props.height * this.paddingFactor, 0); // move top to 5% above start of landmark\n } else if (landmarkEnd.y > imageBounds.end.y) {\n // move down\n offset.y = -Math.max(landmarkEnd.y + this.props.height * this.paddingFactor - this.props.height, 0); // move bottom to 5% below end of landmark\n }\n\n if (landmarkStart.x < imageBounds.start.x) {\n // move right\n offset.x = -Math.max(landmarkStart.x - this.props.width * this.paddingFactor, 0); // move left edge to 5% left of start of landmark\n } else if (landmarkEnd.x > imageBounds.end.x) {\n // move left\n offset.x = -Math.max(landmarkEnd.x + this.props.width * this.paddingFactor - this.props.width, 0); // move right edge to 5% left of end of landmark\n }\n\n this.setState({\n imageStyle: {\n width,\n height,\n top: offset.y,\n left: offset.x,\n },\n imageSource: this.props.uri,\n });\n\n const endTime = moment().valueOf();\n if (endTime - startTime < 500) {\n Animated.timing(this.state.blurRadius, {\n toValue: 0,\n duration: 0,\n useNativeDriver: false,\n }).start();\n }\n } catch (e) {\n this.setState({\n imageSource: this.props.uri,\n });\n }\n };\n\n render() {\n if (this.state.disabled) {\n return (\n <Image\n source={{ uri: this.state.imageSource }}\n style={[\n styles.container,\n styles.staticImage,\n {\n width: this.props.width,\n height: this.props.height,\n },\n this.props.style,\n ]}\n onLoad={this.onLoad}\n />\n );\n }\n return (\n <View\n style={[\n styles.container,\n {\n width: this.props.width,\n height: this.props.height,\n },\n this.props.style,\n ]}\n >\n <Animated.Image\n blurRadius={this.state.blurRadius}\n source={{ uri: this.state.imageSource }}\n style={[styles.image, this.state.imageStyle]}\n onLoad={this.onLoad}\n />\n {this.props.children}\n </View>\n );\n }\n}\n\nconst styles = StyleSheet.create({\n container: {\n overflow: 'hidden',\n },\n image: {\n position: 'absolute',\n top: 0,\n left: 0,\n resizeMode: 'cover',\n },\n staticImage: {\n resizeMode: 'cover',\n },\n});\n\nconst mapStateToProps = state => {\n return {\n imagePositions: state.media.positions,\n };\n};\n\nconst autoOffsetImage = connect(mapStateToProps, { saveImagePosition })(AutoOffsetImage);\nexport { autoOffsetImage as AutoOffsetImage };\n"]}
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { Component } from 'react';
|
|
2
|
-
import { View, Animated, StyleSheet } from 'react-native';
|
|
2
|
+
import { View, Image, Animated, StyleSheet } from 'react-native';
|
|
3
3
|
import { connect } from 'react-redux';
|
|
4
4
|
import moment from 'moment';
|
|
5
5
|
import { findLandmarkRange, getScaledOffset, get300, detectFaces } from '../helper';
|
|
@@ -18,6 +18,7 @@ class AutoOffsetImage extends Component {
|
|
|
18
18
|
},
|
|
19
19
|
blurRadius: new Animated.Value(100),
|
|
20
20
|
imageSource: get300(this.props.uri),
|
|
21
|
+
disabled: true,
|
|
21
22
|
};
|
|
22
23
|
}
|
|
23
24
|
|
|
@@ -32,23 +33,31 @@ class AutoOffsetImage extends Component {
|
|
|
32
33
|
}
|
|
33
34
|
|
|
34
35
|
onLoad = event => {
|
|
35
|
-
if (event.nativeEvent.source.uri
|
|
36
|
-
//unblur
|
|
36
|
+
if (event.nativeEvent.source.uri !== this.props.uri) {
|
|
37
37
|
this.setState({
|
|
38
|
-
|
|
38
|
+
imageSource: this.props.uri,
|
|
39
39
|
});
|
|
40
|
-
Animated.sequence([
|
|
41
|
-
Animated.delay(200),
|
|
42
|
-
Animated.timing(this.state.blurRadius, {
|
|
43
|
-
toValue: 0,
|
|
44
|
-
duration: 500,
|
|
45
|
-
useNativeDriver: false,
|
|
46
|
-
}),
|
|
47
|
-
]).start();
|
|
48
40
|
}
|
|
41
|
+
// if (event.nativeEvent.source.uri === this.props.uri && !this.state.imageLoaded) {
|
|
42
|
+
// //unblur
|
|
43
|
+
// this.setState({
|
|
44
|
+
// imageLoaded: true,
|
|
45
|
+
// });
|
|
46
|
+
// Animated.sequence([
|
|
47
|
+
// Animated.delay(200),
|
|
48
|
+
// Animated.timing(this.state.blurRadius, {
|
|
49
|
+
// toValue: 0,
|
|
50
|
+
// duration: 500,
|
|
51
|
+
// useNativeDriver: false,
|
|
52
|
+
// }),
|
|
53
|
+
// ]).start();
|
|
54
|
+
// }
|
|
49
55
|
};
|
|
50
56
|
|
|
51
57
|
positionImage = async () => {
|
|
58
|
+
if (this.state.disabled) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
52
61
|
try {
|
|
53
62
|
const startTime = moment().valueOf();
|
|
54
63
|
|
|
@@ -132,6 +141,23 @@ class AutoOffsetImage extends Component {
|
|
|
132
141
|
};
|
|
133
142
|
|
|
134
143
|
render() {
|
|
144
|
+
if (this.state.disabled) {
|
|
145
|
+
return (
|
|
146
|
+
<Image
|
|
147
|
+
source={{ uri: this.state.imageSource }}
|
|
148
|
+
style={[
|
|
149
|
+
styles.container,
|
|
150
|
+
styles.staticImage,
|
|
151
|
+
{
|
|
152
|
+
width: this.props.width,
|
|
153
|
+
height: this.props.height,
|
|
154
|
+
},
|
|
155
|
+
this.props.style,
|
|
156
|
+
]}
|
|
157
|
+
onLoad={this.onLoad}
|
|
158
|
+
/>
|
|
159
|
+
);
|
|
160
|
+
}
|
|
135
161
|
return (
|
|
136
162
|
<View
|
|
137
163
|
style={[
|
|
@@ -165,6 +191,9 @@ const styles = StyleSheet.create({
|
|
|
165
191
|
left: 0,
|
|
166
192
|
resizeMode: 'cover',
|
|
167
193
|
},
|
|
194
|
+
staticImage: {
|
|
195
|
+
resizeMode: 'cover',
|
|
196
|
+
},
|
|
168
197
|
});
|
|
169
198
|
|
|
170
199
|
const mapStateToProps = state => {
|