@office-iss/react-native-win32 0.79.0 → 0.80.0-preview.1
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.
- package/.flowconfig +10 -3
- package/CHANGELOG.json +112 -19
- package/CHANGELOG.md +46 -11
- package/IntegrationTests/ImageCachePolicyTest.js +1 -1
- package/IntegrationTests/LayoutEventsTest.js +1 -4
- package/Libraries/Alert/Alert.d.ts +4 -1
- package/Libraries/Alert/Alert.js +3 -0
- package/Libraries/Alert/RCTAlertManager.js +17 -0
- package/Libraries/Animated/Animated.js.flow +1 -3
- package/Libraries/Animated/AnimatedEvent.js +4 -3
- package/Libraries/Animated/AnimatedExports.js +2 -2
- package/Libraries/Animated/AnimatedExports.js.flow +140 -0
- package/Libraries/Animated/AnimatedImplementation.js +2 -123
- package/Libraries/Animated/Easing.js +13 -15
- package/Libraries/Animated/animations/Animation.js +8 -4
- package/Libraries/Animated/components/AnimatedFlatList.js +7 -6
- package/Libraries/Animated/components/AnimatedScrollView.js +48 -42
- package/Libraries/Animated/components/AnimatedSectionList.js +11 -7
- package/Libraries/Animated/createAnimatedComponent.js +105 -57
- package/Libraries/Animated/nodes/AnimatedNode.js +4 -3
- package/Libraries/Animated/nodes/AnimatedProps.js +46 -26
- package/Libraries/Animated/nodes/AnimatedValue.js +16 -7
- package/Libraries/Animated/nodes/AnimatedValueXY.js +3 -1
- package/Libraries/AppState/AppState.js +7 -2
- package/Libraries/BatchedBridge/MessageQueue.js +2 -2
- package/Libraries/BatchedBridge/NativeModules.js +2 -0
- package/Libraries/Blob/BlobManager.js +1 -0
- package/Libraries/Blob/FileReader.js +219 -8
- package/Libraries/Blob/URL.js +37 -12
- package/Libraries/Blob/URLSearchParams.js +106 -31
- package/Libraries/Blob/URLSearchParams.js.flow +12 -7
- package/Libraries/Components/AccessibilityInfo/AccessibilityInfo.js +1 -1
- package/Libraries/Components/AccessibilityInfo/AccessibilityInfo.win32.js +1 -1
- package/Libraries/Components/AccessibilityInfo/legacySendAccessibilityEvent.js +17 -0
- package/Libraries/Components/ActivityIndicator/ActivityIndicator.js +1 -0
- package/Libraries/Components/Button.js +1 -1
- package/Libraries/Components/Button.win32.js +1 -1
- package/Libraries/Components/DrawerAndroid/DrawerLayoutAndroid.android.js +1 -3
- package/Libraries/{NewAppScreen/components/Colors.js → Components/DrawerAndroid/DrawerLayoutAndroid.ios.js} +6 -10
- package/Libraries/Components/DrawerAndroid/DrawerLayoutAndroid.js +6 -66
- package/Libraries/Components/DrawerAndroid/DrawerLayoutAndroid.js.flow +18 -0
- package/Libraries/Components/DrawerAndroid/DrawerLayoutAndroidFallback.js +71 -0
- package/Libraries/Components/Keyboard/Keyboard.js +5 -3
- package/Libraries/Components/Keyboard/KeyboardAvoidingView.js +6 -3
- package/Libraries/Components/Pressable/Pressable.js +20 -4
- package/Libraries/Components/Pressable/Pressable.win32.js +20 -4
- package/Libraries/Components/ProgressBarAndroid/ProgressBarAndroid.js +25 -3
- package/Libraries/Components/ProgressBarAndroid/ProgressBarAndroidTypes.js +29 -20
- package/Libraries/Components/RefreshControl/RefreshControl.js +1 -1
- package/Libraries/Components/ScrollView/ScrollView.d.ts +3 -3
- package/Libraries/Components/ScrollView/ScrollView.js +132 -122
- package/Libraries/Components/StaticRenderer.js +1 -1
- package/Libraries/Components/Switch/Switch.d.ts +3 -0
- package/Libraries/Components/Switch/Switch.js +8 -4
- package/Libraries/Components/TextInput/AndroidTextInputNativeComponent.js +2 -1
- package/Libraries/Components/TextInput/RCTTextInputViewConfig.js +2 -4
- package/Libraries/Components/TextInput/Tests/TextInputTest.d.ts +2 -1
- package/Libraries/Components/TextInput/Tests/TextInputTest.js.map +1 -1
- package/Libraries/Components/TextInput/TextInput.d.ts +70 -33
- package/Libraries/Components/TextInput/TextInput.flow.js +100 -51
- package/Libraries/Components/TextInput/TextInput.flow.win32.js +1208 -0
- package/Libraries/Components/TextInput/TextInput.js +88 -1027
- package/Libraries/Components/TextInput/TextInput.win32.js +89 -1059
- package/Libraries/Components/TextInput/TextInputState.js +1 -1
- package/Libraries/Components/TextInput/TextInputState.win32.js +1 -1
- package/Libraries/{Modal/ModalInjection.js → Components/ToastAndroid/ToastAndroid.ios.js} +3 -5
- package/Libraries/Components/ToastAndroid/ToastAndroid.js +4 -32
- package/Libraries/Components/ToastAndroid/ToastAndroid.js.flow +109 -0
- package/Libraries/Components/ToastAndroid/ToastAndroid.win32.js +4 -32
- package/Libraries/Components/ToastAndroid/ToastAndroidFallback.js +45 -0
- package/Libraries/Components/Touchable/Tests/TouchableWin32Test.d.ts +2 -1
- package/Libraries/Components/Touchable/Tests/TouchableWin32Test.js.map +1 -1
- package/Libraries/Components/Touchable/Touchable.js +5 -5
- package/Libraries/Components/Touchable/Touchable.win32.js +5 -5
- package/Libraries/Components/Touchable/TouchableBounce.js +14 -7
- package/Libraries/Components/Touchable/TouchableHighlight.js +10 -7
- package/Libraries/Components/Touchable/TouchableNativeFeedback.js +6 -6
- package/Libraries/Components/Touchable/TouchableNativeFeedback.win32.js +6 -6
- package/Libraries/Components/Touchable/TouchableOpacity.js +13 -6
- package/Libraries/Components/View/View.js +18 -21
- package/Libraries/Components/View/View.win32.js +21 -24
- package/Libraries/Components/View/ViewAccessibility.js +25 -1
- package/Libraries/Components/View/ViewAccessibility.win32.js +9 -1
- package/Libraries/Components/View/ViewPropTypes.js +49 -3
- package/Libraries/Components/View/ViewPropTypes.win32.js +49 -3
- package/Libraries/Core/ReactNativeVersion.js +1 -1
- package/Libraries/Core/setUpReactDevTools.js +5 -5
- package/Libraries/Debugging/DebuggingOverlayRegistry.js +3 -3
- package/Libraries/EventEmitter/NativeEventEmitter.js +9 -4
- package/Libraries/Image/AssetSourceResolver.js +17 -4
- package/Libraries/Image/Image.d.ts +26 -10
- package/Libraries/Image/Image.js +17 -0
- package/Libraries/Image/Image.js.flow +5 -5
- package/Libraries/Image/ImageBackground.js +2 -0
- package/Libraries/Image/ImageInjection.js +1 -1
- package/Libraries/Image/ImageProps.js +22 -17
- package/Libraries/Image/ImageSource.js +3 -1
- package/Libraries/Image/ImageSourceUtils.js +4 -2
- package/Libraries/Image/ImageTypes.flow.js +1 -1
- package/Libraries/Image/Tests/ImageWin32Test.d.ts +2 -1
- package/Libraries/Image/Tests/ImageWin32Test.js.map +1 -1
- package/Libraries/Interaction/InteractionManager.d.ts +13 -0
- package/Libraries/Interaction/InteractionManager.js +1 -1
- package/Libraries/Interaction/PanResponder.js +3 -3
- package/Libraries/Interaction/TaskQueue.js +1 -0
- package/Libraries/LayoutAnimation/LayoutAnimation.js +2 -2
- package/Libraries/Linking/Linking.js +1 -1
- package/Libraries/Lists/FlatList.d.ts +2 -2
- package/Libraries/Lists/FlatList.js +8 -11
- package/Libraries/Lists/SectionList.js +39 -42
- package/Libraries/Lists/SectionListModern.js +25 -34
- package/Libraries/Lists/VirtualizedList.js +1 -0
- package/Libraries/Lists/VirtualizedSectionList.js +1 -0
- package/Libraries/LogBox/Data/LogBoxData.js +1 -1
- package/Libraries/LogBox/LogBoxNotificationContainer.js +1 -1
- package/Libraries/LogBox/UI/LogBoxInspectorSourceMapStatus.win32.js +140 -0
- package/Libraries/Modal/Modal.js +33 -7
- package/Libraries/NativeComponent/BaseViewConfig.android.js +2 -0
- package/Libraries/NativeComponent/BaseViewConfig.ios.js +2 -0
- package/Libraries/NativeComponent/BaseViewConfig.js +17 -0
- package/Libraries/NativeComponent/BaseViewConfig.win32.js +1 -0
- package/Libraries/NativeComponent/PlatformBaseViewConfig.js +2 -2
- package/Libraries/NativeModules/specs/NativeDevMenu.js +2 -2
- package/Libraries/Network/RCTNetworking.android.js +1 -1
- package/Libraries/Network/RCTNetworking.ios.js +1 -1
- package/Libraries/Network/RCTNetworking.js +17 -0
- package/Libraries/Network/RCTNetworking.js.flow +1 -1
- package/Libraries/Network/RCTNetworking.win32.js +1 -1
- package/Libraries/Network/XMLHttpRequest.js +781 -10
- package/Libraries/Performance/Systrace.js +7 -7
- package/Libraries/Pressability/Pressability.js +1 -1
- package/Libraries/Pressability/Pressability.win32.js +1 -1
- package/Libraries/ReactNative/AppContainer-dev.js +5 -4
- package/Libraries/ReactNative/AppRegistry.flow.js +49 -0
- package/Libraries/ReactNative/AppRegistry.js +2 -322
- package/Libraries/ReactNative/AppRegistry.js.flow +23 -0
- package/Libraries/ReactNative/AppRegistryImpl.js +316 -0
- package/Libraries/ReactNative/FabricUIManager.js +10 -0
- package/Libraries/ReactNative/ReactFabricPublicInstance/ReactFabricHostComponent.js +2 -4
- package/Libraries/ReactNative/ReactFabricPublicInstance/ReactFabricPublicInstance.js +1 -4
- package/Libraries/ReactNative/RendererImplementation.js +10 -5
- package/Libraries/ReactNative/getNativeComponentAttributes.js +1 -0
- package/Libraries/ReactNative/renderApplication.js +9 -0
- package/Libraries/ReactPrivate/ReactNativePrivateInterface.js +3 -3
- package/Libraries/ReactPrivate/ReactNativePrivateInterface.js.flow +51 -0
- package/Libraries/Renderer/implementations/ReactFabric-dev.js +4840 -4748
- package/Libraries/Renderer/implementations/ReactFabric-prod.js +4947 -4829
- package/Libraries/Renderer/implementations/ReactFabric-profiling.js +3998 -3888
- package/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js +5005 -4948
- package/Libraries/Renderer/implementations/ReactNativeRenderer-prod.js +2744 -2652
- package/Libraries/Renderer/implementations/ReactNativeRenderer-profiling.js +5020 -4933
- package/Libraries/Renderer/shims/ReactNativeTypes.js +3 -3
- package/Libraries/Settings/Settings.ios.js +1 -0
- package/Libraries/Settings/Settings.js +13 -19
- package/Libraries/Settings/Settings.win32.js +19 -20
- package/Libraries/Settings/SettingsFallback.js +33 -0
- package/Libraries/StyleSheet/PlatformColorValueTypes.js +15 -0
- package/Libraries/StyleSheet/PlatformColorValueTypesIOS.js +6 -0
- package/Libraries/StyleSheet/Rect.js +1 -0
- package/Libraries/StyleSheet/StyleSheet.js +31 -200
- package/Libraries/StyleSheet/StyleSheet.js.flow +188 -0
- package/Libraries/StyleSheet/{StyleSheet.win32.js → StyleSheetExports.js} +2 -151
- package/Libraries/StyleSheet/StyleSheetExports.js.flow +112 -0
- package/Libraries/StyleSheet/StyleSheetTypes.d.ts +1 -1
- package/Libraries/StyleSheet/StyleSheetTypes.js +130 -52
- package/Libraries/StyleSheet/flattenStyle.js +14 -4
- package/Libraries/StyleSheet/private/_TransformStyle.js +49 -21
- package/Libraries/StyleSheet/processBackgroundImage.js +670 -214
- package/Libraries/Text/Text.d.ts +2 -5
- package/Libraries/Text/Text.js +3 -3
- package/Libraries/Text/Text.win32.js +3 -3
- package/Libraries/Text/TextNativeComponent.js +0 -4
- package/Libraries/Text/TextNativeComponent.win32.js +0 -4
- package/Libraries/Text/TextProps.js +5 -33
- package/Libraries/Text/TextProps.win32.js +5 -30
- package/Libraries/Types/CodegenTypesNamespace.d.ts +45 -0
- package/Libraries/{Blob/__mocks__/BlobModule.js → Types/CodegenTypesNamespace.js} +4 -6
- package/Libraries/Types/CoreEventTypes.d.ts +6 -1
- package/Libraries/Types/CoreEventTypes.js +1 -1
- package/Libraries/Types/CoreEventTypes.win32.js +1 -1
- package/Libraries/Utilities/Appearance.js +2 -0
- package/Libraries/Utilities/BackHandler.js +17 -0
- package/Libraries/Utilities/DeviceInfo.js +2 -0
- package/Libraries/Utilities/Dimensions.js +1 -1
- package/Libraries/Utilities/Dimensions.win32.js +1 -1
- package/Libraries/Utilities/Platform.js +17 -0
- package/Libraries/Utilities/PlatformTypes.js +11 -3
- package/Libraries/Utilities/ReactNativeTestTools.js +2 -2
- package/Libraries/Utilities/codegenNativeCommands.d.ts +18 -0
- package/Libraries/Utilities/codegenNativeComponent.d.ts +26 -0
- package/Libraries/WebSocket/WebSocket.js +313 -8
- package/Libraries/vendor/core/ErrorUtils.js +28 -2
- package/Libraries/vendor/emitter/EventEmitter.js +6 -2
- package/flow/global.js +1 -0
- package/index.js +51 -331
- package/index.win32.js +71 -352
- package/interface.js +0 -4
- package/jest/resolver.js +31 -0
- package/overrides.json +45 -47
- package/package.json +26 -26
- package/src/private/animated/NativeAnimatedHelper.js +21 -8
- package/src/private/animated/NativeAnimatedHelper.win32.js +21 -8
- package/src/private/animated/createAnimatedPropsHook.js +11 -16
- package/src/private/animated/createAnimatedPropsMemoHook.js +1 -2
- package/src/private/components/{SafeAreaView_INTERNAL_DO_NOT_USE.js → safeareaview/SafeAreaView_INTERNAL_DO_NOT_USE.js} +6 -6
- package/src/private/components/{HScrollViewNativeComponents.js → scrollview/HScrollViewNativeComponents.js} +8 -8
- package/src/private/components/scrollview/VScrollViewNativeComponents.js +25 -0
- package/src/private/{devmenu → devsupport/devmenu}/DevMenu.js +1 -1
- package/src/private/{inspector → devsupport/devmenu/elementinspector}/BorderBox.js +3 -3
- package/src/private/{inspector → devsupport/devmenu/elementinspector}/BoxInspector.js +6 -5
- package/src/private/{inspector → devsupport/devmenu/elementinspector}/ElementBox.js +8 -6
- package/src/private/{inspector → devsupport/devmenu/elementinspector}/ElementProperties.js +11 -10
- package/src/private/{inspector → devsupport/devmenu/elementinspector}/Inspector.js +14 -12
- package/src/private/{inspector → devsupport/devmenu/elementinspector}/InspectorOverlay.js +5 -4
- package/src/private/{inspector → devsupport/devmenu/elementinspector}/InspectorPanel.js +9 -8
- package/src/private/{inspector → devsupport/devmenu/elementinspector}/NetworkOverlay.js +10 -9
- package/src/private/{inspector → devsupport/devmenu/elementinspector}/ReactDevToolsOverlay.js +7 -7
- package/src/private/{inspector → devsupport/devmenu/elementinspector}/StyleInspector.js +7 -6
- package/src/private/{inspector → devsupport/devmenu/elementinspector}/XHRInterceptor.js +2 -2
- package/src/private/{inspector → devsupport/devmenu/elementinspector}/getInspectorDataForViewAtPoint.js +4 -4
- package/src/private/{inspector → devsupport/devmenu/elementinspector}/resolveBoxStyle.js +1 -1
- package/src/private/{inspector → devsupport/devmenu/perfmonitor}/PerformanceOverlay.js +6 -5
- package/src/private/{specs_DEPRECATED/modules → devsupport/devmenu/specs}/NativeDevMenu.js +2 -2
- package/src/private/{debugging → devsupport/rndevtools}/ReactDevToolsSettingsManager.android.js +1 -1
- package/src/private/{debugging → devsupport/rndevtools}/ReactDevToolsSettingsManager.ios.js +1 -1
- package/src/private/{debugging → devsupport/rndevtools}/ReactDevToolsSettingsManager.win32.js +1 -1
- package/src/private/{debugging → devsupport/rndevtools}/setUpFuseboxReactDevToolsDispatcher.js +1 -1
- package/src/private/{fusebox → devsupport/rndevtools}/specs/NativeReactDevToolsRuntimeSettingsModule.js +2 -2
- package/src/private/{specs_DEPRECATED/modules → devsupport/rndevtools/specs}/NativeReactDevToolsSettingsManager.js +2 -2
- package/src/private/featureflags/ReactNativeFeatureFlags.js +82 -80
- package/src/private/featureflags/ReactNativeFeatureFlagsBase.js +9 -1
- package/src/private/featureflags/specs/NativeReactNativeFeatureFlags.js +17 -13
- package/src/private/renderer/errorhandling/ErrorHandlers.js +2 -2
- package/src/private/specs_DEPRECATED/modules/NativeAnimatedModule.js +1 -1
- package/src/private/specs_DEPRECATED/modules/NativeAnimatedTurboModule.js +1 -1
- package/src/private/specs_DEPRECATED/modules/NativeSampleTurboModule.js +3 -0
- package/src/private/styles/composeStyles.js +12 -5
- package/src/private/types/HostComponent.js +1 -1
- package/src/private/types/HostInstance.js +67 -1
- package/src/private/webapis/dom/nodes/ReactNativeElement.js +2 -5
- package/src/private/webapis/dom/nodes/ReadOnlyNode.js +5 -18
- package/src/private/webapis/dom/nodes/internals/NodeInternals.js +6 -0
- package/src/private/webapis/performance/Performance.js +1 -3
- package/src/private/webapis/performance/PerformanceEntry.js +6 -1
- package/src/private/webapis/performance/internals/RawPerformanceEntry.js +3 -0
- package/src/private/webapis/performance/specs/NativePerformance.js +10 -1
- package/src/types/globals.d.ts +42 -0
- package/src-win/Libraries/Components/TextInput/Tests/TextInputTest.tsx +7 -7
- package/src-win/Libraries/Components/Touchable/Tests/TouchableWin32Test.tsx +3 -3
- package/src-win/Libraries/Image/Tests/ImageWin32Test.tsx +1 -1
- package/src-win/Libraries/Text/Text.d.ts +2 -5
- package/types/index.d.ts +6 -3
- package/types/public/ReactNativeTypes.d.ts +2 -2
- package/Libraries/BatchedBridge/__mocks__/MessageQueueTestConfig.js +0 -38
- package/Libraries/BatchedBridge/__mocks__/MessageQueueTestModule.js +0 -22
- package/Libraries/Blob/FileReader_new.js +0 -231
- package/Libraries/Blob/FileReader_old.js +0 -186
- package/Libraries/Blob/__mocks__/FileReaderModule.js +0 -20
- package/Libraries/Components/RefreshControl/__mocks__/RefreshControlMock.js +0 -32
- package/Libraries/Core/__mocks__/ErrorUtils.js +0 -33
- package/Libraries/Core/__mocks__/NativeExceptionsManager.js +0 -19
- package/Libraries/EventEmitter/__mocks__/NativeEventEmitter.js +0 -49
- package/Libraries/Events/CustomEvent.js +0 -32
- package/Libraries/Events/EventPolyfill.js +0 -239
- package/Libraries/Lists/__flowtests__/FlatList-flowtest.js +0 -118
- package/Libraries/Lists/__flowtests__/SectionList-flowtest.js +0 -134
- package/Libraries/Network/XMLHttpRequest_new.js +0 -794
- package/Libraries/Network/XMLHttpRequest_old.js +0 -701
- package/Libraries/NewAppScreen/components/DebugInstructions.js +0 -41
- package/Libraries/NewAppScreen/components/Header.js +0 -77
- package/Libraries/NewAppScreen/components/HermesBadge.js +0 -53
- package/Libraries/NewAppScreen/components/LearnMoreLinks.js +0 -148
- package/Libraries/NewAppScreen/components/ReloadInstructions.js +0 -39
- package/Libraries/NewAppScreen/components/logo.png +0 -0
- package/Libraries/NewAppScreen/index.js +0 -25
- package/Libraries/StyleSheet/__flowtests__/StyleSheet-flowtest.js +0 -58
- package/Libraries/Utilities/DeviceInfo.win32.js +0 -19
- package/Libraries/Utilities/__mocks__/BackHandler.js +0 -45
- package/Libraries/Utilities/__mocks__/GlobalPerformanceLogger.js +0 -16
- package/Libraries/Utilities/__mocks__/PixelRatio.js +0 -25
- package/Libraries/WebSocket/WebSocketEvent.js +0 -30
- package/Libraries/WebSocket/WebSocket_new.js +0 -325
- package/Libraries/WebSocket/WebSocket_old.js +0 -297
- package/Libraries/WebSocket/__mocks__/event-target-shim.js +0 -27
- package/Libraries/__flowtests__/ReactNativeTypes-flowtest.js +0 -30
- package/Libraries/vendor/emitter/__flowtests__/EventEmitter-flowtest.js +0 -81
- package/flow/jest.js +0 -1287
- package/jest/__tests__/setup-test.js +0 -18
- package/src/private/components/VScrollViewNativeComponents.js +0 -25
- package/src/private/utilities/ensureInstance.js +0 -21
- package/src/private/webapis/performance/specs/__mocks__/NativePerformanceMock.js +0 -267
- package/types/modules/LaunchScreen.d.ts +0 -18
- /package/src/private/{devmenu → devsupport/devmenu}/DevMenu.d.ts +0 -0
- /package/src/private/{debugging → devsupport/rndevtools}/FuseboxSessionObserver.js +0 -0
|
@@ -1,794 +0,0 @@
|
|
|
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
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
'use strict';
|
|
12
|
-
|
|
13
|
-
import type {
|
|
14
|
-
EventCallback,
|
|
15
|
-
EventListener,
|
|
16
|
-
} from '../../src/private/webapis/dom/events/EventTarget';
|
|
17
|
-
import type Performance from '../../src/private/webapis/performance/Performance';
|
|
18
|
-
import type {IPerformanceLogger} from '../Utilities/createPerformanceLogger';
|
|
19
|
-
|
|
20
|
-
import Event from '../../src/private/webapis/dom/events/Event';
|
|
21
|
-
import {
|
|
22
|
-
getEventHandlerAttribute,
|
|
23
|
-
setEventHandlerAttribute,
|
|
24
|
-
} from '../../src/private/webapis/dom/events/EventHandlerAttributes';
|
|
25
|
-
import EventTarget from '../../src/private/webapis/dom/events/EventTarget';
|
|
26
|
-
import {dispatchTrustedEvent} from '../../src/private/webapis/dom/events/internals/EventTargetInternals';
|
|
27
|
-
import ProgressEvent from '../../src/private/webapis/xhr/events/ProgressEvent';
|
|
28
|
-
import {type EventSubscription} from '../vendor/emitter/EventEmitter';
|
|
29
|
-
|
|
30
|
-
const BlobManager = require('../Blob/BlobManager').default;
|
|
31
|
-
const GlobalPerformanceLogger =
|
|
32
|
-
require('../Utilities/GlobalPerformanceLogger').default;
|
|
33
|
-
const RCTNetworking = require('./RCTNetworking').default;
|
|
34
|
-
const base64 = require('base64-js');
|
|
35
|
-
const invariant = require('invariant');
|
|
36
|
-
|
|
37
|
-
declare var performance: Performance;
|
|
38
|
-
|
|
39
|
-
const DEBUG_NETWORK_SEND_DELAY: false = false; // Set to a number of milliseconds when debugging
|
|
40
|
-
const LABEL_FOR_MISSING_URL_FOR_PROFILING = 'Unknown URL';
|
|
41
|
-
|
|
42
|
-
export type NativeResponseType = 'base64' | 'blob' | 'text';
|
|
43
|
-
export type ResponseType =
|
|
44
|
-
| ''
|
|
45
|
-
| 'arraybuffer'
|
|
46
|
-
| 'blob'
|
|
47
|
-
| 'document'
|
|
48
|
-
| 'json'
|
|
49
|
-
| 'text';
|
|
50
|
-
export type Response = ?Object | string;
|
|
51
|
-
|
|
52
|
-
type XHRInterceptor = interface {
|
|
53
|
-
requestSent(id: number, url: string, method: string, headers: Object): void,
|
|
54
|
-
responseReceived(
|
|
55
|
-
id: number,
|
|
56
|
-
url: string,
|
|
57
|
-
status: number,
|
|
58
|
-
headers: Object,
|
|
59
|
-
): void,
|
|
60
|
-
dataReceived(id: number, data: string): void,
|
|
61
|
-
loadingFinished(id: number, encodedDataLength: number): void,
|
|
62
|
-
loadingFailed(id: number, error: string): void,
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
// The native blob module is optional so inject it here if available.
|
|
66
|
-
if (BlobManager.isAvailable) {
|
|
67
|
-
BlobManager.addNetworkingHandler();
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const UNSENT = 0;
|
|
71
|
-
const OPENED = 1;
|
|
72
|
-
const HEADERS_RECEIVED = 2;
|
|
73
|
-
const LOADING = 3;
|
|
74
|
-
const DONE = 4;
|
|
75
|
-
|
|
76
|
-
const SUPPORTED_RESPONSE_TYPES = {
|
|
77
|
-
arraybuffer: typeof global.ArrayBuffer === 'function',
|
|
78
|
-
blob: typeof global.Blob === 'function',
|
|
79
|
-
document: false,
|
|
80
|
-
json: true,
|
|
81
|
-
text: true,
|
|
82
|
-
'': true,
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
class XMLHttpRequestEventTarget extends EventTarget {
|
|
86
|
-
get onload(): EventCallback | null {
|
|
87
|
-
return getEventHandlerAttribute(this, 'load');
|
|
88
|
-
}
|
|
89
|
-
set onload(listener: ?EventCallback) {
|
|
90
|
-
setEventHandlerAttribute(this, 'load', listener);
|
|
91
|
-
}
|
|
92
|
-
get onloadstart(): EventCallback | null {
|
|
93
|
-
return getEventHandlerAttribute(this, 'loadstart');
|
|
94
|
-
}
|
|
95
|
-
set onloadstart(listener: ?EventCallback) {
|
|
96
|
-
setEventHandlerAttribute(this, 'loadstart', listener);
|
|
97
|
-
}
|
|
98
|
-
get onprogress(): EventCallback | null {
|
|
99
|
-
return getEventHandlerAttribute(this, 'progress');
|
|
100
|
-
}
|
|
101
|
-
set onprogress(listener: ?EventCallback) {
|
|
102
|
-
setEventHandlerAttribute(this, 'progress', listener);
|
|
103
|
-
}
|
|
104
|
-
get ontimeout(): EventCallback | null {
|
|
105
|
-
return getEventHandlerAttribute(this, 'timeout');
|
|
106
|
-
}
|
|
107
|
-
set ontimeout(listener: ?EventCallback) {
|
|
108
|
-
setEventHandlerAttribute(this, 'timeout', listener);
|
|
109
|
-
}
|
|
110
|
-
get onerror(): EventCallback | null {
|
|
111
|
-
return getEventHandlerAttribute(this, 'error');
|
|
112
|
-
}
|
|
113
|
-
set onerror(listener: ?EventCallback) {
|
|
114
|
-
setEventHandlerAttribute(this, 'error', listener);
|
|
115
|
-
}
|
|
116
|
-
get onabort(): EventCallback | null {
|
|
117
|
-
return getEventHandlerAttribute(this, 'abort');
|
|
118
|
-
}
|
|
119
|
-
set onabort(listener: ?EventCallback) {
|
|
120
|
-
setEventHandlerAttribute(this, 'abort', listener);
|
|
121
|
-
}
|
|
122
|
-
get onloadend(): EventCallback | null {
|
|
123
|
-
return getEventHandlerAttribute(this, 'loadend');
|
|
124
|
-
}
|
|
125
|
-
set onloadend(listener: ?EventCallback) {
|
|
126
|
-
setEventHandlerAttribute(this, 'loadend', listener);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* Shared base for platform-specific XMLHttpRequest implementations.
|
|
132
|
-
*/
|
|
133
|
-
class XMLHttpRequest extends EventTarget {
|
|
134
|
-
static UNSENT: number = UNSENT;
|
|
135
|
-
static OPENED: number = OPENED;
|
|
136
|
-
static HEADERS_RECEIVED: number = HEADERS_RECEIVED;
|
|
137
|
-
static LOADING: number = LOADING;
|
|
138
|
-
static DONE: number = DONE;
|
|
139
|
-
|
|
140
|
-
static _interceptor: ?XHRInterceptor = null;
|
|
141
|
-
static _profiling: boolean = false;
|
|
142
|
-
|
|
143
|
-
UNSENT: number = UNSENT;
|
|
144
|
-
OPENED: number = OPENED;
|
|
145
|
-
HEADERS_RECEIVED: number = HEADERS_RECEIVED;
|
|
146
|
-
LOADING: number = LOADING;
|
|
147
|
-
DONE: number = DONE;
|
|
148
|
-
|
|
149
|
-
readyState: number = UNSENT;
|
|
150
|
-
responseHeaders: ?Object;
|
|
151
|
-
status: number = 0;
|
|
152
|
-
timeout: number = 0;
|
|
153
|
-
responseURL: ?string;
|
|
154
|
-
withCredentials: boolean = true;
|
|
155
|
-
|
|
156
|
-
upload: XMLHttpRequestEventTarget = new XMLHttpRequestEventTarget();
|
|
157
|
-
|
|
158
|
-
_requestId: ?number;
|
|
159
|
-
_subscriptions: Array<EventSubscription>;
|
|
160
|
-
|
|
161
|
-
_aborted: boolean = false;
|
|
162
|
-
_cachedResponse: Response;
|
|
163
|
-
_hasError: boolean = false;
|
|
164
|
-
_headers: Object;
|
|
165
|
-
_lowerCaseResponseHeaders: Object;
|
|
166
|
-
_method: ?string = null;
|
|
167
|
-
_perfKey: ?string = null;
|
|
168
|
-
_responseType: ResponseType;
|
|
169
|
-
_response: string = '';
|
|
170
|
-
_sent: boolean;
|
|
171
|
-
_url: ?string = null;
|
|
172
|
-
_timedOut: boolean = false;
|
|
173
|
-
_trackingName: ?string = null;
|
|
174
|
-
_incrementalEvents: boolean = false;
|
|
175
|
-
_startTime: ?number = null;
|
|
176
|
-
_performanceLogger: IPerformanceLogger = GlobalPerformanceLogger;
|
|
177
|
-
|
|
178
|
-
static __setInterceptor_DO_NOT_USE(interceptor: ?XHRInterceptor) {
|
|
179
|
-
XMLHttpRequest._interceptor = interceptor;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
static enableProfiling(enableProfiling: boolean): void {
|
|
183
|
-
XMLHttpRequest._profiling = enableProfiling;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
constructor() {
|
|
187
|
-
super();
|
|
188
|
-
this._reset();
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
_reset(): void {
|
|
192
|
-
this.readyState = this.UNSENT;
|
|
193
|
-
this.responseHeaders = undefined;
|
|
194
|
-
this.status = 0;
|
|
195
|
-
delete this.responseURL;
|
|
196
|
-
|
|
197
|
-
this._requestId = null;
|
|
198
|
-
|
|
199
|
-
this._cachedResponse = undefined;
|
|
200
|
-
this._hasError = false;
|
|
201
|
-
this._headers = {};
|
|
202
|
-
this._response = '';
|
|
203
|
-
this._responseType = '';
|
|
204
|
-
this._sent = false;
|
|
205
|
-
this._lowerCaseResponseHeaders = {};
|
|
206
|
-
|
|
207
|
-
this._clearSubscriptions();
|
|
208
|
-
this._timedOut = false;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
get responseType(): ResponseType {
|
|
212
|
-
return this._responseType;
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
set responseType(responseType: ResponseType): void {
|
|
216
|
-
if (this._sent) {
|
|
217
|
-
throw new Error(
|
|
218
|
-
"Failed to set the 'responseType' property on 'XMLHttpRequest': The " +
|
|
219
|
-
'response type cannot be set after the request has been sent.',
|
|
220
|
-
);
|
|
221
|
-
}
|
|
222
|
-
if (!SUPPORTED_RESPONSE_TYPES.hasOwnProperty(responseType)) {
|
|
223
|
-
console.warn(
|
|
224
|
-
`The provided value '${responseType}' is not a valid 'responseType'.`,
|
|
225
|
-
);
|
|
226
|
-
return;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
// redboxes early, e.g. for 'arraybuffer' on ios 7
|
|
230
|
-
invariant(
|
|
231
|
-
SUPPORTED_RESPONSE_TYPES[responseType] || responseType === 'document',
|
|
232
|
-
`The provided value '${responseType}' is unsupported in this environment.`,
|
|
233
|
-
);
|
|
234
|
-
|
|
235
|
-
if (responseType === 'blob') {
|
|
236
|
-
invariant(
|
|
237
|
-
BlobManager.isAvailable,
|
|
238
|
-
'Native module BlobModule is required for blob support',
|
|
239
|
-
);
|
|
240
|
-
}
|
|
241
|
-
this._responseType = responseType;
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
get responseText(): string {
|
|
245
|
-
if (this._responseType !== '' && this._responseType !== 'text') {
|
|
246
|
-
throw new Error(
|
|
247
|
-
"The 'responseText' property is only available if 'responseType' " +
|
|
248
|
-
`is set to '' or 'text', but it is '${this._responseType}'.`,
|
|
249
|
-
);
|
|
250
|
-
}
|
|
251
|
-
if (this.readyState < LOADING) {
|
|
252
|
-
return '';
|
|
253
|
-
}
|
|
254
|
-
return this._response;
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
get response(): Response {
|
|
258
|
-
const {responseType} = this;
|
|
259
|
-
if (responseType === '' || responseType === 'text') {
|
|
260
|
-
return this.readyState < LOADING || this._hasError ? '' : this._response;
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
if (this.readyState !== DONE) {
|
|
264
|
-
return null;
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
if (this._cachedResponse !== undefined) {
|
|
268
|
-
return this._cachedResponse;
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
switch (responseType) {
|
|
272
|
-
case 'document':
|
|
273
|
-
this._cachedResponse = null;
|
|
274
|
-
break;
|
|
275
|
-
|
|
276
|
-
case 'arraybuffer':
|
|
277
|
-
this._cachedResponse = base64.toByteArray(this._response).buffer;
|
|
278
|
-
break;
|
|
279
|
-
|
|
280
|
-
case 'blob':
|
|
281
|
-
if (typeof this._response === 'object' && this._response) {
|
|
282
|
-
this._cachedResponse = BlobManager.createFromOptions(this._response);
|
|
283
|
-
} else if (this._response === '') {
|
|
284
|
-
this._cachedResponse = BlobManager.createFromParts([]);
|
|
285
|
-
} else {
|
|
286
|
-
throw new Error(
|
|
287
|
-
'Invalid response for blob - expecting object, was ' +
|
|
288
|
-
`${typeof this._response}: ${this._response.trim()}`,
|
|
289
|
-
);
|
|
290
|
-
}
|
|
291
|
-
break;
|
|
292
|
-
|
|
293
|
-
case 'json':
|
|
294
|
-
try {
|
|
295
|
-
this._cachedResponse = JSON.parse(this._response);
|
|
296
|
-
} catch (_) {
|
|
297
|
-
this._cachedResponse = null;
|
|
298
|
-
}
|
|
299
|
-
break;
|
|
300
|
-
|
|
301
|
-
default:
|
|
302
|
-
this._cachedResponse = null;
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
return this._cachedResponse;
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
// exposed for testing
|
|
309
|
-
__didCreateRequest(requestId: number): void {
|
|
310
|
-
this._requestId = requestId;
|
|
311
|
-
|
|
312
|
-
XMLHttpRequest._interceptor &&
|
|
313
|
-
XMLHttpRequest._interceptor.requestSent(
|
|
314
|
-
requestId,
|
|
315
|
-
this._url || '',
|
|
316
|
-
this._method || 'GET',
|
|
317
|
-
this._headers,
|
|
318
|
-
);
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
// exposed for testing
|
|
322
|
-
__didUploadProgress(
|
|
323
|
-
requestId: number,
|
|
324
|
-
progress: number,
|
|
325
|
-
total: number,
|
|
326
|
-
): void {
|
|
327
|
-
if (requestId === this._requestId) {
|
|
328
|
-
dispatchTrustedEvent(
|
|
329
|
-
this.upload,
|
|
330
|
-
new ProgressEvent('progress', {
|
|
331
|
-
lengthComputable: true,
|
|
332
|
-
loaded: progress,
|
|
333
|
-
total,
|
|
334
|
-
}),
|
|
335
|
-
);
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
__didReceiveResponse(
|
|
340
|
-
requestId: number,
|
|
341
|
-
status: number,
|
|
342
|
-
responseHeaders: ?Object,
|
|
343
|
-
responseURL: ?string,
|
|
344
|
-
): void {
|
|
345
|
-
if (requestId === this._requestId) {
|
|
346
|
-
this._perfKey != null &&
|
|
347
|
-
this._performanceLogger.stopTimespan(this._perfKey);
|
|
348
|
-
this.status = status;
|
|
349
|
-
this.setResponseHeaders(responseHeaders);
|
|
350
|
-
this.setReadyState(this.HEADERS_RECEIVED);
|
|
351
|
-
if (responseURL || responseURL === '') {
|
|
352
|
-
this.responseURL = responseURL;
|
|
353
|
-
} else {
|
|
354
|
-
delete this.responseURL;
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
XMLHttpRequest._interceptor &&
|
|
358
|
-
XMLHttpRequest._interceptor.responseReceived(
|
|
359
|
-
requestId,
|
|
360
|
-
responseURL || this._url || '',
|
|
361
|
-
status,
|
|
362
|
-
responseHeaders || {},
|
|
363
|
-
);
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
__didReceiveData(requestId: number, response: string): void {
|
|
368
|
-
if (requestId !== this._requestId) {
|
|
369
|
-
return;
|
|
370
|
-
}
|
|
371
|
-
this._response = response;
|
|
372
|
-
this._cachedResponse = undefined; // force lazy recomputation
|
|
373
|
-
this.setReadyState(this.LOADING);
|
|
374
|
-
|
|
375
|
-
XMLHttpRequest._interceptor &&
|
|
376
|
-
XMLHttpRequest._interceptor.dataReceived(requestId, response);
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
__didReceiveIncrementalData(
|
|
380
|
-
requestId: number,
|
|
381
|
-
responseText: string,
|
|
382
|
-
progress: number,
|
|
383
|
-
total: number,
|
|
384
|
-
) {
|
|
385
|
-
if (requestId !== this._requestId) {
|
|
386
|
-
return;
|
|
387
|
-
}
|
|
388
|
-
if (!this._response) {
|
|
389
|
-
this._response = responseText;
|
|
390
|
-
} else {
|
|
391
|
-
this._response += responseText;
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
if (XMLHttpRequest._profiling) {
|
|
395
|
-
performance.mark(
|
|
396
|
-
'Track:XMLHttpRequest:Incremental Data: ' + this._getMeasureURL(),
|
|
397
|
-
);
|
|
398
|
-
}
|
|
399
|
-
XMLHttpRequest._interceptor &&
|
|
400
|
-
XMLHttpRequest._interceptor.dataReceived(requestId, responseText);
|
|
401
|
-
|
|
402
|
-
this.setReadyState(this.LOADING);
|
|
403
|
-
this.__didReceiveDataProgress(requestId, progress, total);
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
__didReceiveDataProgress(
|
|
407
|
-
requestId: number,
|
|
408
|
-
loaded: number,
|
|
409
|
-
total: number,
|
|
410
|
-
): void {
|
|
411
|
-
if (requestId !== this._requestId) {
|
|
412
|
-
return;
|
|
413
|
-
}
|
|
414
|
-
dispatchTrustedEvent(
|
|
415
|
-
this,
|
|
416
|
-
new ProgressEvent('progress', {
|
|
417
|
-
lengthComputable: total >= 0,
|
|
418
|
-
loaded,
|
|
419
|
-
total,
|
|
420
|
-
}),
|
|
421
|
-
);
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
// exposed for testing
|
|
425
|
-
__didCompleteResponse(
|
|
426
|
-
requestId: number,
|
|
427
|
-
error: string,
|
|
428
|
-
timeOutError: boolean,
|
|
429
|
-
): void {
|
|
430
|
-
if (requestId === this._requestId) {
|
|
431
|
-
if (error) {
|
|
432
|
-
if (this._responseType === '' || this._responseType === 'text') {
|
|
433
|
-
this._response = error;
|
|
434
|
-
}
|
|
435
|
-
this._hasError = true;
|
|
436
|
-
if (timeOutError) {
|
|
437
|
-
this._timedOut = true;
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
|
-
this._clearSubscriptions();
|
|
441
|
-
this._requestId = null;
|
|
442
|
-
this.setReadyState(this.DONE);
|
|
443
|
-
if (XMLHttpRequest._profiling && this._startTime != null) {
|
|
444
|
-
const start = this._startTime;
|
|
445
|
-
performance.measure('Track:XMLHttpRequest:' + this._getMeasureURL(), {
|
|
446
|
-
start,
|
|
447
|
-
end: performance.now(),
|
|
448
|
-
});
|
|
449
|
-
}
|
|
450
|
-
if (error) {
|
|
451
|
-
XMLHttpRequest._interceptor &&
|
|
452
|
-
XMLHttpRequest._interceptor.loadingFailed(requestId, error);
|
|
453
|
-
} else {
|
|
454
|
-
XMLHttpRequest._interceptor &&
|
|
455
|
-
XMLHttpRequest._interceptor.loadingFinished(
|
|
456
|
-
requestId,
|
|
457
|
-
this._response.length,
|
|
458
|
-
);
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
}
|
|
462
|
-
|
|
463
|
-
_clearSubscriptions(): void {
|
|
464
|
-
(this._subscriptions || []).forEach(sub => {
|
|
465
|
-
if (sub) {
|
|
466
|
-
sub.remove();
|
|
467
|
-
}
|
|
468
|
-
});
|
|
469
|
-
this._subscriptions = [];
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
getAllResponseHeaders(): ?string {
|
|
473
|
-
if (!this.responseHeaders) {
|
|
474
|
-
// according to the spec, return null if no response has been received
|
|
475
|
-
return null;
|
|
476
|
-
}
|
|
477
|
-
|
|
478
|
-
// Assign to non-nullable local variable.
|
|
479
|
-
const responseHeaders = this.responseHeaders;
|
|
480
|
-
|
|
481
|
-
const unsortedHeaders: Map<
|
|
482
|
-
string,
|
|
483
|
-
{lowerHeaderName: string, upperHeaderName: string, headerValue: string},
|
|
484
|
-
> = new Map();
|
|
485
|
-
for (const rawHeaderName of Object.keys(responseHeaders)) {
|
|
486
|
-
const headerValue = responseHeaders[rawHeaderName];
|
|
487
|
-
const lowerHeaderName = rawHeaderName.toLowerCase();
|
|
488
|
-
const header = unsortedHeaders.get(lowerHeaderName);
|
|
489
|
-
if (header) {
|
|
490
|
-
header.headerValue += ', ' + headerValue;
|
|
491
|
-
unsortedHeaders.set(lowerHeaderName, header);
|
|
492
|
-
} else {
|
|
493
|
-
unsortedHeaders.set(lowerHeaderName, {
|
|
494
|
-
lowerHeaderName,
|
|
495
|
-
upperHeaderName: rawHeaderName.toUpperCase(),
|
|
496
|
-
headerValue,
|
|
497
|
-
});
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
|
-
|
|
501
|
-
// Sort in ascending order, with a being less than b if a's name is legacy-uppercased-byte less than b's name.
|
|
502
|
-
const sortedHeaders = [...unsortedHeaders.values()].sort((a, b) => {
|
|
503
|
-
if (a.upperHeaderName < b.upperHeaderName) {
|
|
504
|
-
return -1;
|
|
505
|
-
}
|
|
506
|
-
if (a.upperHeaderName > b.upperHeaderName) {
|
|
507
|
-
return 1;
|
|
508
|
-
}
|
|
509
|
-
return 0;
|
|
510
|
-
});
|
|
511
|
-
|
|
512
|
-
// Combine into single text response.
|
|
513
|
-
return (
|
|
514
|
-
sortedHeaders
|
|
515
|
-
.map(header => {
|
|
516
|
-
return header.lowerHeaderName + ': ' + header.headerValue;
|
|
517
|
-
})
|
|
518
|
-
.join('\r\n') + '\r\n'
|
|
519
|
-
);
|
|
520
|
-
}
|
|
521
|
-
|
|
522
|
-
getResponseHeader(header: string): ?string {
|
|
523
|
-
const value = this._lowerCaseResponseHeaders[header.toLowerCase()];
|
|
524
|
-
return value !== undefined ? value : null;
|
|
525
|
-
}
|
|
526
|
-
|
|
527
|
-
setRequestHeader(header: string, value: any): void {
|
|
528
|
-
if (this.readyState !== this.OPENED) {
|
|
529
|
-
throw new Error('Request has not been opened');
|
|
530
|
-
}
|
|
531
|
-
this._headers[header.toLowerCase()] = String(value);
|
|
532
|
-
}
|
|
533
|
-
|
|
534
|
-
/**
|
|
535
|
-
* Custom extension for tracking origins of request.
|
|
536
|
-
*/
|
|
537
|
-
setTrackingName(trackingName: ?string): XMLHttpRequest {
|
|
538
|
-
this._trackingName = trackingName;
|
|
539
|
-
return this;
|
|
540
|
-
}
|
|
541
|
-
|
|
542
|
-
/**
|
|
543
|
-
* Custom extension for setting a custom performance logger
|
|
544
|
-
*/
|
|
545
|
-
setPerformanceLogger(performanceLogger: IPerformanceLogger): XMLHttpRequest {
|
|
546
|
-
this._performanceLogger = performanceLogger;
|
|
547
|
-
return this;
|
|
548
|
-
}
|
|
549
|
-
|
|
550
|
-
open(method: string, url: string, async: ?boolean): void {
|
|
551
|
-
/* Other optional arguments are not supported yet */
|
|
552
|
-
if (this.readyState !== this.UNSENT) {
|
|
553
|
-
throw new Error('Cannot open, already sending');
|
|
554
|
-
}
|
|
555
|
-
if (async !== undefined && !async) {
|
|
556
|
-
// async is default
|
|
557
|
-
throw new Error('Synchronous http requests are not supported');
|
|
558
|
-
}
|
|
559
|
-
if (!url) {
|
|
560
|
-
throw new Error('Cannot load an empty url');
|
|
561
|
-
}
|
|
562
|
-
this._method = method.toUpperCase();
|
|
563
|
-
this._url = url;
|
|
564
|
-
this._aborted = false;
|
|
565
|
-
this.setReadyState(this.OPENED);
|
|
566
|
-
}
|
|
567
|
-
|
|
568
|
-
send(data: any): void {
|
|
569
|
-
if (this.readyState !== this.OPENED) {
|
|
570
|
-
throw new Error('Request has not been opened');
|
|
571
|
-
}
|
|
572
|
-
if (this._sent) {
|
|
573
|
-
throw new Error('Request has already been sent');
|
|
574
|
-
}
|
|
575
|
-
this._sent = true;
|
|
576
|
-
const incrementalEvents =
|
|
577
|
-
this._incrementalEvents || !!this.onreadystatechange || !!this.onprogress;
|
|
578
|
-
|
|
579
|
-
this._subscriptions.push(
|
|
580
|
-
RCTNetworking.addListener('didSendNetworkData', args =>
|
|
581
|
-
this.__didUploadProgress(...args),
|
|
582
|
-
),
|
|
583
|
-
);
|
|
584
|
-
this._subscriptions.push(
|
|
585
|
-
RCTNetworking.addListener('didReceiveNetworkResponse', args =>
|
|
586
|
-
this.__didReceiveResponse(...args),
|
|
587
|
-
),
|
|
588
|
-
);
|
|
589
|
-
this._subscriptions.push(
|
|
590
|
-
RCTNetworking.addListener('didReceiveNetworkData', args =>
|
|
591
|
-
this.__didReceiveData(...args),
|
|
592
|
-
),
|
|
593
|
-
);
|
|
594
|
-
this._subscriptions.push(
|
|
595
|
-
RCTNetworking.addListener('didReceiveNetworkIncrementalData', args =>
|
|
596
|
-
this.__didReceiveIncrementalData(...args),
|
|
597
|
-
),
|
|
598
|
-
);
|
|
599
|
-
this._subscriptions.push(
|
|
600
|
-
RCTNetworking.addListener('didReceiveNetworkDataProgress', args =>
|
|
601
|
-
this.__didReceiveDataProgress(...args),
|
|
602
|
-
),
|
|
603
|
-
);
|
|
604
|
-
this._subscriptions.push(
|
|
605
|
-
RCTNetworking.addListener('didCompleteNetworkResponse', args =>
|
|
606
|
-
this.__didCompleteResponse(...args),
|
|
607
|
-
),
|
|
608
|
-
);
|
|
609
|
-
|
|
610
|
-
let nativeResponseType: NativeResponseType = 'text';
|
|
611
|
-
if (this._responseType === 'arraybuffer') {
|
|
612
|
-
nativeResponseType = 'base64';
|
|
613
|
-
}
|
|
614
|
-
if (this._responseType === 'blob') {
|
|
615
|
-
nativeResponseType = 'blob';
|
|
616
|
-
}
|
|
617
|
-
|
|
618
|
-
const doSend = () => {
|
|
619
|
-
const friendlyName = this._trackingName ?? this._url;
|
|
620
|
-
this._perfKey = 'network_XMLHttpRequest_' + String(friendlyName);
|
|
621
|
-
this._performanceLogger.startTimespan(this._perfKey);
|
|
622
|
-
this._startTime = performance.now();
|
|
623
|
-
invariant(
|
|
624
|
-
this._method,
|
|
625
|
-
'XMLHttpRequest method needs to be defined (%s).',
|
|
626
|
-
friendlyName,
|
|
627
|
-
);
|
|
628
|
-
invariant(
|
|
629
|
-
this._url,
|
|
630
|
-
'XMLHttpRequest URL needs to be defined (%s).',
|
|
631
|
-
friendlyName,
|
|
632
|
-
);
|
|
633
|
-
RCTNetworking.sendRequest(
|
|
634
|
-
this._method,
|
|
635
|
-
this._trackingName,
|
|
636
|
-
this._url,
|
|
637
|
-
this._headers,
|
|
638
|
-
data,
|
|
639
|
-
/* $FlowFixMe(>=0.78.0 site=react_native_android_fb) This issue was found
|
|
640
|
-
* when making Flow check .android.js files. */
|
|
641
|
-
nativeResponseType,
|
|
642
|
-
incrementalEvents,
|
|
643
|
-
this.timeout,
|
|
644
|
-
// $FlowFixMe[method-unbinding] added when improving typing for this parameters
|
|
645
|
-
this.__didCreateRequest.bind(this),
|
|
646
|
-
this.withCredentials,
|
|
647
|
-
);
|
|
648
|
-
};
|
|
649
|
-
if (DEBUG_NETWORK_SEND_DELAY) {
|
|
650
|
-
setTimeout(doSend, DEBUG_NETWORK_SEND_DELAY);
|
|
651
|
-
} else {
|
|
652
|
-
doSend();
|
|
653
|
-
}
|
|
654
|
-
}
|
|
655
|
-
|
|
656
|
-
abort(): void {
|
|
657
|
-
this._aborted = true;
|
|
658
|
-
if (this._requestId) {
|
|
659
|
-
RCTNetworking.abortRequest(this._requestId);
|
|
660
|
-
}
|
|
661
|
-
// only call onreadystatechange if there is something to abort,
|
|
662
|
-
// below logic is per spec
|
|
663
|
-
if (
|
|
664
|
-
!(
|
|
665
|
-
this.readyState === this.UNSENT ||
|
|
666
|
-
(this.readyState === this.OPENED && !this._sent) ||
|
|
667
|
-
this.readyState === this.DONE
|
|
668
|
-
)
|
|
669
|
-
) {
|
|
670
|
-
this._reset();
|
|
671
|
-
this.setReadyState(this.DONE);
|
|
672
|
-
}
|
|
673
|
-
// Reset again after, in case modified in handler
|
|
674
|
-
this._reset();
|
|
675
|
-
}
|
|
676
|
-
|
|
677
|
-
setResponseHeaders(responseHeaders: ?Object): void {
|
|
678
|
-
this.responseHeaders = responseHeaders || null;
|
|
679
|
-
const headers = responseHeaders || {};
|
|
680
|
-
this._lowerCaseResponseHeaders = Object.keys(headers).reduce<{
|
|
681
|
-
[string]: any,
|
|
682
|
-
}>((lcaseHeaders, headerName) => {
|
|
683
|
-
// $FlowFixMe[invalid-computed-prop]
|
|
684
|
-
lcaseHeaders[headerName.toLowerCase()] = headers[headerName];
|
|
685
|
-
return lcaseHeaders;
|
|
686
|
-
}, {});
|
|
687
|
-
}
|
|
688
|
-
|
|
689
|
-
setReadyState(newState: number): void {
|
|
690
|
-
this.readyState = newState;
|
|
691
|
-
dispatchTrustedEvent(this, new Event('readystatechange'));
|
|
692
|
-
if (newState === this.DONE) {
|
|
693
|
-
if (this._aborted) {
|
|
694
|
-
dispatchTrustedEvent(this, new Event('abort'));
|
|
695
|
-
} else if (this._hasError) {
|
|
696
|
-
if (this._timedOut) {
|
|
697
|
-
dispatchTrustedEvent(this, new Event('timeout'));
|
|
698
|
-
} else {
|
|
699
|
-
dispatchTrustedEvent(this, new Event('error'));
|
|
700
|
-
}
|
|
701
|
-
} else {
|
|
702
|
-
dispatchTrustedEvent(this, new Event('load'));
|
|
703
|
-
}
|
|
704
|
-
dispatchTrustedEvent(this, new Event('loadend'));
|
|
705
|
-
}
|
|
706
|
-
}
|
|
707
|
-
|
|
708
|
-
addEventListener(type: string, listener: EventListener | null): void {
|
|
709
|
-
// If we dont' have a 'readystatechange' event handler, we don't
|
|
710
|
-
// have to send repeated LOADING events with incremental updates
|
|
711
|
-
// to responseText, which will avoid a bunch of native -> JS
|
|
712
|
-
// bridge traffic.
|
|
713
|
-
if (type === 'readystatechange' || type === 'progress') {
|
|
714
|
-
this._incrementalEvents = true;
|
|
715
|
-
}
|
|
716
|
-
super.addEventListener(type, listener);
|
|
717
|
-
}
|
|
718
|
-
|
|
719
|
-
_getMeasureURL(): string {
|
|
720
|
-
return (
|
|
721
|
-
this._trackingName ?? this._url ?? LABEL_FOR_MISSING_URL_FOR_PROFILING
|
|
722
|
-
);
|
|
723
|
-
}
|
|
724
|
-
|
|
725
|
-
/*
|
|
726
|
-
* `on<event>` event handling (without JS prototype magic).
|
|
727
|
-
*/
|
|
728
|
-
|
|
729
|
-
get onabort(): EventCallback | null {
|
|
730
|
-
return getEventHandlerAttribute(this, 'abort');
|
|
731
|
-
}
|
|
732
|
-
|
|
733
|
-
set onabort(listener: ?EventCallback) {
|
|
734
|
-
setEventHandlerAttribute(this, 'abort', listener);
|
|
735
|
-
}
|
|
736
|
-
|
|
737
|
-
get onerror(): EventCallback | null {
|
|
738
|
-
return getEventHandlerAttribute(this, 'error');
|
|
739
|
-
}
|
|
740
|
-
|
|
741
|
-
set onerror(listener: ?EventCallback) {
|
|
742
|
-
setEventHandlerAttribute(this, 'error', listener);
|
|
743
|
-
}
|
|
744
|
-
|
|
745
|
-
get onload(): EventCallback | null {
|
|
746
|
-
return getEventHandlerAttribute(this, 'load');
|
|
747
|
-
}
|
|
748
|
-
|
|
749
|
-
set onload(listener: ?EventCallback) {
|
|
750
|
-
setEventHandlerAttribute(this, 'load', listener);
|
|
751
|
-
}
|
|
752
|
-
|
|
753
|
-
get onloadstart(): EventCallback | null {
|
|
754
|
-
return getEventHandlerAttribute(this, 'loadstart');
|
|
755
|
-
}
|
|
756
|
-
|
|
757
|
-
set onloadstart(listener: ?EventCallback) {
|
|
758
|
-
setEventHandlerAttribute(this, 'loadstart', listener);
|
|
759
|
-
}
|
|
760
|
-
|
|
761
|
-
get onprogress(): EventCallback | null {
|
|
762
|
-
return getEventHandlerAttribute(this, 'progress');
|
|
763
|
-
}
|
|
764
|
-
|
|
765
|
-
set onprogress(listener: ?EventCallback) {
|
|
766
|
-
setEventHandlerAttribute(this, 'progress', listener);
|
|
767
|
-
}
|
|
768
|
-
|
|
769
|
-
get ontimeout(): EventCallback | null {
|
|
770
|
-
return getEventHandlerAttribute(this, 'timeout');
|
|
771
|
-
}
|
|
772
|
-
|
|
773
|
-
set ontimeout(listener: ?EventCallback) {
|
|
774
|
-
setEventHandlerAttribute(this, 'timeout', listener);
|
|
775
|
-
}
|
|
776
|
-
|
|
777
|
-
get onloadend(): EventCallback | null {
|
|
778
|
-
return getEventHandlerAttribute(this, 'loadend');
|
|
779
|
-
}
|
|
780
|
-
|
|
781
|
-
set onloadend(listener: ?EventCallback) {
|
|
782
|
-
setEventHandlerAttribute(this, 'loadend', listener);
|
|
783
|
-
}
|
|
784
|
-
|
|
785
|
-
get onreadystatechange(): EventCallback | null {
|
|
786
|
-
return getEventHandlerAttribute(this, 'readystatechange');
|
|
787
|
-
}
|
|
788
|
-
|
|
789
|
-
set onreadystatechange(listener: ?EventCallback) {
|
|
790
|
-
setEventHandlerAttribute(this, 'readystatechange', listener);
|
|
791
|
-
}
|
|
792
|
-
}
|
|
793
|
-
|
|
794
|
-
export default XMLHttpRequest;
|