muba-posting 5.0.6 → 5.0.7

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.
Files changed (2) hide show
  1. package/Publish4.js +68 -54
  2. package/package.json +1 -1
package/Publish4.js CHANGED
@@ -61,18 +61,20 @@ export default class Publish4 extends React.Component {
61
61
  return true;
62
62
  }
63
63
 
64
- async loadUri(imgUri) {
65
- if (imgUri) {
66
- let fileType = imgUri.substring(imgUri.lastIndexOf('.') + 1).toLowerCase();
64
+ async loadUri(photo) {
65
+ if (photo) {
66
+ let fileType = photo.uri.substring(photo.uri.lastIndexOf('.') + 1).toLowerCase();
67
67
 
68
68
  const image = {
69
- uri: imgUri,
69
+ uri: photo.uri,
70
70
  name: 'photo_' + this.state.images.length + '.' + fileType,
71
71
  type: 'image/' + fileType,
72
72
  mainPicture: this.state.images.length === 0,
73
73
  referenceType: 'AD',
74
74
  referenceId: this.props.postingAd.id,
75
- extraInfo: this.state.images.length
75
+ extraInfo: this.state.images.length,
76
+ width: photo.width,
77
+ height: photo.height
76
78
  }
77
79
 
78
80
  this.loadImage(image);
@@ -187,58 +189,70 @@ export default class Publish4 extends React.Component {
187
189
  }
188
190
 
189
191
  calculateImageSize = async (image) => {
190
- if (!image.uri.startsWith('https://') || await this.imageExists(image.uri)) {
191
- let imageSize = this.state.imageSize;
192
+ if (image.width && image.height) {
193
+ this.setImageSize(image.width, image.height);
194
+ } else if (!image.uri.startsWith('https://') || await this.imageExists(image.uri)) {
192
195
  Image.getSize(image.uri, (width, height) => {
193
- if (this.state.containerWidth !== 0 && this.state.containerHeight !== 0) {
194
- const containerRatio = this.state.containerWidth / this.state.containerHeight;
195
- const imageRatio = width / height;
196
-
197
- let finalWidth;
198
- let finalHeight;
199
- if (imageRatio > containerRatio) {
200
- if (width > this.state.containerWidth) {
201
- finalWidth = this.state.containerWidth;
202
- } else {
203
- finalWidth = width;
204
- }
205
- finalHeight = height * (finalWidth / width);
206
- } else if (imageRatio < containerRatio) {
207
- if (height > this.state.containerHeight) {
208
- finalHeight = this.state.containerHeight;
209
- } else {
210
- finalHeight = height;
211
- }
212
- finalWidth = width * (finalHeight / height);
213
- } else {
214
- if (width > this.state.containerWidth) {
215
- finalWidth = this.state.containerWidth;
216
- finalHeight = this.state.containerHeight;
217
- } else {
218
- finalWidth = width;
219
- finalHeight = height;
220
- }
221
- }
222
- imageSize.push({
223
- width: finalWidth,
224
- height: finalHeight,
225
- marginVertical: (this.state.containerHeight - finalHeight) / 2,
226
- marginHorizontal: (this.state.containerWidth - finalWidth) / 2
227
- });
196
+ this.setImageSize(width, height);
197
+ });
198
+ } else {
199
+ setTimeout(() => this.calculateImageSize(image), 500);
200
+ }
201
+ }
202
+
203
+ setImageSize(width, height) {
204
+ let imageSize = this.state.imageSize;
205
+ if (this.state.containerWidth !== 0 && this.state.containerHeight !== 0) {
206
+ const containerRatio = this.state.containerWidth / this.state.containerHeight;
207
+ const imageRatio = width / height;
208
+
209
+ let finalWidth;
210
+ let finalHeight;
211
+ if (imageRatio > containerRatio) {
212
+ if (width > this.state.containerWidth) {
213
+ finalWidth = this.state.containerWidth;
214
+ } else {
215
+ finalWidth = width;
216
+ }
217
+ finalHeight = height * (finalWidth / width);
218
+ } else if (imageRatio < containerRatio) {
219
+ if (height > this.state.containerHeight) {
220
+ finalHeight = this.state.containerHeight;
228
221
  } else {
229
- imageSize.push({
230
- width: '100%',
231
- height: '100%',
232
- marginVertical: 0,
233
- marginHorizontal: 0
234
- })
222
+ finalHeight = height;
235
223
  }
236
- this.setState({
237
- imageSize: imageSize
238
- });
224
+ finalWidth = width * (finalHeight / height);
225
+ } else {
226
+ if (width > this.state.containerWidth) {
227
+ finalWidth = this.state.containerWidth;
228
+ finalHeight = this.state.containerHeight;
229
+ } else {
230
+ finalWidth = width;
231
+ finalHeight = height;
232
+ }
233
+ }
234
+ imageSize.push({
235
+ width: finalWidth,
236
+ height: finalHeight,
237
+ marginVertical: (this.state.containerHeight - finalHeight) / 2,
238
+ marginHorizontal: (this.state.containerWidth - finalWidth) / 2
239
239
  });
240
240
  } else {
241
- setTimeout(() => this.calculateImageSize(image), 500);
241
+ imageSize.push({
242
+ width: '100%',
243
+ height: '100%',
244
+ marginVertical: 0,
245
+ marginHorizontal: 0
246
+ })
247
+ }
248
+ this.setState({
249
+ imageSize: imageSize
250
+ });
251
+ }
252
+
253
+ setContainerWidth = (event) => {
254
+ if (this.state.containerWidth === 0) {
255
+ this.setState({ containerWidth: event.nativeEvent.layout.width, containerHeight: event.nativeEvent.layout.height })
242
256
  }
243
257
  }
244
258
 
@@ -267,7 +281,7 @@ export default class Publish4 extends React.Component {
267
281
  {this.state.allPhotosSelected ?
268
282
  null
269
283
  :
270
- <TouchableOpacity style={[commonStyles.photoBox, this.state.showErrorNoSelectedImages ? commonStyles.fieldError : null]} onPress={() => this.props.openPictureSelector()}>
284
+ <TouchableOpacity onLayout={this.setContainerWidth} style={[commonStyles.photoBox, this.state.showErrorNoSelectedImages ? commonStyles.fieldError : null]} onPress={() => this.props.openPictureSelector()}>
271
285
  <TouchableOpacity style={[commonStyles.photoBoxAddIcon]} onPress={() => this.props.openPictureSelector()}>
272
286
  <TouchableHighlight underlayColor="#104a7a" onPress={() => this.props.openPictureSelector()}>
273
287
  <FontAwesomeIcon style={commonStyles.photoAddIcon} name="plus-circled" />
@@ -280,7 +294,7 @@ export default class Publish4 extends React.Component {
280
294
  }
281
295
  {this.state.images.map((item, index) => {
282
296
  return (
283
- <View style={[commonStyles.photoBox]} onLayout={(event) => this.setState({ containerWidth: event.nativeEvent.layout.width, containerHeight: event.nativeEvent.layout.height })} key={index}>
297
+ <View style={[commonStyles.photoBox]} onLayout={this.setContainerWidth} key={index}>
284
298
  <Image style={{ width: this.state.imageSize[index]?.width, height: this.state.imageSize[index]?.height, marginVertical: this.state.imageSize[index]?.marginVertical, marginHorizontal: this.state.imageSize[index]?.marginHorizontal }}
285
299
  resizeMode='center' source={{ uri: item.uri }} borderRadius={10} onError={() => this.rerenderImage(index)} />
286
300
  <ImageBackground style={[commonStyles.photoControls, commonStyles.row]} source={require('./assets/images/bg-shadow.png')} resizeMode='center' borderRadius={1.5}>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "muba-posting",
3
- "version": "5.0.6",
3
+ "version": "5.0.7",
4
4
  "description": "Posting",
5
5
  "main": "Posting.js",
6
6
  "scripts": {