@office-iss/react-native-win32 0.0.0-canary.291 → 0.0.0-canary.293

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (191) hide show
  1. package/.flowconfig +1 -1
  2. package/CHANGELOG.json +43 -1
  3. package/CHANGELOG.md +22 -4
  4. package/Libraries/Alert/RCTAlertManager.js +17 -0
  5. package/Libraries/Animated/AnimatedEvent.js +4 -3
  6. package/Libraries/Animated/AnimatedExports.js.flow +2 -0
  7. package/Libraries/Animated/AnimatedImplementation.js +2 -2
  8. package/Libraries/Animated/components/AnimatedScrollView.js +48 -43
  9. package/Libraries/Animated/nodes/AnimatedValue.js +2 -1
  10. package/Libraries/BatchedBridge/MessageQueue.js +2 -2
  11. package/Libraries/Blob/FileReader.js +219 -8
  12. package/Libraries/Blob/URL.js +13 -1
  13. package/Libraries/Components/AccessibilityInfo/legacySendAccessibilityEvent.js +17 -0
  14. package/Libraries/Components/Button.js +1 -1
  15. package/Libraries/Components/Button.win32.js +1 -1
  16. package/Libraries/Components/DrawerAndroid/DrawerLayoutAndroid.android.js +1 -3
  17. package/Libraries/{Utilities/__mocks__/GlobalPerformanceLogger.js → Components/DrawerAndroid/DrawerLayoutAndroid.ios.js} +3 -4
  18. package/Libraries/Components/DrawerAndroid/DrawerLayoutAndroid.js +6 -66
  19. package/Libraries/Components/DrawerAndroid/DrawerLayoutAndroid.js.flow +18 -0
  20. package/Libraries/Components/DrawerAndroid/DrawerLayoutAndroidFallback.js +71 -0
  21. package/Libraries/Components/Keyboard/Keyboard.js +4 -2
  22. package/Libraries/Components/Keyboard/KeyboardAvoidingView.js +6 -3
  23. package/Libraries/Components/Pressable/Pressable.js +6 -1
  24. package/Libraries/Components/Pressable/Pressable.win32.js +6 -1
  25. package/Libraries/Components/ProgressBarAndroid/ProgressBarAndroid.js +12 -2
  26. package/Libraries/Components/RefreshControl/RefreshControl.js +1 -1
  27. package/Libraries/Components/ScrollView/ScrollView.d.ts +1 -1
  28. package/Libraries/Components/ScrollView/ScrollView.js +128 -116
  29. package/Libraries/Components/StaticRenderer.js +1 -1
  30. package/Libraries/Components/Switch/Switch.js +7 -3
  31. package/Libraries/Components/TextInput/AndroidTextInputNativeComponent.js +2 -1
  32. package/Libraries/Components/TextInput/RCTTextInputViewConfig.js +2 -4
  33. package/Libraries/Components/TextInput/TextInput.flow.js +59 -42
  34. package/Libraries/Components/TextInput/TextInput.flow.win32.js +1208 -0
  35. package/Libraries/Components/TextInput/TextInput.js +67 -1005
  36. package/Libraries/Components/TextInput/TextInput.win32.js +69 -1037
  37. package/Libraries/{Blob/__mocks__/BlobModule.js → Components/ToastAndroid/ToastAndroid.ios.js} +3 -6
  38. package/Libraries/Components/ToastAndroid/ToastAndroid.js +4 -32
  39. package/Libraries/Components/ToastAndroid/ToastAndroid.js.flow +109 -0
  40. package/Libraries/Components/ToastAndroid/ToastAndroid.win32.js +4 -32
  41. package/Libraries/Components/ToastAndroid/ToastAndroidFallback.js +45 -0
  42. package/Libraries/Components/Touchable/Touchable.js +5 -5
  43. package/Libraries/Components/Touchable/Touchable.win32.js +5 -5
  44. package/Libraries/Components/Touchable/TouchableBounce.js +12 -6
  45. package/Libraries/Components/Touchable/TouchableHighlight.js +9 -6
  46. package/Libraries/Components/Touchable/TouchableNativeFeedback.js +4 -4
  47. package/Libraries/Components/Touchable/TouchableNativeFeedback.win32.js +4 -4
  48. package/Libraries/Components/Touchable/TouchableOpacity.js +11 -5
  49. package/Libraries/Components/View/View.js +18 -21
  50. package/Libraries/Components/View/View.win32.js +21 -24
  51. package/Libraries/Components/View/ViewAccessibility.js +7 -0
  52. package/Libraries/Components/View/ViewAccessibility.win32.js +7 -0
  53. package/Libraries/Components/View/ViewPropTypes.js +1 -1
  54. package/Libraries/Components/View/ViewPropTypes.win32.js +1 -1
  55. package/Libraries/Core/ReactNativeVersion.js +1 -1
  56. package/Libraries/Core/setUpReactDevTools.js +5 -5
  57. package/Libraries/EventEmitter/NativeEventEmitter.js +4 -1
  58. package/Libraries/Image/Image.js +17 -0
  59. package/Libraries/Image/Image.js.flow +2 -2
  60. package/Libraries/Image/ImageInjection.js +1 -1
  61. package/Libraries/Image/ImageProps.js +5 -5
  62. package/Libraries/Image/ImageSource.js +3 -1
  63. package/Libraries/Image/ImageSourceUtils.js +4 -2
  64. package/Libraries/Image/ImageTypes.flow.js +1 -1
  65. package/Libraries/Lists/FlatList.d.ts +2 -2
  66. package/Libraries/Lists/FlatList.js +1 -1
  67. package/Libraries/Lists/SectionList.js +1 -1
  68. package/Libraries/Lists/SectionListModern.js +3 -3
  69. package/Libraries/LogBox/Data/LogBoxData.js +1 -1
  70. package/Libraries/LogBox/LogBoxNotificationContainer.js +1 -1
  71. package/Libraries/Modal/Modal.js +3 -3
  72. package/Libraries/NativeComponent/BaseViewConfig.js +17 -0
  73. package/Libraries/NativeComponent/PlatformBaseViewConfig.js +2 -2
  74. package/Libraries/NativeModules/specs/NativeDevMenu.js +2 -2
  75. package/Libraries/Network/RCTNetworking.js +17 -0
  76. package/Libraries/Network/XMLHttpRequest.js +781 -10
  77. package/Libraries/NewAppScreen/components/DebugInstructions.js +1 -1
  78. package/Libraries/NewAppScreen/components/Header.js +1 -1
  79. package/Libraries/NewAppScreen/components/HermesBadge.js +1 -1
  80. package/Libraries/NewAppScreen/components/LearnMoreLinks.js +3 -3
  81. package/Libraries/NewAppScreen/components/ReloadInstructions.js +1 -1
  82. package/Libraries/Performance/Systrace.js +7 -7
  83. package/Libraries/ReactNative/AppContainer-dev.js +3 -2
  84. package/Libraries/ReactNative/RendererImplementation.js +6 -5
  85. package/Libraries/ReactNative/renderApplication.js +9 -0
  86. package/Libraries/ReactPrivate/ReactNativePrivateInterface.js +2 -2
  87. package/Libraries/Renderer/implementations/ReactFabric-dev.js +4840 -4748
  88. package/Libraries/Renderer/implementations/ReactFabric-prod.js +4947 -4829
  89. package/Libraries/Renderer/implementations/ReactFabric-profiling.js +3998 -3888
  90. package/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js +5005 -4948
  91. package/Libraries/Renderer/implementations/ReactNativeRenderer-prod.js +2744 -2652
  92. package/Libraries/Renderer/implementations/ReactNativeRenderer-profiling.js +5020 -4933
  93. package/Libraries/Renderer/shims/ReactFabric.js +3 -1
  94. package/Libraries/Renderer/shims/ReactFeatureFlags.js +3 -1
  95. package/Libraries/Renderer/shims/ReactNative.js +3 -1
  96. package/Libraries/Renderer/shims/ReactNativeViewConfigRegistry.js +3 -1
  97. package/Libraries/Renderer/shims/createReactNativeComponentClass.js +3 -1
  98. package/Libraries/Settings/Settings.js +13 -19
  99. package/Libraries/Settings/Settings.win32.js +19 -20
  100. package/Libraries/Settings/SettingsFallback.js +33 -0
  101. package/Libraries/StyleSheet/PlatformColorValueTypes.js +15 -0
  102. package/Libraries/StyleSheet/Rect.js +1 -0
  103. package/Libraries/StyleSheet/StyleSheet.js.flow +3 -3
  104. package/Libraries/StyleSheet/StyleSheetTypes.d.ts +1 -1
  105. package/Libraries/StyleSheet/StyleSheetTypes.js +75 -33
  106. package/Libraries/StyleSheet/flattenStyle.js +7 -1
  107. package/Libraries/StyleSheet/processBackgroundImage.js +670 -214
  108. package/Libraries/Text/Text.js +3 -3
  109. package/Libraries/Text/Text.win32.js +3 -3
  110. package/Libraries/Text/TextNativeComponent.js +0 -4
  111. package/Libraries/Text/TextNativeComponent.win32.js +0 -4
  112. package/Libraries/Text/TextProps.js +1 -1
  113. package/Libraries/Text/TextProps.win32.js +1 -1
  114. package/Libraries/Utilities/Appearance.js +2 -0
  115. package/Libraries/Utilities/BackHandler.js +17 -0
  116. package/Libraries/Utilities/Platform.js +17 -0
  117. package/Libraries/Utilities/PlatformTypes.js +2 -0
  118. package/Libraries/Utilities/ReactNativeTestTools.js +1 -1
  119. package/Libraries/WebSocket/WebSocket.js +313 -8
  120. package/flow/global.js +0 -2
  121. package/index.js +1 -288
  122. package/index.win32.js +8 -297
  123. package/overrides.json +29 -23
  124. package/package.json +16 -16
  125. package/src/private/animated/NativeAnimatedHelper.js +1 -1
  126. package/src/private/animated/NativeAnimatedHelper.win32.js +1 -1
  127. package/src/private/animated/createAnimatedPropsHook.js +2 -27
  128. package/src/private/components/{SafeAreaView_INTERNAL_DO_NOT_USE.js → safeareaview/SafeAreaView_INTERNAL_DO_NOT_USE.js} +6 -6
  129. package/src/private/components/{HScrollViewNativeComponents.js → scrollview/HScrollViewNativeComponents.js} +8 -8
  130. package/src/private/components/scrollview/VScrollViewNativeComponents.js +25 -0
  131. package/src/private/{devmenu → devsupport/devmenu}/DevMenu.js +1 -1
  132. package/src/private/{inspector → devsupport/devmenu/elementinspector}/BorderBox.js +3 -3
  133. package/src/private/{inspector → devsupport/devmenu/elementinspector}/BoxInspector.js +6 -5
  134. package/src/private/{inspector → devsupport/devmenu/elementinspector}/ElementBox.js +8 -6
  135. package/src/private/{inspector → devsupport/devmenu/elementinspector}/ElementProperties.js +11 -10
  136. package/src/private/{inspector → devsupport/devmenu/elementinspector}/Inspector.js +14 -12
  137. package/src/private/{inspector → devsupport/devmenu/elementinspector}/InspectorOverlay.js +5 -4
  138. package/src/private/{inspector → devsupport/devmenu/elementinspector}/InspectorPanel.js +9 -8
  139. package/src/private/{inspector → devsupport/devmenu/elementinspector}/NetworkOverlay.js +10 -9
  140. package/src/private/{inspector → devsupport/devmenu/elementinspector}/ReactDevToolsOverlay.js +7 -7
  141. package/src/private/{inspector → devsupport/devmenu/elementinspector}/StyleInspector.js +7 -6
  142. package/src/private/{inspector → devsupport/devmenu/elementinspector}/XHRInterceptor.js +2 -2
  143. package/src/private/{inspector → devsupport/devmenu/elementinspector}/getInspectorDataForViewAtPoint.js +2 -2
  144. package/src/private/{inspector → devsupport/devmenu/elementinspector}/resolveBoxStyle.js +1 -1
  145. package/src/private/{inspector → devsupport/devmenu/perfmonitor}/PerformanceOverlay.js +6 -5
  146. package/src/private/{specs_DEPRECATED/modules → devsupport/devmenu/specs}/NativeDevMenu.js +2 -2
  147. package/src/private/{debugging → devsupport/rndevtools}/ReactDevToolsSettingsManager.android.js +1 -1
  148. package/src/private/{debugging → devsupport/rndevtools}/ReactDevToolsSettingsManager.ios.js +1 -1
  149. package/src/private/{debugging → devsupport/rndevtools}/ReactDevToolsSettingsManager.win32.js +1 -1
  150. package/src/private/{debugging → devsupport/rndevtools}/setUpFuseboxReactDevToolsDispatcher.js +1 -1
  151. package/src/private/{fusebox → devsupport/rndevtools}/specs/NativeReactDevToolsRuntimeSettingsModule.js +2 -2
  152. package/src/private/{specs_DEPRECATED/modules → devsupport/rndevtools/specs}/NativeReactDevToolsSettingsManager.js +2 -2
  153. package/src/private/featureflags/ReactNativeFeatureFlags.js +37 -43
  154. package/src/private/featureflags/specs/NativeReactNativeFeatureFlags.js +8 -8
  155. package/src/private/renderer/errorhandling/ErrorHandlers.js +2 -2
  156. package/src/private/specs_DEPRECATED/modules/NativeSampleTurboModule.js +3 -0
  157. package/src/private/types/HostComponent.js +1 -1
  158. package/src/private/types/HostInstance.js +12 -4
  159. package/src/private/webapis/performance/Performance.js +1 -3
  160. package/types/index.d.ts +1 -1
  161. package/types/public/ReactNativeTypes.d.ts +2 -2
  162. package/Libraries/BatchedBridge/__mocks__/MessageQueueTestConfig.js +0 -38
  163. package/Libraries/BatchedBridge/__mocks__/MessageQueueTestModule.js +0 -22
  164. package/Libraries/Blob/FileReader_new.js +0 -231
  165. package/Libraries/Blob/FileReader_old.js +0 -186
  166. package/Libraries/Blob/__mocks__/FileReaderModule.js +0 -20
  167. package/Libraries/Components/RefreshControl/__mocks__/RefreshControlMock.js +0 -32
  168. package/Libraries/Core/__mocks__/ErrorUtils.js +0 -33
  169. package/Libraries/Core/__mocks__/NativeExceptionsManager.js +0 -19
  170. package/Libraries/EventEmitter/__mocks__/NativeEventEmitter.js +0 -49
  171. package/Libraries/Events/CustomEvent.js +0 -32
  172. package/Libraries/Events/EventPolyfill.js +0 -239
  173. package/Libraries/Lists/__flowtests__/FlatList-flowtest.js +0 -118
  174. package/Libraries/Lists/__flowtests__/SectionList-flowtest.js +0 -134
  175. package/Libraries/Network/XMLHttpRequest_new.js +0 -794
  176. package/Libraries/Network/XMLHttpRequest_old.js +0 -701
  177. package/Libraries/StyleSheet/__flowtests__/StyleSheet-flowtest.js +0 -58
  178. package/Libraries/Utilities/__mocks__/BackHandler.js +0 -45
  179. package/Libraries/Utilities/__mocks__/PixelRatio.js +0 -25
  180. package/Libraries/WebSocket/WebSocketEvent.js +0 -30
  181. package/Libraries/WebSocket/WebSocket_new.js +0 -325
  182. package/Libraries/WebSocket/WebSocket_old.js +0 -297
  183. package/Libraries/WebSocket/__mocks__/event-target-shim.js +0 -27
  184. package/Libraries/__flowtests__/ReactNativeTypes-flowtest.js +0 -30
  185. package/Libraries/vendor/emitter/__flowtests__/EventEmitter-flowtest.js +0 -81
  186. package/jest/__tests__/setup-test.js +0 -18
  187. package/src/private/components/VScrollViewNativeComponents.js +0 -25
  188. package/src/private/webapis/performance/specs/__mocks__/NativePerformanceMock.js +0 -267
  189. package/src/types/third_party/event-target-shim.d.ts +0 -392
  190. /package/src/private/{devmenu → devsupport/devmenu}/DevMenu.d.ts +0 -0
  191. /package/src/private/{debugging → devsupport/rndevtools}/FuseboxSessionObserver.js +0 -0
