muba-posting 5.0.6 → 5.0.9

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 +79 -58
  2. package/package.json +1 -1
package/Publish4.js CHANGED
@@ -61,18 +61,21 @@ 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
+ const photoStr = photo.uri.lastIndexOf('.') > 0 && photo.uri.lastIndexOf('.') > photo.uri.length - 5 ? photo.uri : photo.filename;
67
+ const fileType = photoStr.substring(photoStr.lastIndexOf('.') + 1).toLowerCase();
67
68
 
68
69
  const image = {
69
- uri: imgUri,
70
+ uri: photo.uri,
70
71
  name: 'photo_' + this.state.images.length + '.' + fileType,
71
72
  type: 'image/' + fileType,
72
73
  mainPicture: this.state.images.length === 0,
73
74
  referenceType: 'AD',
74
75
  referenceId: this.props.postingAd.id,
75
- extraInfo: this.state.images.length
76
+ extraInfo: this.state.images.length,
77
+ width: photo.width,
78
+ height: photo.height
76
79
  }
77
80
 
78
81
  this.loadImage(image);
@@ -127,14 +130,19 @@ export default class Publish4 extends React.Component {
127
130
 
128
131
  selectMainPhoto(itemSelected) {
129
132
  let imagesArray = this.state.images.slice();
133
+ let imageSize = this.state.imageSize.slice();
130
134
 
131
135
  for (let imageObject of imagesArray) {
132
136
  imageObject.mainPicture = false;
133
137
 
134
138
  if (imageObject.uri === itemSelected.uri) {
135
139
  imageObject.mainPicture = true;
136
- imagesArray.splice(imagesArray.indexOf(imageObject), 1);
140
+ const imageIndex = imagesArray.indexOf(imageObject);
141
+ imagesArray.splice(imageIndex, 1);
137
142
  imagesArray.splice(0, 0, imageObject);
143
+
144
+ const size = imageSize.splice(imageIndex, 1);
145
+ imageSize.splice(0, 0, ...size);
138
146
  }
139
147
  }
140
148
  let index = 0;
@@ -146,7 +154,8 @@ export default class Publish4 extends React.Component {
146
154
 
147
155
  this.setState({
148
156
  updateMainPhoto: true,
149
- images: imagesArray
157
+ images: imagesArray,
158
+ imageSize: imageSize
150
159
  });
151
160
  }
152
161
 
@@ -187,58 +196,70 @@ export default class Publish4 extends React.Component {
187
196
  }
188
197
 
189
198
  calculateImageSize = async (image) => {
190
- if (!image.uri.startsWith('https://') || await this.imageExists(image.uri)) {
191
- let imageSize = this.state.imageSize;
199
+ if (image.width && image.height) {
200
+ this.setImageSize(image.width, image.height);
201
+ } else if (!image.uri.startsWith('https://') || await this.imageExists(image.uri)) {
192
202
  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
- });
203
+ this.setImageSize(width, height);
204
+ });
205
+ } else {
206
+ setTimeout(() => this.calculateImageSize(image), 500);
207
+ }
208
+ }
209
+
210
+ setImageSize(width, height) {
211
+ let imageSize = this.state.imageSize;
212
+ if (this.state.containerWidth !== 0 && this.state.containerHeight !== 0) {
213
+ const containerRatio = this.state.containerWidth / this.state.containerHeight;
214
+ const imageRatio = width / height;
215
+
216
+ let finalWidth;
217
+ let finalHeight;
218
+ if (imageRatio > containerRatio) {
219
+ if (width > this.state.containerWidth) {
220
+ finalWidth = this.state.containerWidth;
228
221
  } else {
229
- imageSize.push({
230
- width: '100%',
231
- height: '100%',
232
- marginVertical: 0,
233
- marginHorizontal: 0
234
- })
222
+ finalWidth = width;
235
223
  }
236
- this.setState({
237
- imageSize: imageSize
238
- });
224
+ finalHeight = height * (finalWidth / width);
225
+ } else if (imageRatio < containerRatio) {
226
+ if (height > this.state.containerHeight) {
227
+ finalHeight = this.state.containerHeight;
228
+ } else {
229
+ finalHeight = height;
230
+ }
231
+ finalWidth = width * (finalHeight / height);
232
+ } else {
233
+ if (width > this.state.containerWidth) {
234
+ finalWidth = this.state.containerWidth;
235
+ finalHeight = this.state.containerHeight;
236
+ } else {
237
+ finalWidth = width;
238
+ finalHeight = height;
239
+ }
240
+ }
241
+ imageSize.push({
242
+ width: finalWidth,
243
+ height: finalHeight,
244
+ marginVertical: (this.state.containerHeight - finalHeight) / 2,
245
+ marginHorizontal: (this.state.containerWidth - finalWidth) / 2
239
246
  });
240
247
  } else {
241
- setTimeout(() => this.calculateImageSize(image), 500);
248
+ imageSize.push({
249
+ width: '100%',
250
+ height: '100%',
251
+ marginVertical: 0,
252
+ marginHorizontal: 0
253
+ })
254
+ }
255
+ this.setState({
256
+ imageSize: imageSize
257
+ });
258
+ }
259
+
260
+ setContainerWidth = (event) => {
261
+ if (this.state.containerWidth === 0) {
262
+ this.setState({ containerWidth: event.nativeEvent.layout.width, containerHeight: event.nativeEvent.layout.height })
242
263
  }
243
264
  }
