Skip to content

Commit 65f79db

Browse files
authored
Update RichTextToolbar.js
accepting React elements as icons & centering Icons.
1 parent 45a9817 commit 65f79db

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/RichTextToolbar.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,28 +89,31 @@ export default class RichTextToolbar extends Component {
8989
return this.props.unselectedButtonStyle ? this.props.unselectedButtonStyle : styles.defaultUnselectedButton;
9090
}
9191

92-
_getButtonIcon(action) {
93-
if (this.props.iconMap && this.props.iconMap[action]) {
94-
return this.props.iconMap[action];
92+
_getButtonIcon(action, selected) {
93+
if (this.props.iconMap && React.isValidElement(this.props.iconMap[action])) {
94+
return this.props.iconMap[action]
95+
} else if (this.props.iconMap && this.props.iconMap[action]) {
96+
return <Image source={this.props.iconMap[action]} style={{tintColor: selected ? this.props.selectedIconTint : this.props.iconTint}}/>
9597
} else if (getDefaultIcon()[action]){
96-
return getDefaultIcon()[action];
98+
const defaultImage = getDefaultIcon()[action];
99+
return <Image source={defaultImage} style={{tintColor: selected ? this.props.selectedIconTint : this.props.iconTint}}/>
97100
} else {
98101
return undefined;
99102
}
100103
}
101104

102105
_defaultRenderAction(action, selected) {
103-
const icon = this._getButtonIcon(action);
106+
const icon = this._getButtonIcon(action, selected);
104107
return (
105108
<TouchableOpacity
106109
key={action}
107110
style={[
108-
{height: 50, width: 50, justifyContent: 'center'},
111+
{height: 50, width: 50, justifyContent: 'center', alignItems: 'center'},
109112
selected ? this._getButtonSelectedStyle() : this._getButtonUnselectedStyle()
110113
]}
111114
onPress={() => this._onPress(action)}
112115
>
113-
{icon ? <Image source={icon} style={{tintColor: selected ? this.props.selectedIconTint : this.props.iconTint}}/> : null}
116+
{icon ? icon : null}
114117
</TouchableOpacity>
115118
);
116119
}

0 commit comments

Comments
 (0)