Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

Link.native.js 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import React, { Component } from 'react';
  2. import { Linking, Text } from 'react-native';
  3. /**
  4. * Implements a (hyper)link to a URL in the fashion of the HTML anchor element
  5. * and its href attribute.
  6. */
  7. export class Link extends Component {
  8. /**
  9. * Link component's property types.
  10. *
  11. * @static
  12. */
  13. static propTypes = {
  14. /**
  15. * The children to be displayed within this Link.
  16. */
  17. children: React.PropTypes.node,
  18. /**
  19. * Notifies that this Link failed to open the URL associated with it.
  20. */
  21. onLinkingOpenURLRejected: React.PropTypes.func,
  22. /**
  23. * The CSS style to be applied to this Link for the purposes of display.
  24. */
  25. style: React.PropTypes.object,
  26. /**
  27. * The URL to be opened when this Link is clicked/pressed.
  28. */
  29. url: React.PropTypes.string
  30. }
  31. /**
  32. * Initializes a new Link instance.
  33. *
  34. * @param {Object} props - Component properties.
  35. */
  36. constructor(props) {
  37. super(props);
  38. // Bind event handlers so they are only bound once for every instance.
  39. this._onPress = this._onPress.bind(this);
  40. }
  41. /**
  42. * Implements React's {@link Component#render()}.
  43. *
  44. * @inheritdoc
  45. * @returns {ReactElement}
  46. */
  47. render() {
  48. return (
  49. <Text
  50. onPress = { this._onPress }
  51. style = { this.props.style }>
  52. {
  53. this.props.children
  54. }
  55. </Text>
  56. );
  57. }
  58. /**
  59. * Notifies this instance that Linking failed to open the associated URL.
  60. *
  61. * @param {any} reason - The rejection reason.
  62. * @private
  63. * @returns {void}
  64. */
  65. _onLinkingOpenURLRejected(reason) {
  66. const onRejected = this.props.onLinkingOpenURLRejected;
  67. onRejected && onRejected(reason);
  68. }
  69. /**
  70. * Handles press on this Link. Opens the URL associated with this Link.
  71. *
  72. * @private
  73. * @returns {void}
  74. */
  75. _onPress() {
  76. Linking.openURL(this.props.url)
  77. .catch(reason => this._onLinkingOpenURLRejected(reason));
  78. }
  79. }