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.

ToolbarButton.native.js 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import React from 'react';
  2. import { TouchableHighlight } from 'react-native';
  3. import { connect } from 'react-redux';
  4. import { Icon } from '../../base/font-icons';
  5. import AbstractToolbarButton from './AbstractToolbarButton';
  6. /**
  7. * Represents a button in Toolbar on React Native.
  8. *
  9. * @extends AbstractToolbarButton
  10. */
  11. class ToolbarButton extends AbstractToolbarButton {
  12. /**
  13. * ToolbarButton component's property types.
  14. *
  15. * @static
  16. */
  17. static propTypes = {
  18. ...AbstractToolbarButton.propTypes,
  19. /**
  20. * Used to dispatch an action when the button is clicked.
  21. */
  22. dispatch: React.PropTypes.func
  23. };
  24. /**
  25. * Renders the button of this Toolbar button.
  26. *
  27. * @param {Object} children - The children, if any, to be rendered inside
  28. * the button. Presumably, contains the icon of this Toolbar button.
  29. * @protected
  30. * @returns {ReactElement} The button of this Toolbar button.
  31. */
  32. _renderButton(children) {
  33. const props = {};
  34. 'onClick' in this.props && (props.onPress = event => {
  35. const action = this.props.onClick(event);
  36. if (action) {
  37. this.props.dispatch(action);
  38. }
  39. });
  40. 'style' in this.props && (props.style = this.props.style);
  41. 'underlayColor' in this.props
  42. && (props.underlayColor = this.props.underlayColor);
  43. return React.createElement(TouchableHighlight, props, children);
  44. }
  45. // eslint-disable-next-line valid-jsdoc
  46. /**
  47. * @inheritdoc
  48. */
  49. _renderIcon() {
  50. return super._renderIcon(Icon);
  51. }
  52. }
  53. export default connect()(ToolbarButton);