Skip to content

Commit c932aef

Browse files
committed
Add support for ImageComponent prop
1 parent a6a6167 commit c932aef

3 files changed

Lines changed: 7 additions & 8 deletions

File tree

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ yarn add react-native-cn-richtext-editor
2121

2222
Here is a simple overview of our components usage.
2323

24-
```
24+
``` jsx
2525
import React, { Component } from 'react';
2626
import { View, StyleSheet, Keyboard
2727
, TouchableWithoutFeedback, Text
@@ -176,8 +176,10 @@ Also be noticed that this example is writen with expo and required 'react-native
176176
| onSelectedTagChanged | this event triggers when selected tag of editor is changed. | No |
177177
| onSelectedStyleChanged | this event triggers when selected style of editor is changed. | No |
178178
| onValueChanged | this event triggers when value of editor is changed. | No |
179+
| onRemoveImage | this event triggers when an image is removed. Callback param in the form `{ uri, id }`. | No |
179180
| value | an array object which keeps value of the editor | Yes |
180181
| styleList | an object consist of styles name and values (use getDefaultStyles function) | Yes |
182+
| ImageComponent | a React component (class or functional) which will be used to render images. Will be passed `style` and `source` props. | No |
181183

182184
### CNToolbar
183185

src/CNRichTextEditor.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ class CNRichTextEditor extends Component {
450450
const { width, height } = image.size;
451451
let myHeight = (this.state.layoutWidth - 4 < width) ? height * ((this.state.layoutWidth - 4) / width) : height;
452452
let myWidth = (this.state.layoutWidth - 4 < width) ? this.state.layoutWidth - 4 : width;
453-
453+
const { ImageComponent = Image } = this.props
454454
return (
455455
<View key={`image${index}`}
456456
style={{
@@ -468,15 +468,14 @@ class CNRichTextEditor extends Component {
468468
onPress={() => this.onImageClicked(index)}
469469

470470
>
471-
<Image
471+
<ImageComponent
472472
style={{width: myWidth, height: myHeight
473473
, opacity: this.state.imageHighLightedInex === index ? .8 : 1
474474
}}
475475
source={{uri: image.url}}
476476
/>
477477
</TouchableWithoutFeedback>
478478
<TextInput
479-
480479
onKeyPress={(event) => this.handleKeyDown(event, index)}
481480
//onSelectionChange={(event) =>this.onSelectionChange(event, index)}
482481
multiline={false}

src/CNRichTextView.js

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

76-
7776
return (
7877
<View key={`image${index}`}
7978
style={{
@@ -82,8 +81,7 @@ class CNRichTextView extends Component {
8281
}}
8382
>
8483
<View>
85-
<Image
86-
84+
<ImageComponent
8785
style={{
8886
width: myWidth, height: myHeight
8987
, opacity: this.state.imageHighLightedInex === index ? .8 : 1

0 commit comments

Comments
 (0)