Skip to content

Commit

Permalink
Merge pull request #29 from jsamr/image-component
Browse files Browse the repository at this point in the history
Add support for ImageComponent prop
  • Loading branch information
imnapo authored Mar 20, 2019
2 parents a6a6167 + c932aef commit 4db4cc8
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ yarn add react-native-cn-richtext-editor

Here is a simple overview of our components usage.

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

### CNToolbar

Expand Down
5 changes: 2 additions & 3 deletions src/CNRichTextEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ class CNRichTextEditor extends Component {
const { width, height } = image.size;
let myHeight = (this.state.layoutWidth - 4 < width) ? height * ((this.state.layoutWidth - 4) / width) : height;
let myWidth = (this.state.layoutWidth - 4 < width) ? this.state.layoutWidth - 4 : width;

const { ImageComponent = Image } = this.props
return (
<View key={`image${index}`}
style={{
Expand All @@ -468,15 +468,14 @@ class CNRichTextEditor extends Component {
onPress={() => this.onImageClicked(index)}

>
<Image
<ImageComponent
style={{width: myWidth, height: myHeight
, opacity: this.state.imageHighLightedInex === index ? .8 : 1
}}
source={{uri: image.url}}
/>
</TouchableWithoutFeedback>
<TextInput

onKeyPress={(event) => this.handleKeyDown(event, index)}
//onSelectionChange={(event) =>this.onSelectionChange(event, index)}
multiline={false}
Expand Down
6 changes: 2 additions & 4 deletions src/CNRichTextView.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,10 @@ class CNRichTextView extends Component {
renderImage(image, index) {
const { width, height } = image.size;
const { layoutWidth } = this.state;

const { ImageComponent = Image } = this.props
let myHeight = (layoutWidth - 4 < width) ? height * ((layoutWidth - 4) / width) : height;
let myWidth = (layoutWidth - 4 < width) ? layoutWidth - 4 : width;


return (
<View key={`image${index}`}
style={{
Expand All @@ -82,8 +81,7 @@ class CNRichTextView extends Component {
}}
>
<View>
<Image

<ImageComponent
style={{
width: myWidth, height: myHeight
, opacity: this.state.imageHighLightedInex === index ? .8 : 1
Expand Down

0 comments on commit 4db4cc8

Please sign in to comment.