diff --git a/src/RichTextToolbar.js b/src/RichTextToolbar.js
index d97f4cb7..e84b98d4 100644
--- a/src/RichTextToolbar.js
+++ b/src/RichTextToolbar.js
@@ -1,7 +1,7 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
-import {ListView, View, TouchableOpacity, Image, StyleSheet} from 'react-native';
-import {actions} from './const';
+import { FlatList, View, TouchableOpacity, Image, StyleSheet } from 'react-native';
+import { actions } from './const';
const defaultActions = [
actions.insertImage,
@@ -46,7 +46,7 @@ export default class RichTextToolbar extends Component {
editor: undefined,
selectedItems: [],
actions,
- ds: new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2}).cloneWithRows(this.getRows(actions, []))
+ dataSet: this.getRows(actions, [])
};
}
@@ -54,12 +54,12 @@ export default class RichTextToolbar extends Component {
const actions = newProps.actions ? newProps.actions : defaultActions;
this.setState({
actions,
- ds: this.state.ds.cloneWithRows(this.getRows(actions, this.state.selectedItems))
+ dataSet: this.getRows(actions, this.state.selectedItems)
});
}
getRows(actions, selectedItems) {
- return actions.map((action) => {return {action, selected: selectedItems.includes(action)};});
+ return actions.map((action) => { return { action, selected: selectedItems.includes(action) }; });
}
componentDidMount() {
@@ -68,7 +68,7 @@ export default class RichTextToolbar extends Component {
throw new Error('Toolbar has no editor!');
} else {
editor.registerToolbar((selectedItems) => this.setSelectedItems(selectedItems));
- this.setState({editor});
+ this.setState({ editor });
}
}
@@ -76,7 +76,7 @@ export default class RichTextToolbar extends Component {
if (selectedItems !== this.state.selectedItems) {
this.setState({
selectedItems,
- ds: this.state.ds.cloneWithRows(this.getRows(this.state.actions, selectedItems))
+ dataSet: this.getRows(this.state.actions, selectedItems)
});
}
}
@@ -92,7 +92,7 @@ export default class RichTextToolbar extends Component {
_getButtonIcon(action) {
if (this.props.iconMap && this.props.iconMap[action]) {
return this.props.iconMap[action];
- } else if (getDefaultIcon()[action]){
+ } else if (getDefaultIcon()[action]) {
return getDefaultIcon()[action];
} else {
return undefined;
@@ -103,41 +103,38 @@ export default class RichTextToolbar extends Component {
const icon = this._getButtonIcon(action);
return (
this._onPress(action)}
+ key={action}
+ style={[
+ { height: 50, width: 50, justifyContent: 'center' },
+ selected ? this._getButtonSelectedStyle() : this._getButtonUnselectedStyle()
+ ]}
+ onPress={() => this._onPress(action)}
>
- {icon ? : null}
+ {icon ? : null}
);
}
_renderAction(action, selected) {
return this.props.renderAction ?
- this.props.renderAction(action, selected) :
- this._defaultRenderAction(action, selected);
+ this.props.renderAction(action, selected) :
+ this._defaultRenderAction(action, selected);
}
render() {
return (
-
- this._renderAction(row.action, row.selected)}
+
+ this._renderAction(item.item.action, item.item.selected)}
/>
- );
+ )
}
_onPress(action) {
- switch(action) {
+ switch (action) {
case actions.setBold:
case actions.setItalic:
case actions.insertBulletsList:
@@ -165,7 +162,7 @@ export default class RichTextToolbar extends Component {
break;
case actions.insertLink:
this.state.editor.prepareInsert();
- if(this.props.onPressAddLink) {
+ if (this.props.onPressAddLink) {
this.props.onPressAddLink();
} else {
this.state.editor.getSelectedText().then(selectedText => {
@@ -175,7 +172,7 @@ export default class RichTextToolbar extends Component {
break;
case actions.insertImage:
this.state.editor.prepareInsert();
- if(this.props.onPressAddImage) {
+ if (this.props.onPressAddImage) {
this.props.onPressAddImage();
}
break;
@@ -189,4 +186,4 @@ const styles = StyleSheet.create({
backgroundColor: 'red'
},
defaultUnselectedButton: {}
-});
\ No newline at end of file
+});