Skip to content

Commit ce8d63c

Browse files
committed
Image real size added
1 parent b76ea71 commit ce8d63c

5 files changed

Lines changed: 20 additions & 20 deletions

File tree

expo-demo/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"expo": "^31.0.2",
1111
"react": "16.5.0",
1212
"react-native": "https://github.com/expo/react-native/archive/sdk-31.0.0.tar.gz",
13-
"react-native-cn-richtext-editor": "^1.0.28",
13+
"react-native-cn-richtext-editor": "^1.0.29",
1414
"react-native-popup-menu": "^0.14.2"
1515
},
1616
"devDependencies": {

expo-demo/yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3730,10 +3730,10 @@ react-native-branch@2.2.5:
37303730
version "2.2.5"
37313731
resolved "https://registry.yarnpkg.com/react-native-branch/-/react-native-branch-2.2.5.tgz#4074dd63b4973e6397d9ce50e97b57c77a518e9d"
37323732

3733-
react-native-cn-richtext-editor@^1.0.28:
3734-
version "1.0.28"
3735-
resolved "https://registry.yarnpkg.com/react-native-cn-richtext-editor/-/react-native-cn-richtext-editor-1.0.28.tgz#6c076f0c1eba4183f222d06eeef77600f18bff62"
3736-
integrity sha512-PzIbwwj1qIwxW9mcatvXmb8uNamNOYj1mFI1B0Hn/vxaVxksjxQBHBK8DDawF4D28pxhvCp6QlYY7C61QuyJ4Q==
3733+
react-native-cn-richtext-editor@^1.0.29:
3734+
version "1.0.29"
3735+
resolved "https://registry.yarnpkg.com/react-native-cn-richtext-editor/-/react-native-cn-richtext-editor-1.0.29.tgz#98e9b2cd38c1a932ffda39dc18f4ddff5e6a85e5"
3736+
integrity sha512-t3wdl4uYPdx+V3qnbtIYxaeUfjHmWea2YdLnRdnlQUu431FBQg7oqXB1HaLq6JcSS/fIfEoSsLb2ZyUv4W92+w==
37373737
dependencies:
37383738
diff-match-patch "^1.0.4"
37393739
immutability-helper "^2.8.1"

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-cn-richtext-editor",
3-
"version": "1.0.28",
3+
"version": "1.0.29",
44
"description": "RichText Editor for React-Native",
55
"main": "index.js",
66
"scripts": {
@@ -27,11 +27,11 @@
2727
"type": "git",
2828
"url": "git+https://github.com/imnapo/react-native-cn-richtext-editor.git"
2929
},
30-
"author": "Narbe HS <imnapo@gmail.com> (http://learncode.net)",
3130
"contributors": [
3231
"Narbe HS <imnapo@gmail.com> (http://learncode.net)",
3332
"Christ Kho <christ.khodabakhshi@gmail.com> (http://learncode.net)"
3433
],
34+
"author": "Narbe HS <imnapo@gmail.com> (http://learncode.net)",
3535
"license": "ISC",
3636
"bugs": {
3737
"url": "https://github.com/imnapo/react-native-cn-richtext-editor/issues"

src/CNRichTextEditor.js

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -236,16 +236,14 @@ class CNRichTextEditor extends Component {
236236
const { value } = this.props;
237237
let index = focusInputIndex + 1;
238238

239-
let myHeight = (this.layoutWidth - 4 < width) ? height * ((this.layoutWidth - 4) / width) : height;
240-
241239
const item = {
242240
id: shortid.generate(),
243241
imageId: id,
244242
component: 'image',
245243
url: url,
246244
size: {
247-
height: myHeight,
248-
width: (this.layoutWidth - 4 < width) ? this.layoutWidth - 4 : width
245+
height: height,
246+
width: width
249247
}
250248
};
251249

@@ -314,9 +312,7 @@ class CNRichTextEditor extends Component {
314312

315313

316314

317-
if(height != null && width != null) {
318-
319-
315+
if(height != null && width != null) {
320316
this.addImageContent(url, id, height, width);
321317
}
322318
else {
@@ -456,6 +452,9 @@ class CNRichTextEditor extends Component {
456452
}
457453

458454
renderImage(image, index) {
455+
const { width, height } = image.size;
456+
let myHeight = (this.layoutWidth - 4 < width) ? height * ((this.layoutWidth - 4) / width) : height;
457+
let myWidth = (this.layoutWidth - 4 < width) ? this.layoutWidth - 4 : width;
459458

460459
return (
461460
<View key={`image${index}`}
@@ -467,16 +466,15 @@ class CNRichTextEditor extends Component {
467466
paddingLeft: 2,
468467
paddingRight: 2,
469468
paddingTop: 2,
470-
paddingBottom: 2,
469+
paddingBottom: 2
471470
}}
472471
>
473472
<TouchableWithoutFeedback
474473
onPress={() => this.onImageClicked(index)}
475474

476475
>
477476
<Image
478-
479-
style={{width: image.size.width, height: image.size.height
477+
style={{width: myWidth, height: myHeight
480478
, opacity: this.state.imageHighLightedInex === index ? .8 : 1
481479
}}
482480
source={{uri: image.url}}
@@ -488,7 +486,7 @@ class CNRichTextEditor extends Component {
488486
//onSelectionChange={(event) =>this.onSelectionChange(event, index)}
489487
multiline={false}
490488
style={{
491-
fontSize: image.size.height * .65,
489+
fontSize: myHeight * .65,
492490
borderWidth: 0,
493491
paddingBottom:1,
494492
width: 1

src/CNRichTextView.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,11 @@ class CNRichTextView extends Component {
6969
renderImage(image, index) {
7070
const { width, height } = image.size;
7171
const { layoutWidth } = this.state;
72-
let myHeight = height * (layoutWidth / width);
73-
let myWidth = layoutWidth
7472

73+
let myHeight = (layoutWidth - 4 < width) ? height * ((layoutWidth - 4) / width) : height;
74+
let myWidth = (layoutWidth - 4 < width) ? layoutWidth - 4 : width;
75+
76+
7577
return (
7678
<View key={`image${index}`}
7779
style={{

0 commit comments

Comments
 (0)