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.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. toggled
  40. } = this.props;
  41. let children = this._renderIcon();
  42. // XXX When using a wrapper View, apply the style to it instead of
  43. // applying it to the TouchableHighlight.
  44. let style = styles && styles.style;
  45. if (showLabel) {
  46. // XXX TouchableHighlight requires 1 child. If there's a need to
  47. // show both the icon and the label, then these two need to be
  48. // wrapped in a View.
  49. children = (
  50. <View style = { style }>
  51. { children }
  52. <Text style = { styles && styles.labelStyle }>
  53. { this.label }
  54. </Text>
  55. { elementAfter }
  56. </View>
  57. );
  58. // XXX As stated earlier, the style was applied to the wrapper View
  59. // (above).
  60. style = undefined;
  61. }
  62. return (
  63. <TouchableHighlight
  64. accessibilityLabel = { this.accessibilityLabel }
  65. accessibilityRole = 'button'
  66. accessibilityState = {{ 'selected': toggled }}
  67. disabled = { disabled }
  68. onPress = { onClick }
  69. style = { style }
  70. underlayColor = { styles && styles.underlayColor } >
  71. { children }
  72. </TouchableHighlight>
  73. );
  74. }
  75. }