您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

App.native.js 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /* global __DEV__ */
  2. import React from 'react';
  3. import { Linking } from 'react-native';
  4. import '../../analytics';
  5. import { Platform } from '../../base/react';
  6. import '../../mobile/audio-mode';
  7. import '../../mobile/background';
  8. import '../../mobile/external-api';
  9. import '../../mobile/full-screen';
  10. import '../../mobile/network-activity';
  11. import '../../mobile/permissions';
  12. import '../../mobile/proximity';
  13. import '../../mobile/wake-lock';
  14. import { AbstractApp } from './AbstractApp';
  15. /**
  16. * Root application component.
  17. *
  18. * @extends AbstractApp
  19. */
  20. export class App extends AbstractApp {
  21. /**
  22. * App component's property types.
  23. *
  24. * @static
  25. */
  26. static propTypes = {
  27. ...AbstractApp.propTypes,
  28. /**
  29. * Whether the Welcome page is enabled. If {@code true}, the Welcome
  30. * page is rendered when the {@link App} is not at a location (URL)
  31. * identifying a Jitsi Meet conference/room.
  32. */
  33. welcomePageEnabled: React.PropTypes.bool
  34. };
  35. /**
  36. * Initializes a new App instance.
  37. *
  38. * @param {Object} props - The read-only React Component props with which
  39. * the new instance is to be initialized.
  40. */
  41. constructor(props) {
  42. super(props);
  43. // Bind event handlers so they are only bound once for every instance.
  44. this._onLinkingURL = this._onLinkingURL.bind(this);
  45. // In the Release configuration, React Native will (intentionally) throw
  46. // an unhandled JavascriptException for an unhandled JavaScript error.
  47. // This will effectively kill the application. In accord with the Web,
  48. // do not kill the application.
  49. this._maybeDisableExceptionsManager();
  50. }
  51. /**
  52. * Subscribe to notifications about activating URLs registered to be handled
  53. * by this app.
  54. *
  55. * @inheritdoc
  56. * @returns {void}
  57. * @see https://facebook.github.io/react-native/docs/linking.html
  58. */
  59. componentWillMount() {
  60. super.componentWillMount();
  61. Linking.addEventListener('url', this._onLinkingURL);
  62. }
  63. /**
  64. * Unsubscribe from notifications about activating URLs registered to be
  65. * handled by this app.
  66. *
  67. * @inheritdoc
  68. * @returns {void}
  69. * @see https://facebook.github.io/react-native/docs/linking.html
  70. */
  71. componentWillUnmount() {
  72. Linking.removeEventListener('url', this._onLinkingURL);
  73. super.componentWillUnmount();
  74. }
  75. /**
  76. * Attempts to disable the use of React Native
  77. * {@link ExceptionsManager#handleException} on platforms and in
  78. * configurations on/in which the use of the method in questions has been
  79. * determined to be undesirable. For example, React Native will
  80. * (intentionally) throw an unhandled JavascriptException for an
  81. * unhandled JavaScript error in the Release configuration. This will
  82. * effectively kill the application. In accord with the Web, do not kill the
  83. * application.
  84. *
  85. * @private
  86. * @returns {void}
  87. */
  88. _maybeDisableExceptionsManager() {
  89. if (__DEV__) {
  90. // As mentioned above, only the Release configuration was observed
  91. // to suffer.
  92. return;
  93. }
  94. if (Platform.OS !== 'android') {
  95. // A solution based on RTCSetFatalHandler was implemented on iOS and
  96. // it is preferred because it is at a later step of the
  97. // error/exception handling and it is specific to fatal
  98. // errors/exceptions which were observed to kill the application.
  99. // The solution implemented bellow was tested on Android only so it
  100. // is considered safest to use it there only.
  101. return;
  102. }
  103. const oldHandler = global.ErrorUtils.getGlobalHandler();
  104. const newHandler = _handleException;
  105. if (!oldHandler || oldHandler !== newHandler) {
  106. newHandler.next = oldHandler;
  107. global.ErrorUtils.setGlobalHandler(newHandler);
  108. }
  109. }
  110. /**
  111. * Notified by React's Linking API that a specific URL registered to be
  112. * handled by this App was activated.
  113. *
  114. * @param {Object} event - The details of the notification/event.
  115. * @param {string} event.url - The URL registered to be handled by this App
  116. * which was activated.
  117. * @private
  118. * @returns {void}
  119. */
  120. _onLinkingURL({ url }) {
  121. this._openURL(url);
  122. }
  123. }
  124. /**
  125. * Handles a (possibly unhandled) JavaScript error by preventing React Native
  126. * from converting a fatal error into an unhandled native exception which will
  127. * kill the application.
  128. *
  129. * @param {Error} error - The (possibly unhandled) JavaScript error to handle.
  130. * @param {boolean} fatal - True if the specified error is fatal; otherwise,
  131. * false.
  132. * @private
  133. * @returns {void}
  134. */
  135. function _handleException(error, fatal) {
  136. if (fatal) {
  137. // In the Release configuration, React Native will (intentionally) throw
  138. // an unhandled JavascriptException for an unhandled JavaScript error.
  139. // This will effectively kill the application. In accord with the Web,
  140. // do not kill the application.
  141. console.error(error);
  142. } else {
  143. // Forward to the next globalHandler of ErrorUtils.
  144. const next = _handleException.next;
  145. typeof next === 'function' && next(error, fatal);
  146. }
  147. }