You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ToolboxItem.native.tsx 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import React from 'react';
  2. import { Text, TextStyle, TouchableHighlight, View, ViewStyle } from 'react-native';
  3. import Icon from '../../icons/components/Icon';
  4. import AbstractToolboxItem, { IProps } from './AbstractToolboxItem';
  5. /**
  6. * Native implementation of {@code AbstractToolboxItem}.
  7. */
  8. export default class ToolboxItem extends AbstractToolboxItem<IProps> {
  9. /**
  10. * Renders the {@code Icon} part of this {@code ToolboxItem}.
  11. *
  12. * @private
  13. * @returns {ReactElement}
  14. */
  15. _renderIcon() {
  16. const { styles } = this.props;
  17. return (
  18. <Icon
  19. src = { this.props.icon }
  20. style = { styles?.iconStyle } />
  21. );
  22. }
  23. /**
  24. * Renders this {@code ToolboxItem}. Invoked by {@link AbstractToolboxItem}.
  25. *
  26. * @override
  27. * @protected
  28. * @returns {ReactElement}
  29. */
  30. _renderItem() {
  31. const {
  32. disabled,
  33. elementAfter,
  34. onClick,
  35. showLabel,
  36. styles,
  37. toggled
  38. } = this.props;
  39. let children = this._renderIcon();
  40. // XXX When using a wrapper View, apply the style to it instead of
  41. // applying it to the TouchableHighlight.
  42. let style = styles?.style;
  43. if (showLabel) {
  44. // XXX TouchableHighlight requires 1 child. If there's a need to
  45. // show both the icon and the label, then these two need to be
  46. // wrapped in a View.
  47. children = (
  48. <View style = { style as ViewStyle }>
  49. { children }
  50. <Text style = { styles?.labelStyle as TextStyle }>
  51. { this.label }
  52. </Text>
  53. { elementAfter }
  54. </View>
  55. );
  56. // XXX As stated earlier, the style was applied to the wrapper View
  57. // (above).
  58. style = undefined;
  59. }
  60. return (
  61. <TouchableHighlight
  62. accessibilityLabel = { this.accessibilityLabel }
  63. accessibilityRole = { 'button' }
  64. accessibilityState = {{ 'selected': Boolean(toggled) }}
  65. disabled = { disabled }
  66. onPress = { onClick }
  67. style = { style as ViewStyle }
  68. underlayColor = { styles?.underlayColor } >
  69. { children }
  70. </TouchableHighlight>
  71. );
  72. }
  73. }