muba-posting 5.0.2 → 5.0.4

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.
package/Posting.js CHANGED
@@ -35,6 +35,7 @@ const BUSINESS_PRODUCTS = { method: 'GET', url: '/controller/products/{key}/rema
35
35
  const MAX_PICTURES = { method: 'GET', url: '/controller/posting/max-pictures' };
36
36
  const COUNTRY_PHONE = { method: 'GET', url: '/controller/countries/{countryCode}/phones' };
37
37
  const LOAD_PENDING_CREATED = { method: 'GET', url: '/controller/ads/pending-created/posting' };
38
+ const PAYMENT_ONLINE_ACTIVE = { method: 'GET', url: '/controller/payments-online/{countryCode}/active' };
38
39
 
39
40
  export default class Posting extends React.Component {
40
41
  constructor(props) {
@@ -65,7 +66,6 @@ export default class Posting extends React.Component {
65
66
  countryPhone: '',
66
67
  businessId: this.props.businessId,
67
68
  picturesUploaded: 0,
68
- images: [],
69
69
  params: null,
70
70
  postingAd: {
71
71
  transaction: null,
@@ -400,6 +400,11 @@ export default class Posting extends React.Component {
400
400
  } else {
401
401
  await this.setState({ postingAd: { ...this.state.postingAd, adId: response.id } });
402
402
  this._goToPage(Views.PREVIEW, null, response);
403
+
404
+ const paymentOnlineActive = await this.props.request(this, PAYMENT_ONLINE_ACTIVE, { regionId: this.state.postingAd.region });
405
+ if (!this.businessId && paymentOnlineActive.value === 'true') {
406
+ this._goToPage(Views.PAYMENT_ONLINE);
407
+ }
403
408
  }
404
409
  this._hideLoading();
405
410
 
@@ -427,8 +432,11 @@ export default class Posting extends React.Component {
427
432
 
428
433
  imageBrowserCallback = async (photos) => {
429
434
  this.setState({
430
- showImageBrowser: false,
431
- images: photos
435
+ showImageBrowser: false
436
+ }, () => {
437
+ for (let photo of photos) {
438
+ this.publish4?.loadUri(photo)
439
+ }
432
440
  });
433
441
  }
434
442
 
@@ -442,9 +450,8 @@ export default class Posting extends React.Component {
442
450
 
443
451
  _savePicture = async (picture) => {
444
452
  this.setState({
445
- showImageBrowser: false,
446
- images: [picture]
447
- });
453
+ showImageBrowser: false
454
+ }, () => this.publish4?.loadUri(picture));
448
455
  }
449
456
 
450
457
  render() {
@@ -552,6 +559,7 @@ export default class Posting extends React.Component {
552
559
 
553
560
  {this.state.view === Views.PUBLISH_4 ?
554
561
  <Publish4 postingAd={this.state.postingAd}
562
+ ref={publish4 => this.publish4 = publish4}
555
563
  saveEditAd={() => this._saveEditAd()}
556
564
  goToPage={(view) => this._goToPage(view)}
557
565
  request={this.props.request}
@@ -562,8 +570,7 @@ export default class Posting extends React.Component {
562
570
  progressBarHeight={this.state.progressBarHeight}
563
571
  headerHeight={this.state.headerHeight}
564
572
  openPictureSelector={() => this._openPictureSelector()}
565
- maxPictures={this.state.maxPictures}
566
- images={this.state.images} />
573
+ maxPictures={this.state.maxPictures} />
567
574
  :
568
575
  null
569
576
  }
@@ -642,7 +649,7 @@ export default class Posting extends React.Component {
642
649
  }
643
650
 
644
651
  </CustomScrollView>
645
- <PopupAdvice icon={<FontAwesomeIcon name='block' />} title={strings('setup.noPromoteTitle', { product: '' })} headerColor={commonStyles.red} ref={(popupAdvice) => { this.popupNoListings = popupAdvice; }}
652
+ <PopupAdvice icon={<FontAwesomeIcon name='block' />} title={strings('setup.noPromoteTitle', { product: '' })} headerColor={commonStyles.red} ref={popupAdvice => this.popupNoListings = popupAdvice}
646
653
  onClose={async () => this.state.view !== Views.PREVIEW ? this.goBack() : null} hideButton={true}>
647
654
  <OutputText style={commonStyles.popupText}>{strings('setup.noPromoteSubtitle', { countryPhone: this.state.countryPhone })}</OutputText>
648
655
  <TouchableOpacity style={[commonStyles.okBtnBoxPopup, commonStyles.okBtnPopup]} onPress={() => this.popupNoListings.hide()} >
package/Publish4.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { Text, View, TouchableHighlight, TouchableOpacity, ImageBackground, Dimensions } from 'react-native';
2
+ import { Text, View, TouchableHighlight, TouchableOpacity, ImageBackground, Dimensions, Image } from 'react-native';
3
3
  import PopupAdvice from 'muba-popup-advice';
4
4
  import { strings } from 'muba-i18n';
5
5
  import commonStyles from './commonStyles';
@@ -20,12 +20,15 @@ export default class Publish4 extends React.Component {
20
20
  allPhotosSelected: false,
21
21
  updateMainPhoto: false,
22
22
  isLoading: false,
23
- imageBrowserOpen: false
23
+ imageBrowserOpen: false,
24
+ imageSize: [],
25
+ containerWidth: 0,
26
+ containerHeight: 0
24
27
  }
25
28
  }
26
29
 
27
30
  componentDidMount() {
28
- for (let photo of this.props.images) {
31
+ for (let photo of this.props.postingAd.images) {
29
32
  this.loadImage(photo);
30
33
  }
31
34
 
@@ -37,9 +40,9 @@ export default class Publish4 extends React.Component {
37
40
  }
38
41
 
39
42
  componentDidUpdate = async (prevProps) => {
40
- if (!this.isSameList(prevProps.images, this.props.images)) {
43
+ if (!this.isSameList(prevProps.postingAd.images, this.props.postingAd.images)) {
41
44
  this.setState({ images: [] }, () => {
42
- for (let photo of this.props.images) {
45
+ for (let photo of this.props.postingAd.images) {
43
46
  this.loadImage(photo);
44
47
  }
45
48
  });
@@ -58,7 +61,7 @@ export default class Publish4 extends React.Component {
58
61
  return true;
59
62
  }
60
63
 
61
- async loadImage(imgUri) {
64
+ async loadUri(imgUri) {
62
65
  if (imgUri) {
63
66
  let fileType = imgUri.substring(imgUri.lastIndexOf('.') + 1).toLowerCase();
64
67
 
@@ -72,20 +75,26 @@ export default class Publish4 extends React.Component {
72
75
  extraInfo: this.state.images.length
73
76
  }
74
77
 
75
- let imagesArray = this.state.images;
76
- imagesArray.push(image);
78
+ this.loadImage(image);
79
+ }
80
+ }
77
81
 
78
- await this.setState({
79
- showErrorNoSelectedImages: false,
80
- images: imagesArray
81
- });
82
+ loadImage(image) {
83
+ let imagesArray = this.state.images;
84
+ imagesArray.push(image);
82
85
 
86
+ this.calculateImageSize(image, imagesArray.length - 1)
87
+
88
+ this.setState({
89
+ showErrorNoSelectedImages: false,
90
+ images: imagesArray
91
+ }, () => {
83
92
  if (this.state.images.length == this.props.maxPictures) {
84
93
  this.setState({ allPhotosSelected: true });
85
94
  } else if (this.state.images.length == 1) {
86
95
  this.selectMainPhoto(this.state.images[0]);
87
96
  }
88
- }
97
+ });
89
98
  }
90
99
 
91
100
  async deleteImage(itemId, index) {
@@ -170,6 +179,58 @@ export default class Publish4 extends React.Component {
170
179
  }, 500);
171
180
  }
172
181
 
182
+ calculateImageSize = (image) => {
183
+ let imageSize = this.state.imageSize;
184
+ Image.getSize(image.uri, (width, height) => {
185
+ if (this.state.containerWidth !== 0 && this.state.containerHeight !== 0) {
186
+ const containerRatio = this.state.containerWidth / this.state.containerHeight;
187
+ const imageRatio = width / height;
188
+
189
+ let finalWidth;
190
+ let finalHeight;
191
+ if (imageRatio > containerRatio) {
192
+ if (width > this.state.containerWidth) {
193
+ finalWidth = this.state.containerWidth;
194
+ } else {
195
+ finalWidth = width;
196
+ }
197
+ finalHeight = height * (finalWidth / width);
198
+ } else if (imageRatio < containerRatio) {
199
+ if (height > this.state.containerHeight) {
200
+ finalHeight = this.state.containerHeight;
201
+ } else {
202
+ finalHeight = height;
203
+ }
204
+ finalWidth = width * (finalHeight / height);
205
+ } else {
206
+ if (width > this.state.containerWidth) {
207
+ finalWidth = this.state.containerWidth;
208
+ finalHeight = this.state.containerHeight;
209
+ } else {
210
+ finalWidth = width;
211
+ finalHeight = height;
212
+ }
213
+ }
214
+ imageSize.push({
215
+ width: finalWidth,
216
+ height: finalHeight,
217
+ marginVertical: (this.state.containerHeight - finalHeight) / 2,
218
+ marginHorizontal: (this.state.containerWidth - finalWidth) / 2
219
+ });
220
+ } else {
221
+ imageSize.push({
222
+ width: '100%',
223
+ height: '100%',
224
+ marginVertical: 0,
225
+ marginHorizontal: 0
226
+ })
227
+ }
228
+ this.setState({
229
+ imageSize: imageSize
230
+ });
231
+ });
232
+ }
233
+
173
234
  render() {
174
235
  return (
175
236
  <View style={{ minHeight: this.state.minHeight }}>
@@ -208,9 +269,10 @@ export default class Publish4 extends React.Component {
208
269
  }
209
270
  {this.state.images.map((item, index) => {
210
271
  return (
211
- <ImageBackground style={[commonStyles.photoBox, commonStyles.photoBoxImage]} source={{ uri: item.uri }} borderRadius={10} key={index}
212
- onError={() => this.rerenderImage(index)}>
213
- <ImageBackground style={[commonStyles.photoControls, commonStyles.row]} source={require('./assets/images/bg-shadow.png')} resizeMode='stretch' borderRadius={1.5}>
272
+ <View style={[commonStyles.photoBox]} onLayout={(event) => this.setState({ containerWidth: event.nativeEvent.layout.width, containerHeight: event.nativeEvent.layout.height })} key={index}>
273
+ <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 }}
274
+ resizeMode='center' source={{ uri: item.uri }} borderRadius={10} onError={() => this.rerenderImage(index)} />
275
+ <ImageBackground style={[commonStyles.photoControls, commonStyles.row]} source={require('./assets/images/bg-shadow.png')} resizeMode='center' borderRadius={1.5}>
214
276
 
215
277
  <TouchableHighlight style={commonStyles.leftIcon} onPress={() => this.deleteImage(item.id, index)}>
216
278
  <FontAwesomeIcon style={commonStyles.whiteIcon} name="cancel-circled" />
@@ -220,7 +282,7 @@ export default class Publish4 extends React.Component {
220
282
  </TouchableHighlight>
221
283
 
222
284
  </ImageBackground>
223
- </ImageBackground>
285
+ </View>
224
286
  )
225
287
  })}
226
288
  </View>
package/commonStyles.js CHANGED
@@ -576,10 +576,6 @@ export default StyleSheet.create({
576
576
  backgroundColor: '#fff'
577
577
  },
578
578
 
579
- photoBoxImage: {
580
- alignSelf: 'stretch'
581
- },
582
-
583
579
  photoBoxAddIcon: {
584
580
  alignItems: 'center',
585
581
  justifyContent: 'center',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "muba-posting",
3
- "version": "5.0.2",
3
+ "version": "5.0.4",
4
4
  "description": "Posting",
5
5
  "main": "Posting.js",
6
6
  "scripts": {