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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // @flow
  2. import React from 'react';
  3. import { Text, TouchableHighlight, View } from 'react-native';
  4. import { Icon } from '../../../base/font-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. * Transform the given (web) icon name into a name that works with
  13. * {@code Icon}.
  14. *
  15. * @private
  16. * @returns {string}
  17. */
  18. _getIconName() {
  19. const { iconName } = this.props;
  20. return iconName.replace('icon-', '').split(' ')[0];
  21. }
  22. /**
  23. * Helper function to render the {@code Icon} part of this item.
  24. *
  25. * @private
  26. * @returns {ReactElement}
  27. */
  28. _renderIcon() {
  29. const { styles } = this.props;
  30. return (
  31. <Icon
  32. name = { this._getIconName() }
  33. style = { styles && styles.iconStyle } />
  34. );
  35. }
  36. /**
  37. * Handles rendering of the actual item.
  38. *
  39. * @protected
  40. * @returns {ReactElement}
  41. */
  42. _renderItem() {
  43. const {
  44. accessibilityLabel,
  45. disabled,
  46. onClick,
  47. showLabel,
  48. styles
  49. } = this.props;
  50. let children;
  51. if (showLabel) {
  52. // eslint-disable-next-line no-extra-parens
  53. children = (
  54. <View style = { styles && styles.style } >
  55. { this._renderIcon() }
  56. <Text style = { styles && styles.labelStyle } >
  57. { this.label }
  58. </Text>
  59. </View>
  60. );
  61. } else {
  62. children = this._renderIcon();
  63. }
  64. // When using a wrapper view, apply the style to it instead of
  65. // applying it to the TouchableHighlight.
  66. const style = showLabel ? undefined : styles && styles.style;
  67. return (
  68. <TouchableHighlight
  69. accessibilityLabel = { accessibilityLabel }
  70. disabled = { disabled }
  71. onPress = { onClick }
  72. style = { style }
  73. underlayColor = { styles && styles.underlayColor } >
  74. { children }
  75. </TouchableHighlight>
  76. );
  77. }
  78. }