muba-posting 5.0.3 → 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/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,7 +20,10 @@ 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
 
@@ -80,6 +83,8 @@ export default class Publish4 extends React.Component {
80
83
  let imagesArray = this.state.images;
81
84
  imagesArray.push(image);
82
85
 
86
+ this.calculateImageSize(image, imagesArray.length - 1)
87
+
83
88
  this.setState({
84
89
  showErrorNoSelectedImages: false,
85
90
  images: imagesArray
@@ -174,6 +179,58 @@ export default class Publish4 extends React.Component {
174
179
  }, 500);
175
180
  }
176
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
+
177
234
  render() {
178
235
  return (
179
236
  <View style={{ minHeight: this.state.minHeight }}>
@@ -212,9 +269,10 @@ export default class Publish4 extends React.Component {
212
269
  }
213
270
  {this.state.images.map((item, index) => {
214
271
  return (
215
- <ImageBackground style={[commonStyles.photoBox, commonStyles.photoBoxImage]} source={{ uri: item.uri }} borderRadius={10} key={index}
216
- onError={() => this.rerenderImage(index)}>
217
- <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}>
218
276
 
219
277
  <TouchableHighlight style={commonStyles.leftIcon} onPress={() => this.deleteImage(item.id, index)}>
220
278
  <FontAwesomeIcon style={commonStyles.whiteIcon} name="cancel-circled" />
@@ -224,7 +282,7 @@ export default class Publish4 extends React.Component {
224
282
  </TouchableHighlight>
225
283
 
226
284
  </ImageBackground>
227
- </ImageBackground>
285
+ </View>
228
286
  )
229
287
  })}
230
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.3",
3
+ "version": "5.0.4",
4
4
  "description": "Posting",
5
5
  "main": "Posting.js",
6
6
  "scripts": {