Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 75 additions & 12 deletions src/CNTextInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -768,16 +768,62 @@ class CNTextInput extends Component {
};
}

manageColorToolType(arrayOfToolTypes, toolType) {
const colors = ['red', 'green', 'blue', 'default'];
const isColor = colors.indexOf(toolType) > -1;
if (isColor)
{

const indexOfUpToolType = arrayOfToolTypes.indexOf(toolType);
if (indexOfUpToolType != -1) {
//Selected color already in list. do nothing.

}
else {

// first check if other colors are in the list, if so remove them
const otherColors = colors.filter(x => toolType != x);
for (let c = 0; c < otherColors.length; c++) {
const indexOfUpToolType = arrayOfToolTypes.indexOf(otherColors[c]);
if (indexOfUpToolType != -1)
{
arrayOfToolTypes = update(arrayOfToolTypes, { $splice: [[indexOfUpToolType, 1]] });
}
}
// then add the selected color in...
arrayOfToolTypes = update(arrayOfToolTypes, { $push: [toolType] });

}

}
return arrayOfToolTypes;
}

addToUpComming(toolType) {
if (this.upComingStype) {
const indexOfUpToolType = this.upComingStype.stype.indexOf(toolType);
const newUpStype = this.upComingStype ? (indexOfUpToolType != -1 ? update(this.upComingStype.stype, { $splice: [[indexOfUpToolType, 1]] })
: update(this.upComingStype.stype, { $push: [toolType] })) : [toolType];
this.upComingStype.stype = newUpStype;
this.upComingStype.styleList = StyleSheet.flatten(this.convertStyleList(update(newUpStype, { $push: [this.upComingStype.tag] })));
// Need to treat colors as having the same toolType and even selecting existing color is ok - doesn't turnoff
const colors = ['red', 'green', 'blue', 'default'];
const isColor = colors.indexOf(toolType) > -1;
if (isColor)
{
this.upComingStype.stype = this.manageColorToolType(this.upComingStype.stype, toolType);
this.upComingStype.styleList = StyleSheet.flatten(this.convertStyleList(update(this.upComingStype.stype, { $push: [this.upComingStype.tag] })));


}
else //not color
{
const indexOfUpToolType = this.upComingStype.stype.indexOf(toolType);
const newUpStype = this.upComingStype ? (indexOfUpToolType != -1 ? update(this.upComingStype.stype, { $splice: [[indexOfUpToolType, 1]] })
: update(this.upComingStype.stype, { $push: [toolType] })) : [toolType];
this.upComingStype.stype = newUpStype;
this.upComingStype.styleList = StyleSheet.flatten(this.convertStyleList(update(newUpStype, { $push: [this.upComingStype.tag] })));
}
}
}



applyStyle(toolType) {
const { selection: { start, end } } = this.state;
const { items } = this.props;
Expand All @@ -792,16 +838,31 @@ class CNTextInput extends Component {
const {
id, len, stype, tag, text, styleList,
} = content[i];

console.log('applyStyle:', id, len, stype, tag, text, styleList);

const NewLine = content[i].NewLine ? content[i].NewLine : false;
const readOnly = content[i].readOnly ? content[i].readOnly : false;

const indexOfToolType = stype.indexOf(toolType);
const newStype = (indexOfToolType != -1)
? update(stype, { $splice: [[indexOfToolType, 1]] })
: update(stype, { $push: [toolType] });
const colors = ['red', 'green', 'blue', 'default'];
const isColor = colors.indexOf(toolType) > -1;
let newStype = [];
if (isColor)
{
newStype = this.manageColorToolType(stype, toolType);
}
else {
const indexOfToolType = stype.indexOf(toolType);
newStype = (indexOfToolType != -1)
? update(stype, { $splice: [[indexOfToolType, 1]] })
: update(stype, { $push: [toolType] });
}
console.log('applyStyle:newStype:', newStype);

const newStyles = StyleSheet.flatten(this.convertStyleList(update(newStype, { $push: [tag] })));

console.log('applyStyle:newStyles:', newStyles);

const from = indx;
indx += len;
const to = indx;
Expand Down Expand Up @@ -1011,6 +1072,8 @@ class CNTextInput extends Component {
styles = newCollection[res.findIndx].stype;
}

console.log('applyStyle:aboutToCallOnSelectedStyleChanged:', newCollection, styles);

this.justToolAdded = start !== end;
this.props.onContentChanged(newCollection);
if (this.props.onSelectedStyleChanged) this.props.onSelectedStyleChanged(styles);
Expand Down Expand Up @@ -1306,7 +1369,7 @@ class CNTextInput extends Component {

render() {
const {
items, foreColor, style, returnKeyType, styleList, textInputProps
items, foreColor, style, returnKeyType, styleList
} = this.props;
const { selection } = this.state;
const color = foreColor || '#000';
Expand All @@ -1330,14 +1393,14 @@ class CNTextInput extends Component {
scrollEnabled={false}
returnKeyType={returnKeyType || 'next'}
keyboardType="default"
ref={component => this.textInput = component}
ref={this.textInput}
onChangeText={this.handleChangeText}
onKeyPress={this.handleKeyDown}
selection={selection}
onFocus={this.onFocus}
onBlur={this.onBlur}
onContentSizeChange={this.handleContentSizeChange}
placeholder={this.props.placeholder}
selection={undefined}
>
{
_.map(items, item => (
Expand Down
8 changes: 4 additions & 4 deletions src/Convertors.js
Original file line number Diff line number Diff line change
Expand Up @@ -449,16 +449,16 @@ const defaultStyles = StyleSheet.create(
fontSize: 20,
},
red: {
color: '#d23431',
color: '#F57474',
},
green: {
color: '#4a924d',
color: '#29CC75',
},
blue: {
color: '#0560ab',
color: '#67B6FF',
},
black: {
color: '#33363d',
color: '#676767',
},
blue_hl: {
backgroundColor: '#34f3f4',
Expand Down