Skip to content

Commit 430a4fd

Browse files
committed
Update to 1.0.38
#62
1 parent cb5d921 commit 430a4fd

7 files changed

Lines changed: 34 additions & 24 deletions

File tree

expo-demo/App.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,17 @@ class App extends Component {
2626

2727
constructor(props) {
2828
super(props);
29-
30-
29+
3130
this.state = {
3231
selectedTag : 'body',
3332
selectedColor : 'default',
3433
selectedHighlight: 'default',
3534
colors : ['red', 'green', 'blue'],
3635
highlights:['yellow_hl','pink_hl', 'orange_hl', 'green_hl','purple_hl','blue_hl'],
3736
selectedStyles : [],
38-
value: [getInitialObject]
37+
value: [getInitialObject()]
3938
};
4039

41-
this.state.value = [getInitialObject()];
42-
4340
this.editor = null;
4441

4542
}
@@ -299,6 +296,8 @@ class App extends Component {
299296
}
300297

301298
render() {
299+
let customStyles = {...defaultStyles, body: {fontSize: 12}, heading : {fontSize: 16}, title : {fontSize: 20}};
300+
302301
return (
303302
<KeyboardAvoidingView
304303
behavior="padding"
@@ -315,7 +314,7 @@ class App extends Component {
315314
onSelectedStyleChanged={this.onSelectedStyleChanged}
316315
value={this.state.value}
317316
style={styles.editor}
318-
styleList={defaultStyles}
317+
styleList={customStyles}
319318
foreColor='dimgray' // optional (will override default fore-color)
320319
onValueChanged={this.onValueChanged}
321320
onRemoveImage={this.onRemoveImage}

expo-demo/app.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"ios",
1010
"android"
1111
],
12-
"version": "1.0.7",
12+
"version": "1.0.8",
1313
"orientation": "portrait",
1414
"icon": "./assets/icon.png",
1515
"splash": {

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.37",
13+
"react-native-cn-richtext-editor": "^1.0.38",
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.37:
3734-
version "1.0.37"
3735-
resolved "https://registry.yarnpkg.com/react-native-cn-richtext-editor/-/react-native-cn-richtext-editor-1.0.37.tgz#dc1fe33b2a36e82aed3782a9523ef79c45f3bbcb"
3736-
integrity sha512-qdetqUf+9rhi2HRyd6881U57FUdMCRyNYIfuiIY98OhKVuu4F+JyUO2d55YAv7iCqBJ/vFLGOXg8Eo5x6WlzxA==
3733+
react-native-cn-richtext-editor@^1.0.38:
3734+
version "1.0.38"
3735+
resolved "https://registry.yarnpkg.com/react-native-cn-richtext-editor/-/react-native-cn-richtext-editor-1.0.38.tgz#77c9da58e4391416a1ac795481177c5e39b313de"
3736+
integrity sha512-SJ7hBmscKR7Oj91wPD0dEAco0CvwnE4l6VeibJk4aUGbMqXiab/lmsTR6eE52fFg4ASemLGfEa6uCrD2/svAEA==
37373737
dependencies:
37383738
diff-match-patch "^1.0.4"
37393739
immutability-helper "^2.8.1"

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-cn-richtext-editor",
3-
"version": "1.0.37",
3+
"version": "1.0.38",
44
"description": "RichText Editor for React-Native",
55
"main": "index.js",
66
"scripts": {

src/CNRichTextEditor.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
} from 'react-native';
77
import _ from 'lodash';
88
import update from 'immutability-helper';
9-
import { getInitialObject, defaultStyles } from './Convertors';
9+
import { getInitialObject, getDefaultStyles } from './Convertors';
1010
import CNTextInput from './CNTextInput';
1111

1212
const shortid = require('shortid');
@@ -38,10 +38,7 @@ class CNRichTextEditor extends Component {
3838
this.focusOnNextUpdate = -1;
3939
this.selectionOnFocus = null;
4040
this.scrollOffset = 0;
41-
}
42-
43-
componentDidMount() {
44-
41+
this.defaultStyles = getDefaultStyles();
4542
}
4643

4744
componentDidUpdate(prevProps, prevState) {
@@ -403,7 +400,7 @@ class CNRichTextEditor extends Component {
403400
}
404401

405402
renderInput(input, index, isLast, measureScroll = true) {
406-
const styles = this.props.styleList ? this.props.styleList : defaultStyles;
403+
const styles = this.props.styleList ? this.props.styleList : this.defaultStyles;
407404
return (
408405
<View
409406
key={input.id}
@@ -540,7 +537,7 @@ class CNRichTextEditor extends Component {
540537
const {
541538
value, style, contentContainerStyle, measureInputScroll = true,
542539
} = this.props;
543-
const styleList = this.props.styleList ? this.props.styleList : defaultStyles;
540+
const styleList = this.props.styleList ? this.props.styleList : this.defaultStyles;
544541

545542
return (
546543
<View

src/CNTextInput.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,19 @@ class CNTextInput extends Component {
4242
DiffMatchPatch.DIFF_EQUAL = 0;
4343
}
4444

45+
componentWillMount() {
46+
const { items } = this.props;
47+
if(items && Array.isArray(items) === true) {
48+
let content = items;
49+
for (let i = 0; i < content.length; i++) {
50+
content[i].styleList = StyleSheet.flatten(this.convertStyleList(content[i].stype));
51+
}
52+
if (this.props.onContentChanged) {
53+
this.props.onContentChanged(content);
54+
}
55+
}
56+
}
57+
4558
componentDidMount() {
4659
if (this.props.items) {
4760
this.textLength = 0;
@@ -1293,19 +1306,20 @@ class CNTextInput extends Component {
12931306

12941307
render() {
12951308
const {
1296-
items, foreColor, style, returnKeyType,
1309+
items, foreColor, style, returnKeyType, styleList
12971310
} = this.props;
12981311
const { selection } = this.state;
12991312
const color = foreColor || '#000';
1300-
1313+
const fontSize =styleList && styleList.body && styleList.body.fontSize ? styleList.body.fontSize : 20;
1314+
13011315
return (
13021316
<TextInput
13031317
underlineColorAndroid="rgba(0,0,0,0)"
13041318
onSelectionChange={this.onSelectionChange}
13051319
multiline
13061320
style={[{
13071321
color,
1308-
fontSize: 20,
1322+
fontSize: fontSize,
13091323
paddingTop: 5,
13101324
paddingBottom: 5,
13111325
paddingLeft: 2,
@@ -1322,7 +1336,7 @@ class CNTextInput extends Component {
13221336
onFocus={this.onFocus}
13231337
onBlur={this.onBlur}
13241338
onContentSizeChange={this.handleContentSizeChange}
1325-
placeholder={this.props.placeholder}
1339+
placeholder={this.props.placeholder}
13261340
>
13271341
{
13281342
_.map(items, item => (

0 commit comments

Comments
 (0)