244
265
 
@@ -267,7 +288,7 @@ export default class Publish4 extends React.Component {
267
288
  {this.state.allPhotosSelected ?
268
289
  null
269
290
  :
270
- <TouchableOpacity style={[commonStyles.photoBox, this.state.showErrorNoSelectedImages ? commonStyles.fieldError : null]} onPress={() => this.props.openPictureSelector()}>
291
+ <TouchableOpacity onLayout={this.setContainerWidth} style={[commonStyles.photoBox, this.state.showErrorNoSelectedImages ? commonStyles.fieldError : null]} onPress={() => this.props.openPictureSelector()}>
271
292
  <TouchableOpacity style={[commonStyles.photoBoxAddIcon]} onPress={() => this.props.openPictureSelector()}>
272
293
  <TouchableHighlight underlayColor="#104a7a" onPress={() => this.props.openPictureSelector()}>
273
294
  <FontAwesomeIcon style={commonStyles.photoAddIcon} name="plus-circled" />
@@ -280,10 +301,10 @@ export default class Publish4 extends React.Component {
280
301
  }
281
302
  {this.state.images.map((item, index) => {
282
303
  return (
283
- <View style={[commonStyles.photoBox]} onLayout={(event) => this.setState({ containerWidth: event.nativeEvent.layout.width, containerHeight: event.nativeEvent.layout.height })} key={index}>
304
+ <View style={[commonStyles.photoBox]} onLayout={this.setContainerWidth} key={index}>
284
305
  <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
- resizeMode='center' source={{ uri: item.uri }} borderRadius={10} onError={() => this.rerenderImage(index)} />
286
- <ImageBackground style={[commonStyles.photoControls, commonStyles.row]} source={require('./assets/images/bg-shadow.png')} resizeMode='center' borderRadius={1.5}>
306
+ resizeMode='cover' source={{ uri: item.uri }} borderRadius={10} onError={() => this.rerenderImage(index)} />
307
+ <ImageBackground style={[commonStyles.photoControls, commonStyles.row]} source={require('./assets/images/bg-shadow.png')} resizeMode='stretch' borderRadius={1.5}>
287
308
 
288
309
  <TouchableHighlight style={commonStyles.leftIcon} onPress={() => this.deleteImage(item.id, index)}>
289
310
  <FontAwesomeIcon style={commonStyles.whiteIcon} name="cancel-circled" />
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "muba-posting",
3
- "version": "5.0.6",
3
+ "version": "5.0.9",
4
4
  "description": "Posting",
5
5
  "main": "Posting.js",
6
6
  "scripts": {