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.js 2.3KB

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