2018-04-12 14:15:44 +00:00
|
|
|
// @flow
|
|
|
|
|
|
|
|
import React from 'react';
|
2018-05-15 11:18:42 +00:00
|
|
|
import { Text, TouchableHighlight, View } from 'react-native';
|
2018-04-12 14:15:44 +00:00
|
|
|
|
2019-08-30 16:39:06 +00:00
|
|
|
import { Icon } from '../../icons';
|
2018-04-12 14:15:44 +00:00
|
|
|
|
|
|
|
import AbstractToolboxItem from './AbstractToolboxItem';
|
|
|
|
import type { Props } from './AbstractToolboxItem';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Native implementation of {@code AbstractToolboxItem}.
|
|
|
|
*/
|
|
|
|
export default class ToolboxItem extends AbstractToolboxItem<Props> {
|
|
|
|
/**
|
2018-05-16 21:49:03 +00:00
|
|
|
* Renders the {@code Icon} part of this {@code ToolboxItem}.
|
2018-04-12 14:15:44 +00:00
|
|
|
*
|
2018-05-15 11:18:42 +00:00
|
|
|
* @private
|
|
|
|
* @returns {ReactElement}
|
|
|
|
*/
|
|
|
|
_renderIcon() {
|
|
|
|
const { styles } = this.props;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Icon
|
2019-08-30 16:39:06 +00:00
|
|
|
src = { this.props.icon }
|
2018-05-15 11:18:42 +00:00
|
|
|
style = { styles && styles.iconStyle } />
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-05-16 21:49:03 +00:00
|
|
|
* Renders this {@code ToolboxItem}. Invoked by {@link AbstractToolboxItem}.
|
2018-04-12 14:15:44 +00:00
|
|
|
*
|
2018-05-16 21:49:03 +00:00
|
|
|
* @override
|
2018-04-12 14:15:44 +00:00
|
|
|
* @protected
|
|
|
|
* @returns {ReactElement}
|
|
|
|
*/
|
|
|
|
_renderItem() {
|
|
|
|
const {
|
|
|
|
disabled,
|
2018-07-17 17:49:58 +00:00
|
|
|
elementAfter,
|
2018-04-12 14:15:44 +00:00
|
|
|
onClick,
|
2018-05-15 11:18:42 +00:00
|
|
|
showLabel,
|
2020-04-10 13:07:48 +00:00
|
|
|
styles,
|
|
|
|
toggled
|
2018-04-12 14:15:44 +00:00
|
|
|
} = this.props;
|
|
|
|
|
2018-05-16 21:49:03 +00:00
|
|
|
let children = this._renderIcon();
|
|
|
|
|
|
|
|
// XXX When using a wrapper View, apply the style to it instead of
|
|
|
|
// applying it to the TouchableHighlight.
|
|
|
|
let style = styles && styles.style;
|
2018-05-15 11:18:42 +00:00
|
|
|
|
|
|
|
if (showLabel) {
|
2018-05-16 21:49:03 +00:00
|
|
|
// XXX TouchableHighlight requires 1 child. If there's a need to
|
|
|
|
// show both the icon and the label, then these two need to be
|
|
|
|
// wrapped in a View.
|
2018-08-06 16:09:32 +00:00
|
|
|
children = (
|
2018-05-16 21:49:03 +00:00
|
|
|
<View style = { style }>
|
|
|
|
{ children }
|
|
|
|
<Text style = { styles && styles.labelStyle }>
|
2018-05-15 11:18:42 +00:00
|
|
|
{ this.label }
|
|
|
|
</Text>
|
2018-07-17 17:49:58 +00:00
|
|
|
{ elementAfter }
|
2018-05-15 11:18:42 +00:00
|
|
|
</View>
|
|
|
|
);
|
|
|
|
|
2018-05-16 21:49:03 +00:00
|
|
|
// XXX As stated earlier, the style was applied to the wrapper View
|
|
|
|
// (above).
|
|
|
|
style = undefined;
|
|
|
|
}
|
2018-05-15 11:18:42 +00:00
|
|
|
|
2018-04-12 14:15:44 +00:00
|
|
|
return (
|
|
|
|
<TouchableHighlight
|
2018-06-07 20:32:18 +00:00
|
|
|
accessibilityLabel = { this.accessibilityLabel }
|
2020-04-10 13:07:48 +00:00
|
|
|
accessibilityRole = 'button'
|
2022-01-07 10:54:42 +00:00
|
|
|
accessibilityState = {{ 'selected': Boolean(toggled) }}
|
2018-04-12 14:15:44 +00:00
|
|
|
disabled = { disabled }
|
|
|
|
onPress = { onClick }
|
2018-05-15 11:18:42 +00:00
|
|
|
style = { style }
|
2018-04-12 14:15:44 +00:00
|
|
|
underlayColor = { styles && styles.underlayColor } >
|
2018-05-15 11:18:42 +00:00
|
|
|
{ children }
|
2018-04-12 14:15:44 +00:00
|
|
|
</TouchableHighlight>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|