@@ -35,7 +35,7 @@ type TextForwardRef = React.ElementRef<
35
35
  *
36
36
  * @see https://reactnative.dev/docs/text
37
37
  */
38
- const Text: component(
38
+ const TextImpl: component(
39
39
  ref?: React.RefSetter<TextForwardRef>,
40
40
  ...props: TextProps
41
41
  ) = React.forwardRef(
@@ -330,7 +330,7 @@ const Text: component(
330
330
  },
331
331
  );
332
332
 
333
- Text.displayName = 'Text';
333
+ TextImpl.displayName = 'Text';
334
334
 
335
335
  type TextPressabilityProps = $ReadOnly<{
336
336
  onLongPress?: ?(event: GestureResponderEvent) => mixed,
@@ -536,4 +536,4 @@ const verticalAlignToTextAlignVerticalMap = {
536
536
  middle: 'center',
537
537
  };
538
538
 
539
- export default Text;
539
+ export default TextImpl;
@@ -35,7 +35,7 @@ type TextForwardRef = React.ElementRef<
35
35
  *
36
36
  * @see https://reactnative.dev/docs/text
37
37
  */
38
- const Text: component(
38
+ const TextImpl: component(
39
39
  ref?: React.RefSetter<TextForwardRef>,
40
40
  ...props: TextProps
41
41
  ) = React.forwardRef(
@@ -370,7 +370,7 @@ const Text: component(
370
370
  },
371
371
  );
372
372
 
373
- Text.displayName = 'Text';
373
+ TextImpl.displayName = 'Text';
374
374
 
375
375
  type TextPressabilityProps = $ReadOnly<{
376
376
  onLongPress?: ?(event: GestureResponderEvent) => mixed,
@@ -576,4 +576,4 @@ const verticalAlignToTextAlignVerticalMap = {
576
576
  middle: 'center',
577
577
  };
578
578
 
579
- export default Text;
579
+ export default TextImpl;
@@ -44,7 +44,6 @@ const textViewConfig = {
44
44
  minimumFontScale: true,
45
45
  textBreakStrategy: true,
46
46
  onTextLayout: true,
47
- onInlineViewLayout: true,
48
47
  dataDetectorType: true,
49
48
  android_hyphenationFrequency: true,
50
49
  lineBreakStrategyIOS: true,
@@ -53,9 +52,6 @@ const textViewConfig = {
53
52
  topTextLayout: {
54
53
  registrationName: 'onTextLayout',
55
54
  },
56
- topInlineViewLayout: {
57
- registrationName: 'onInlineViewLayout',
58
- },
59
55
  },
60
56
  uiViewClassName: 'RCTText',
61
57
  };
@@ -44,7 +44,6 @@ const textViewConfig = {
44
44
  minimumFontScale: true,
45
45
  textBreakStrategy: true,
46
46
  onTextLayout: true,
47
- onInlineViewLayout: true,
48
47
  dataDetectorType: true,
49
48
  android_hyphenationFrequency: true,
50
49
  lineBreakStrategyIOS: true,
@@ -87,9 +86,6 @@ const textViewConfig = {
87
86
  topTextLayout: {
88
87
  registrationName: 'onTextLayout',
89
88
  },
90
- topInlineViewLayout: {
91
- registrationName: 'onInlineViewLayout',
92
- },
93
89
  },
94
90
  uiViewClassName: 'RCTText',
95
91
  };
@@ -25,7 +25,7 @@ import type {
25
25
  TextLayoutEvent,
26
26
  } from '../Types/CoreEventTypes';
27
27
 
28
- import React from 'react';
28
+ import * as React from 'react';
29
29
 
30
30
  export type PressRetentionOffset = $ReadOnly<{
31
31
  top: number,
@@ -25,7 +25,7 @@ import type {
25
25
  TextLayoutEvent,
26
26
  } from '../Types/CoreEventTypes';
27
27
 
28
- import React from 'react';
28
+ import * as React from 'react';
29
29
 
30
30
  export type PressRetentionOffset = $ReadOnly<{
31
31
  top: number,
@@ -16,6 +16,8 @@ import NativeEventEmitter from '../EventEmitter/NativeEventEmitter';
16
16
  import EventEmitter from '../vendor/emitter/EventEmitter';
17
17
  import invariant from 'invariant';
18
18
 
19
+ export type {AppearancePreferences};
20
+
19
21
  type Appearance = {
20
22
  colorScheme: ?ColorSchemeName,
21
23
  };
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @flow strict-local
8
+ * @format
9
+ */
10
+
11
+ // NOTE: This file supports backwards compatibility of subpath (deep) imports
12
+ // from 'react-native' with platform-specific extensions. It can be deleted
13
+ // once we remove the "./*" mapping from package.json "exports".
14
+
15
+ import BackHandler from './BackHandler';
16
+
17
+ export default BackHandler;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @format
8
+ * @flow strict
9
+ */
10
+
11
+ // NOTE: This file supports backwards compatibility of subpath (deep) imports
12
+ // from 'react-native' with platform-specific extensions. It can be deleted
13
+ // once we remove the "./*" mapping from package.json "exports".
14
+
15
+ import Platform from './Platform';
16
+
17
+ export default Platform;
@@ -196,6 +196,8 @@ type Win32Platform = {
196
196
  type WebPlatform = {
197
197
  OS: 'web',
198
198
  // $FlowFixMe[unsafe-getters-setters]
199
+ get Version(): void,
200
+ // $FlowFixMe[unsafe-getters-setters]
199
201
  get constants(): {
200
202
  reactNativeVersion: {
201
203
  major: number,
@@ -13,7 +13,7 @@
13
13
  import type {ReactTestRenderer as ReactTestRendererType} from 'react-test-renderer';
14
14
 
15
15
  import TouchableWithoutFeedback from '../Components/Touchable/TouchableWithoutFeedback';
16
- import React from 'react';
16
+ import * as React from 'react';
17
17
  import ReactTestRenderer from 'react-test-renderer';
18
18
 
19
19
  const Switch = require('../Components/Switch/Switch').default;
@@ -8,13 +8,318 @@
8
8
  * @flow
9
9
  */
10
10
 
11
- import typeof WebSocket from './WebSocket_old';
11
+ import type {EventCallback} from '../../src/private/webapis/dom/events/EventTarget';
12
+ import type {BlobData} from '../Blob/BlobTypes';
13
+ import type {EventSubscription} from '../vendor/emitter/EventEmitter';
12
14
 
13
- // Use a global instead of a flag from ReactNativeFeatureFlags because this will
14
- // be read before apps have a chance to set overrides.
15
- const useBuiltInEventTarget = global.RN$useBuiltInEventTarget?.();
15
+ import Event from '../../src/private/webapis/dom/events/Event';
16
+ import {
17
+ getEventHandlerAttribute,
18
+ setEventHandlerAttribute,
19
+ } from '../../src/private/webapis/dom/events/EventHandlerAttributes';
20
+ import EventTarget from '../../src/private/webapis/dom/events/EventTarget';
21
+ import MessageEvent from '../../src/private/webapis/html/events/MessageEvent';
22
+ import CloseEvent from '../../src/private/webapis/websockets/events/CloseEvent';
23
+ import Blob from '../Blob/Blob';
24
+ import BlobManager from '../Blob/BlobManager';
25
+ import NativeEventEmitter from '../EventEmitter/NativeEventEmitter';
26
+ import binaryToBase64 from '../Utilities/binaryToBase64';
27
+ import Platform from '../Utilities/Platform';
28
+ import NativeWebSocketModule from './NativeWebSocketModule';
29
+ import base64 from 'base64-js';
30
+ import invariant from 'invariant';
16
31
 
17
- export default (useBuiltInEventTarget
18
- ? // $FlowExpectedError[incompatible-cast]
19
- require('./WebSocket_new').default
20
- : require('./WebSocket_old').default) as WebSocket;
32
+ type ArrayBufferView =
33
+ | Int8Array
34
+ | Uint8Array
35
+ | Uint8ClampedArray
36
+ | Int16Array
37
+ | Uint16Array
38
+ | Int32Array
39
+ | Uint32Array
40
+ | Float32Array
41
+ | Float64Array
42
+ | DataView;
43
+
44
+ type BinaryType = 'blob' | 'arraybuffer';
45
+
46
+ const CONNECTING = 0;
47
+ const OPEN = 1;
48
+ const CLOSING = 2;
49
+ const CLOSED = 3;
50
+
51
+ const CLOSE_NORMAL = 1000;
52
+
53
+ // Abnormal closure where no code is provided in a control frame
54
+ // https://www.rfc-editor.org/rfc/rfc6455.html#section-7.1.5
55
+ const CLOSE_ABNORMAL = 1006;
56
+
57
+ let nextWebSocketId = 0;
58
+
59
+ type WebSocketEventDefinitions = {
60
+ websocketOpen: [{id: number, protocol: string}],
61
+ websocketClosed: [{id: number, code: number, reason: string}],
62
+ websocketMessage: [
63
+ | {type: 'binary', id: number, data: string}
64
+ | {type: 'text', id: number, data: string}
65
+ | {type: 'blob', id: number, data: BlobData},
66
+ ],
67
+ websocketFailed: [{id: number, message: string}],
68
+ };
69
+
70
+ /**
71
+ * Browser-compatible WebSockets implementation.
72
+ *
73
+ * See https://developer.mozilla.org/en-US/docs/Web/API/WebSocket
74
+ * See https://github.com/websockets/ws
75
+ */
76
+ class WebSocket extends EventTarget {
77
+ static CONNECTING: number = CONNECTING;
78
+ static OPEN: number = OPEN;
79
+ static CLOSING: number = CLOSING;
80
+ static CLOSED: number = CLOSED;
81
+
82
+ CONNECTING: number = CONNECTING;
83
+ OPEN: number = OPEN;
84
+ CLOSING: number = CLOSING;
85
+ CLOSED: number = CLOSED;
86
+
87
+ _socketId: number;
88
+ _eventEmitter: NativeEventEmitter<WebSocketEventDefinitions>;
89
+ _subscriptions: Array<EventSubscription>;
90
+ _binaryType: ?BinaryType;
91
+
92
+ bufferedAmount: number;
93
+ extension: ?string;
94
+ protocol: ?string;
95
+ readyState: number = CONNECTING;
96
+ url: ?string;
97
+
98
+ constructor(
99
+ url: string,
100
+ protocols: ?string | ?Array<string>,
101
+ options: ?{headers?: {origin?: string, ...}, ...},
102
+ ) {
103
+ super();
104
+ this.url = url;
105
+ if (typeof protocols === 'string') {
106
+ protocols = [protocols];
107
+ }
108
+
109
+ const {headers = {}, ...unrecognized} = options || {};
110
+
111
+ // Preserve deprecated backwards compatibility for the 'origin' option
112
+ // $FlowFixMe[prop-missing]
113
+ if (unrecognized && typeof unrecognized.origin === 'string') {
114
+ console.warn(
115
+ 'Specifying `origin` as a WebSocket connection option is deprecated. Include it under `headers` instead.',
116
+ );
117
+ /* $FlowFixMe[prop-missing] (>=0.54.0 site=react_native_fb,react_native_
118
+ * oss) This comment suppresses an error found when Flow v0.54 was
119
+ * deployed. To see the error delete this comment and run Flow. */
120
+ headers.origin = unrecognized.origin;
121
+ /* $FlowFixMe[prop-missing] (>=0.54.0 site=react_native_fb,react_native_
122
+ * oss) This comment suppresses an error found when Flow v0.54 was
123
+ * deployed. To see the error delete this comment and run Flow. */
124
+ delete unrecognized.origin;
125
+ }
126
+
127
+ // Warn about and discard anything else
128
+ if (Object.keys(unrecognized).length > 0) {
129
+ console.warn(
130
+ 'Unrecognized WebSocket connection option(s) `' +
131
+ Object.keys(unrecognized).join('`, `') +
132
+ '`. ' +
133
+ 'Did you mean to put these under `headers`?',
134
+ );
135
+ }
136
+
137
+ if (!Array.isArray(protocols)) {
138
+ protocols = null;
139
+ }
140
+
141
+ this._eventEmitter = new NativeEventEmitter(
142
+ // T88715063: NativeEventEmitter only used this parameter on iOS. Now it uses it on all platforms, so this code was modified automatically to preserve its behavior
143
+ // If you want to use the native module on other platforms, please remove this condition and test its behavior
144
+ Platform.OS !== 'ios' ? null : NativeWebSocketModule,
145
+ );
146
+ this._socketId = nextWebSocketId++;
147
+ this._registerEvents();
148
+ NativeWebSocketModule.connect(url, protocols, {headers}, this._socketId);
149
+ }
150
+
151
+ get binaryType(): ?BinaryType {
152
+ return this._binaryType;
153
+ }
154
+
155
+ set binaryType(binaryType: BinaryType): void {
156
+ if (binaryType !== 'blob' && binaryType !== 'arraybuffer') {
157
+ throw new Error("binaryType must be either 'blob' or 'arraybuffer'");
158
+ }
159
+ if (this._binaryType === 'blob' || binaryType === 'blob') {
160
+ invariant(
161
+ BlobManager.isAvailable,
162
+ 'Native module BlobModule is required for blob support',
163
+ );
164
+ if (binaryType === 'blob') {
165
+ BlobManager.addWebSocketHandler(this._socketId);
166
+ } else {
167
+ BlobManager.removeWebSocketHandler(this._socketId);
168
+ }
169
+ }
170
+ this._binaryType = binaryType;
171
+ }
172
+
173
+ close(code?: number, reason?: string): void {
174
+ if (this.readyState === this.CLOSING || this.readyState === this.CLOSED) {
175
+ return;
176
+ }
177
+
178
+ this.readyState = this.CLOSING;
179
+ this._close(code, reason);
180
+ }
181
+
182
+ send(data: string | ArrayBuffer | ArrayBufferView | Blob): void {
183
+ if (this.readyState === this.CONNECTING) {
184
+ throw new Error('INVALID_STATE_ERR');
185
+ }
186
+
187
+ if (data instanceof Blob) {
188
+ invariant(
189
+ BlobManager.isAvailable,
190
+ 'Native module BlobModule is required for blob support',
191
+ );
192
+ BlobManager.sendOverSocket(data, this._socketId);
193
+ return;
194
+ }
195
+
196
+ if (typeof data === 'string') {
197
+ NativeWebSocketModule.send(data, this._socketId);
198
+ return;
199
+ }
200
+
201
+ if (data instanceof ArrayBuffer || ArrayBuffer.isView(data)) {
202
+ NativeWebSocketModule.sendBinary(binaryToBase64(data), this._socketId);
203
+ return;
204
+ }
205
+
206
+ throw new Error('Unsupported data type');
207
+ }
208
+
209
+ ping(): void {
210
+ if (this.readyState === this.CONNECTING) {
211
+ throw new Error('INVALID_STATE_ERR');
212
+ }
213
+
214
+ NativeWebSocketModule.ping(this._socketId);
215
+ }
216
+
217
+ _close(code?: number, reason?: string): void {
218
+ // See https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent
219
+ const statusCode = typeof code === 'number' ? code : CLOSE_NORMAL;
220
+ const closeReason = typeof reason === 'string' ? reason : '';
221
+ NativeWebSocketModule.close(statusCode, closeReason, this._socketId);
222
+
223
+ if (BlobManager.isAvailable && this._binaryType === 'blob') {
224
+ BlobManager.removeWebSocketHandler(this._socketId);
225
+ }
226
+ }
227
+
228
+ _unregisterEvents(): void {
229
+ this._subscriptions.forEach(e => e.remove());
230
+ this._subscriptions = [];
231
+ }
232
+
233
+ _registerEvents(): void {
234
+ this._subscriptions = [
235
+ this._eventEmitter.addListener('websocketMessage', ev => {
236
+ if (ev.id !== this._socketId) {
237
+ return;
238
+ }
239
+ let data: Blob | BlobData | ArrayBuffer | string = ev.data;
240
+ switch (ev.type) {
241
+ case 'binary':
242
+ data = base64.toByteArray(ev.data).buffer;
243
+ break;
244
+ case 'blob':
245
+ data = BlobManager.createFromOptions(ev.data);
246
+ break;
247
+ }
248
+ this.dispatchEvent(new MessageEvent('message', {data}));
249
+ }),
250
+ this._eventEmitter.addListener('websocketOpen', ev => {
251
+ if (ev.id !== this._socketId) {
252
+ return;
253
+ }
254
+ this.readyState = this.OPEN;
255
+ this.protocol = ev.protocol;
256
+ this.dispatchEvent(new Event('open'));
257
+ }),
258
+ this._eventEmitter.addListener('websocketClosed', ev => {
259
+ if (ev.id !== this._socketId) {
260
+ return;
261
+ }
262
+ this.readyState = this.CLOSED;
263
+ this.dispatchEvent(
264
+ new CloseEvent('close', {
265
+ code: ev.code,
266
+ reason: ev.reason,
267
+ // TODO: missing `wasClean` (exposed on iOS as `clean` but missing on Android)
268
+ }),
269
+ );
270
+ this._unregisterEvents();
271
+ this.close();
272
+ }),
273
+ this._eventEmitter.addListener('websocketFailed', ev => {
274
+ if (ev.id !== this._socketId) {
275
+ return;
276
+ }
277
+ this.readyState = this.CLOSED;
278
+ this.dispatchEvent(new Event('error'));
279
+ this.dispatchEvent(
280
+ new CloseEvent('close', {
281
+ code: CLOSE_ABNORMAL,
282
+ reason: ev.message,
283
+ // TODO: Expose `wasClean`
284
+ }),
285
+ );
286
+ this._unregisterEvents();
287
+ this.close();
288
+ }),
289
+ ];
290
+ }
291
+
292
+ get onclose(): EventCallback | null {
293
+ return getEventHandlerAttribute(this, 'close');
294
+ }
295
+
296
+ set onclose(listener: ?EventCallback) {
297
+ setEventHandlerAttribute(this, 'close', listener);
298
+ }
299
+
300
+ get onerror(): EventCallback | null {
301
+ return getEventHandlerAttribute(this, 'error');
302
+ }
303
+
304
+ set onerror(listener: ?EventCallback) {
305
+ setEventHandlerAttribute(this, 'error', listener);
306
+ }
307
+
308
+ get onmessage(): EventCallback | null {
309
+ return getEventHandlerAttribute(this, 'message');
310
+ }
311
+
312
+ set onmessage(listener: ?EventCallback) {
313
+ setEventHandlerAttribute(this, 'message', listener);
314
+ }
315
+
316
+ get onopen(): EventCallback | null {
317
+ return getEventHandlerAttribute(this, 'open');
318
+ }
319
+
320
+ set onopen(listener: ?EventCallback) {
321
+ setEventHandlerAttribute(this, 'open', listener);
322
+ }
323
+ }
324
+
325
+ export default WebSocket;
package/flow/global.js CHANGED
@@ -86,5 +86,3 @@ declare var global: {
86
86
  // Undeclared properties are implicitly `any`.
87
87
  [string | symbol]: any,
88
88
  };
89
-
90
- type $PropertyType<T, K> = T[K];