@office-iss/react-native-win32 0.0.0-canary.299 → 0.0.0-canary.300

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 (99) hide show
  1. package/.flowconfig +3 -6
  2. package/CHANGELOG.json +46 -1
  3. package/CHANGELOG.md +19 -6
  4. package/IntegrationTests/IntegrationTestsApp.js +1 -1
  5. package/Libraries/Alert/RCTAlertManager.android.js +2 -0
  6. package/Libraries/Animated/Animated.d.ts +2 -0
  7. package/Libraries/Animated/AnimatedImplementation.js +2 -0
  8. package/Libraries/Animated/Easing.js +2 -0
  9. package/Libraries/Animated/animations/Animation.js +14 -14
  10. package/Libraries/Animated/animations/TimingAnimation.js +2 -0
  11. package/Libraries/Animated/nodes/AnimatedNode.js +7 -7
  12. package/Libraries/Animated/nodes/AnimatedObject.js +7 -7
  13. package/Libraries/Animated/nodes/AnimatedProps.js +30 -30
  14. package/Libraries/Animated/nodes/AnimatedStyle.js +17 -17
  15. package/Libraries/Animated/nodes/AnimatedTransform.js +5 -5
  16. package/Libraries/Animated/nodes/AnimatedValue.js +18 -18
  17. package/Libraries/AppState/AppState.js +3 -3
  18. package/Libraries/BatchedBridge/MessageQueue.js +4 -0
  19. package/Libraries/Components/AccessibilityInfo/AccessibilityInfo.js +1 -1
  20. package/Libraries/Components/AccessibilityInfo/AccessibilityInfo.win32.js +1 -1
  21. package/Libraries/Components/Pressable/Pressable.js +10 -1
  22. package/Libraries/Components/Pressable/Pressable.win32.js +9 -0
  23. package/Libraries/Components/StatusBar/StatusBar.js +2 -2
  24. package/Libraries/Components/Switch/Switch.js +1 -1
  25. package/Libraries/Components/TextInput/TextInput.js +2 -2
  26. package/Libraries/Components/TextInput/TextInput.win32.js +2 -1
  27. package/Libraries/Components/Touchable/TouchableBounce.js +1 -1
  28. package/Libraries/Components/Touchable/TouchableHighlight.js +1 -1
  29. package/Libraries/Components/Touchable/TouchableNativeFeedback.js +1 -1
  30. package/Libraries/Components/Touchable/TouchableOpacity.js +1 -1
  31. package/Libraries/Components/Touchable/TouchableWithoutFeedback.js +2 -2
  32. package/Libraries/Components/View/View.js +86 -168
  33. package/Libraries/Core/ReactNativeVersion.js +37 -10
  34. package/Libraries/Core/Timers/queueMicrotask.js +1 -0
  35. package/Libraries/Core/setUpPerformance.js +2 -1
  36. package/Libraries/Interaction/InteractionManager.js +118 -171
  37. package/Libraries/LayoutAnimation/LayoutAnimation.js +2 -0
  38. package/Libraries/LogBox/Data/LogBoxData.js +4 -1
  39. package/Libraries/Modal/Modal.js +1 -1
  40. package/Libraries/NativeComponent/ViewConfig.js +1 -1
  41. package/Libraries/Network/XMLHttpRequest.js +18 -5
  42. package/Libraries/Pressability/Pressability.js +1 -1
  43. package/Libraries/Pressability/Pressability.win32.js +1 -1
  44. package/Libraries/ReactNative/AppRegistryImpl.js +4 -2
  45. package/Libraries/Renderer/implementations/ReactFabric-dev.js +38 -35
  46. package/Libraries/Renderer/implementations/ReactFabric-prod.js +51 -22
  47. package/Libraries/Renderer/implementations/ReactFabric-profiling.js +54 -24
  48. package/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js +36 -33
  49. package/Libraries/Renderer/implementations/ReactNativeRenderer-prod.js +5 -5
  50. package/Libraries/Renderer/implementations/ReactNativeRenderer-profiling.js +5 -5
  51. package/Libraries/Renderer/shims/ReactFabric.js +3 -1
  52. package/Libraries/Renderer/shims/ReactFeatureFlags.js +3 -1
  53. package/Libraries/Renderer/shims/ReactNative.js +3 -1
  54. package/Libraries/Renderer/shims/ReactNativeViewConfigRegistry.js +3 -1
  55. package/Libraries/Renderer/shims/createReactNativeComponentClass.js +3 -1
  56. package/Libraries/Utilities/useMergeRefs.js +1 -1
  57. package/Libraries/promiseRejectionTrackingOptions.js +17 -31
  58. package/flow/HermesInternalType.js +114 -0
  59. package/flow/Stringish.js +14 -0
  60. package/flow/bom.js.flow +554 -0
  61. package/flow/console.js +49 -0
  62. package/flow/cssom.js.flow +575 -0
  63. package/flow/dom.js.flow +6289 -0
  64. package/flow/global.js +88 -0
  65. package/flow/prettier.js.flow +14 -0
  66. package/flow/streams.js.flow +140 -0
  67. package/index.js +5 -2
  68. package/index.win32.js +6 -2
  69. package/jest/mockComponent.js +1 -1
  70. package/jest/setup.js +11 -0
  71. package/overrides.json +11 -11
  72. package/package.json +19 -19
  73. package/src/private/animated/NativeAnimatedHelper.js +8 -1
  74. package/src/private/animated/NativeAnimatedHelper.win32.js +8 -1
  75. package/src/private/animated/createAnimatedPropsHook.js +2 -49
  76. package/src/private/animated/createAnimatedPropsMemoHook.js +2 -48
  77. package/src/private/components/virtualview/VirtualView.js +22 -6
  78. package/src/private/components/virtualview/VirtualViewExperimentalNativeComponent.js +93 -0
  79. package/src/private/devsupport/devmenu/elementinspector/ReactDevToolsOverlay.js +2 -2
  80. package/src/private/featureflags/ReactNativeFeatureFlags.js +71 -51
  81. package/src/private/featureflags/ReactNativeFeatureFlagsBase.js +19 -0
  82. package/src/private/featureflags/specs/NativeReactNativeFeatureFlags.js +15 -5
  83. package/src/private/webapis/dom/nodes/ReadOnlyElement.js +1 -1
  84. package/src/private/webapis/dom/oldstylecollections/HTMLCollection.js +2 -2
  85. package/src/private/webapis/dom/oldstylecollections/NodeList.js +2 -2
  86. package/src/private/webapis/geometry/DOMRectList.js +2 -2
  87. package/src/private/webapis/intersectionobserver/internals/IntersectionObserverManager.js +19 -74
  88. package/src/private/webapis/intersectionobserver/specs/NativeIntersectionObserver.js +0 -4
  89. package/src/private/webapis/performance/EventTiming.js +5 -9
  90. package/src/private/webapis/performance/Performance.js +251 -191
  91. package/src/private/webapis/performance/PerformanceObserver.js +8 -29
  92. package/src/private/webapis/performance/UserTiming.js +24 -23
  93. package/src/private/webapis/performance/UserTimingExtensibility.js.flow +38 -0
  94. package/src/private/webapis/performance/internals/Utilities.js +9 -0
  95. package/src/private/webapis/performance/specs/NativePerformance.js +19 -33
  96. package/src/private/webapis/structuredClone/structuredClone.js +1 -1
  97. package/Libraries/Interaction/InteractionManagerStub.js +0 -184
  98. package/Libraries/Interaction/TaskQueue.js +0 -197
  99. package/Libraries/ReactNative/ReactNativeFeatureFlags.js +0 -31
@@ -21,12 +21,13 @@ import {
21
21
  rawToPerformanceEntry,
22
22
  rawToPerformanceEntryType,
23
23
  } from './internals/RawPerformanceEntry';
24
- import {warnNoNativePerformance} from './internals/Utilities';
25
- import NativePerformance from './specs/NativePerformance';
24
+ import MaybeNativePerformance from './specs/NativePerformance';
26
25
  import nullthrows from 'nullthrows';
27
26
 
28
27
  export {PerformanceEntry} from './PerformanceEntry';
29
28
 
29
+ const NativePerformance = nullthrows(MaybeNativePerformance);
30
+
30
31
  export class PerformanceObserverEntryList {
31
32
  #entries: PerformanceEntryList;
32
33
 
@@ -75,13 +76,6 @@ export interface PerformanceObserverInit {
75
76
  }
76
77
 
77
78
  function getSupportedPerformanceEntryTypes(): $ReadOnlyArray<PerformanceEntryType> {
78
- if (!NativePerformance) {
79
- return Object.freeze([]);
80
- }
81
- if (!NativePerformance.getSupportedPerformanceEntryTypes) {
82
- // fallback if getSupportedPerformanceEntryTypes is not defined on native side
83
- return Object.freeze(['mark', 'measure', 'event']);
84
- }
85
79
  return Object.freeze(
86
80
  NativePerformance.getSupportedPerformanceEntryTypes().map(
87
81
  rawToPerformanceEntryType,
@@ -120,11 +114,6 @@ export class PerformanceObserver {
120
114
  }
121
115
 
122
116
  observe(options: PerformanceObserverInit): void {
123
- if (!NativePerformance || NativePerformance.observe == null) {
124
- warnNoNativePerformance();
125
- return;
126
- }
127
-
128
117
  this.#validateObserveOptions(options);
129
118
 
130
119
  if (this.#nativeObserverHandle == null) {
@@ -135,12 +124,12 @@ export class PerformanceObserver {
135
124
 
136
125
  if (options.entryTypes) {
137
126
  this.#type = 'multiple';
138
- NativePerformance.observe?.(observerHandle, {
127
+ NativePerformance.observe(observerHandle, {
139
128
  entryTypes: options.entryTypes.map(performanceEntryTypeToRaw),
140
129
  });
141
130
  } else if (options.type) {
142
131
  this.#type = 'single';
143
- NativePerformance.observe?.(observerHandle, {
132
+ NativePerformance.observe(observerHandle, {
144
133
  type: performanceEntryTypeToRaw(options.type),
145
134
  buffered: options.buffered,
146
135
  durationThreshold: options.durationThreshold,
@@ -149,12 +138,7 @@ export class PerformanceObserver {
149
138
  }
150
139
 
151
140
  disconnect(): void {
152
- if (!NativePerformance) {
153
- warnNoNativePerformance();
154
- return;
155
- }
156
-
157
- if (this.#nativeObserverHandle == null || !NativePerformance.disconnect) {
141
+ if (this.#nativeObserverHandle == null) {
158
142
  return;
159
143
  }
160
144
 
@@ -162,16 +146,11 @@ export class PerformanceObserver {
162
146
  }
163
147
 
164
148
  #createNativeObserver(): OpaqueNativeObserverHandle | null {
165
- if (!NativePerformance || !NativePerformance.createObserver) {
166
- warnNoNativePerformance();
167
- return null;
168
- }
169
-
170
149
  this.#calledAtLeastOnce = false;
171
150
 
172
151
  const observerHandle: OpaqueNativeObserverHandle =
173
152
  NativePerformance.createObserver(() => {
174
- const rawEntries = NativePerformance.takeRecords?.(
153
+ const rawEntries = NativePerformance.takeRecords(
175
154
  observerHandle,
176
155
  true, // sort records
177
156
  );
@@ -185,7 +164,7 @@ export class PerformanceObserver {
185
164
  let droppedEntriesCount = 0;
186
165
  if (!this.#calledAtLeastOnce) {
187
166
  droppedEntriesCount =
188
- NativePerformance.getDroppedEntriesCount?.(observerHandle) ?? 0;
167
+ NativePerformance.getDroppedEntriesCount(observerHandle);
189
168
  this.#calledAtLeastOnce = true;
190
169
  }
191
170
 
@@ -11,45 +11,52 @@
11
11
  // flowlint unsafe-getters-setters:off
12
12
 
13
13
  import type {DOMHighResTimeStamp} from './PerformanceEntry';
14
+ import type {
15
+ ExtensionMarkerPayload,
16
+ ExtensionTrackEntryPayload,
17
+ } from './UserTimingExtensibility';
14
18
 
19
+ import {getCurrentTimeStamp} from './internals/Utilities';
15
20
  import {PerformanceEntry} from './PerformanceEntry';
16
21
 
17
- export type DetailType = mixed;
22
+ export type DetailType =
23
+ | mixed
24
+ // This will effectively ignored by Flow (mixed | anything = mixed)
25
+ // but we'll use it as documentation for how to use the extensibility API.
26
+ | {devtools?: ExtensionMarkerPayload | ExtensionTrackEntryPayload, ...};
18
27
 
19
- export type PerformanceMarkOptions = {
28
+ export type PerformanceMarkOptions = $ReadOnly<{
20
29
  detail?: DetailType,
21
30
  startTime?: DOMHighResTimeStamp,
22
- };
31
+ }>;
23
32
 
24
33
  export type TimeStampOrName = DOMHighResTimeStamp | string;
25
34
 
26
- export type PerformanceMeasureInit = {
35
+ export type PerformanceMeasureInit = $ReadOnly<{
27
36
  detail?: DetailType,
28
37
  startTime: DOMHighResTimeStamp,
29
38
  duration: DOMHighResTimeStamp,
30
- };
39
+ }>;
31
40
 
32
41
  class PerformanceMarkTemplate extends PerformanceEntry {
33
42
  // We don't use private fields because they're significantly slower to
34
43
  // initialize on construction and to access.
35
- _detail: DetailType;
44
+ __detail: DetailType;
36
45
 
37
46
  // This constructor isn't really used. See `PerformanceMark` below.
38
47
  constructor(markName: string, markOptions?: PerformanceMarkOptions) {
39
48
  super({
40
49
  name: markName,
41
50
  entryType: 'mark',
42
- startTime: markOptions?.startTime ?? performance.now(),
51
+ startTime: markOptions?.startTime ?? getCurrentTimeStamp(),
43
52
  duration: 0,
44
53
  });
45
54
 
46
- if (markOptions) {
47
- this._detail = markOptions.detail;
48
- }
55
+ this.__detail = markOptions?.detail ?? null;
49
56
  }
50
57
 
51
58
  get detail(): DetailType {
52
- return this._detail;
59
+ return this.__detail;
53
60
  }
54
61
  }
55
62
 
@@ -67,12 +74,10 @@ export const PerformanceMark: typeof PerformanceMarkTemplate =
67
74
  ) {
68
75
  this.__name = markName;
69
76
  this.__entryType = 'mark';
70
- this.__startTime = markOptions?.startTime ?? performance.now();
77
+ this.__startTime = markOptions?.startTime ?? getCurrentTimeStamp();
71
78
  this.__duration = 0;
72
79
 
73
- if (markOptions) {
74
- this._detail = markOptions.detail;
75
- }
80
+ this.__detail = markOptions?.detail ?? null;
76
81
  };
77
82
 
78
83
  // $FlowExpectedError[prop-missing]
@@ -81,7 +86,7 @@ PerformanceMark.prototype = PerformanceMarkTemplate.prototype;
81
86
  class PerformanceMeasureTemplate extends PerformanceEntry {
82
87
  // We don't use private fields because they're significantly slower to
83
88
  // initialize on construction and to access.
84
- _detail: DetailType;
89
+ __detail: DetailType;
85
90
 
86
91
  // This constructor isn't really used. See `PerformanceMeasure` below.
87
92
  constructor(measureName: string, measureOptions: PerformanceMeasureInit) {
@@ -92,13 +97,11 @@ class PerformanceMeasureTemplate extends PerformanceEntry {
92
97
  duration: measureOptions.duration,
93
98
  });
94
99
 
95
- if (measureOptions) {
96
- this._detail = measureOptions.detail;
97
- }
100
+ this.__detail = measureOptions?.detail ?? null;
98
101
  }
99
102
 
100
103
  get detail(): DetailType {
101
- return this._detail;
104
+ return this.__detail;
102
105
  }
103
106
  }
104
107
 
@@ -115,9 +118,7 @@ export const PerformanceMeasure: typeof PerformanceMeasureTemplate =
115
118
  this.__startTime = measureOptions.startTime;
116
119
  this.__duration = measureOptions.duration;
117
120
 
118
- if (measureOptions) {
119
- this._detail = measureOptions.detail;
120
- }
121
+ this.__detail = measureOptions.detail ?? null;
121
122
  };
122
123
 
123
124
  // $FlowExpectedError[prop-missing]
@@ -0,0 +1,38 @@
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
8
+ * @format
9
+ */
10
+
11
+ export type DevToolsColor =
12
+ | 'primary'
13
+ | 'primary-light'
14
+ | 'primary-dark'
15
+ | 'secondary'
16
+ | 'secondary-light'
17
+ | 'secondary-dark'
18
+ | 'tertiary'
19
+ | 'tertiary-light'
20
+ | 'tertiary-dark'
21
+ | 'warning'
22
+ | 'error';
23
+
24
+ export interface ExtensionTrackEntryPayload {
25
+ dataType?: 'track-entry'; // Defaults to "track-entry"
26
+ color?: DevToolsColor; // Defaults to "primary"
27
+ track: string; // Required: Name of the custom track
28
+ trackGroup?: string; // Optional: Group for organizing tracks
29
+ properties?: Array<[string, string]>; // Key-value pairs for detailed view
30
+ tooltipText?: string; // Short description for tooltip
31
+ }
32
+
33
+ export interface ExtensionMarkerPayload {
34
+ dataType: 'marker'; // Required: Identifies as a marker
35
+ color?: DevToolsColor; // Defaults to "primary"
36
+ properties?: Array<[string, string]>; // Key-value pairs for detailed view
37
+ tooltipText?: string; // Short description for tooltip
38
+ }
@@ -9,6 +9,7 @@
9
9
  */
10
10
 
11
11
  import warnOnce from '../../../../../Libraries/Utilities/warnOnce';
12
+ import NativePerformance from '../specs/NativePerformance';
12
13
 
13
14
  export function warnNoNativePerformance() {
14
15
  warnOnce(
@@ -16,3 +17,11 @@ export function warnNoNativePerformance() {
16
17
  'Missing native implementation of Performance',
17
18
  );
18
19
  }
20
+
21
+ declare var global: {
22
+ // This value is defined directly via JSI, if available.
23
+ +nativePerformanceNow?: ?() => number,
24
+ };
25
+
26
+ export const getCurrentTimeStamp: () => DOMHighResTimeStamp =
27
+ NativePerformance?.now ?? global.nativePerformanceNow ?? (() => Date.now());
@@ -53,60 +53,46 @@ export type PerformanceObserverInit = {
53
53
  };
54
54
 
55
55
  export interface Spec extends TurboModule {
56
- +now?: () => number;
57
- +markWithResult?: (
58
- name: string,
59
- startTime?: number,
60
- ) => NativePerformanceMarkResult;
61
- +measure?: (
62
- name: string,
63
- startTime?: number,
64
- endTime?: number,
65
- duration?: number,
66
- startMark?: string,
67
- endMark?: string,
68
- ) => NativePerformanceMeasureResult;
69
- // DEPRECATED: Use measure instead.
70
- +measureWithResult?: (
56
+ +now: () => number;
57
+ +reportMark?: (name: string, startTime: number, entry: mixed) => void;
58
+ +reportMeasure?: (
71
59
  name: string,
72
60
  startTime: number,
73
- endTime: number,
74
- duration?: number,
75
- startMark?: string,
76
- endMark?: string,
77
- ) => NativePerformanceMeasureResult;
78
- +clearMarks?: (entryName?: string) => void;
79
- +clearMeasures?: (entryName?: string) => void;
80
- +getEntries?: () => $ReadOnlyArray<RawPerformanceEntry>;
81
- +getEntriesByName?: (
61
+ duration: number,
62
+ entry: mixed,
63
+ ) => void;
64
+ +getMarkTime?: (name: string) => ?number;
65
+ +clearMarks: (entryName?: string) => void;
66
+ +clearMeasures: (entryName?: string) => void;
67
+ +getEntries: () => $ReadOnlyArray<RawPerformanceEntry>;
68
+ +getEntriesByName: (
82
69
  entryName: string,
83
70
  entryType?: ?RawPerformanceEntryType,
84
71
  ) => $ReadOnlyArray<RawPerformanceEntry>;
85
- +getEntriesByType?: (
72
+ +getEntriesByType: (
86
73
  entryType: RawPerformanceEntryType,
87
74
  ) => $ReadOnlyArray<RawPerformanceEntry>;
88
- +getEventCounts?: () => $ReadOnlyArray<[string, number]>;
75
+ +getEventCounts: () => $ReadOnlyArray<[string, number]>;
89
76
  +getSimpleMemoryInfo: () => NativeMemoryInfo;
90
77
  +getReactNativeStartupTiming: () => ReactNativeStartupTiming;
91
78
 
92
- +createObserver?: (
79
+ +createObserver: (
93
80
  callback: NativeBatchedObserverCallback,
94
81
  ) => OpaqueNativeObserverHandle;
95
- +getDroppedEntriesCount?: (observer: OpaqueNativeObserverHandle) => number;
82
+ +getDroppedEntriesCount: (observer: OpaqueNativeObserverHandle) => number;
96
83
 
97
- +observe?: (
84
+ +observe: (
98
85
  observer: OpaqueNativeObserverHandle,
99
86
  options: PerformanceObserverInit,
100
87
  ) => void;
101
- +disconnect?: (observer: OpaqueNativeObserverHandle) => void;
102
- +takeRecords?: (
88
+ +disconnect: (observer: OpaqueNativeObserverHandle) => void;
89
+ +takeRecords: (
103
90
  observer: OpaqueNativeObserverHandle,
104
91
  sort: boolean,
105
92
  ) => $ReadOnlyArray<RawPerformanceEntry>;
106
93
 
107
- +getSupportedPerformanceEntryTypes?: () => $ReadOnlyArray<RawPerformanceEntryType>;
94
+ +getSupportedPerformanceEntryTypes: () => $ReadOnlyArray<RawPerformanceEntryType>;
108
95
 
109
- +setCurrentTimeStampForTesting?: (timeStamp: number) => void;
110
96
  +clearEventCountsForTesting?: () => void;
111
97
  }
112
98
 
@@ -79,7 +79,7 @@ function structuredCloneInternal<T>(value: T): T {
79
79
  }
80
80
 
81
81
  // Simple object fast path
82
- // $FlowIssue[prop-missing] Why doesn't Flow know about Object.prototype?
82
+ // $FlowFixMe[prop-missing] Why doesn't Flow know about Object.prototype?
83
83
  if (Object.getPrototypeOf(value) === ObjectPrototype) {
84
84
  const result = {};
85
85
  memory.set(value, result);
@@ -1,184 +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
- * @flow strict
8
- * @format
9
- */
10
-
11
- import type {EventSubscription} from '../vendor/emitter/EventEmitter';
12
-
13
- const invariant = require('invariant');
14
-
15
- export type Handle = number;
16
-
17
- type Task =
18
- | {
19
- name: string,
20
- run: () => void,
21
- }
22
- | {
23
- name: string,
24
- gen: () => Promise<void>,
25
- }
26
- | (() => void);
27
-
28
- // NOTE: The original implementation of `InteractionManager` never rejected
29
- // the returned promise. This preserves that behavior in the stub.
30
- function reject(error: Error): void {
31
- setTimeout(() => {
32
- throw error;
33
- }, 0);
34
- }
35
-
36
- /**
37
- * InteractionManager allows long-running work to be scheduled after any
38
- * interactions/animations have completed. In particular, this allows JavaScript
39
- * animations to run smoothly.
40
- *
41
- * Applications can schedule tasks to run after interactions with the following:
42
- *
43
- * ```
44
- * InteractionManager.runAfterInteractions(() => {
45
- * // ...long-running synchronous task...
46
- * });
47
- * ```
48
- *
49
- * Compare this to other scheduling alternatives:
50
- *
51
- * - requestAnimationFrame(): for code that animates a view over time.
52
- * - setImmediate/setTimeout(): run code later, note this may delay animations.
53
- * - runAfterInteractions(): run code later, without delaying active animations.
54
- *
55
- * The touch handling system considers one or more active touches to be an
56
- * 'interaction' and will delay `runAfterInteractions()` callbacks until all
57
- * touches have ended or been cancelled.
58
- *
59
- * InteractionManager also allows applications to register animations by
60
- * creating an interaction 'handle' on animation start, and clearing it upon
61
- * completion:
62
- *
63
- * ```
64
- * var handle = InteractionManager.createInteractionHandle();
65
- * // run animation... (`runAfterInteractions` tasks are queued)
66
- * // later, on animation completion:
67
- * InteractionManager.clearInteractionHandle(handle);
68
- * // queued tasks run if all handles were cleared
69
- * ```
70
- *
71
- * `runAfterInteractions` takes either a plain callback function, or a
72
- * `PromiseTask` object with a `gen` method that returns a `Promise`. If a
73
- * `PromiseTask` is supplied, then it is fully resolved (including asynchronous
74
- * dependencies that also schedule more tasks via `runAfterInteractions`) before
75
- * starting on the next task that might have been queued up synchronously
76
- * earlier.
77
- *
78
- * By default, queued tasks are executed together in a loop in one
79
- * `setImmediate` batch. If `setDeadline` is called with a positive number, then
80
- * tasks will only be executed until the deadline (in terms of js event loop run
81
- * time) approaches, at which point execution will yield via setTimeout,
82
- * allowing events such as touches to start interactions and block queued tasks
83
- * from executing, making apps more responsive.
84
- *
85
- * @deprecated
86
- */
87
- const InteractionManagerStub = {
88
- Events: {
89
- interactionStart: 'interactionStart',
90
- interactionComplete: 'interactionComplete',
91
- },
92
-
93
- /**
94
- * Schedule a function to run after all interactions have completed. Returns a cancellable
95
- * "promise".
96
- *
97
- * @deprecated
98
- */
99
- runAfterInteractions(task: ?Task): {
100
- then: <U>(
101
- onFulfill?: ?(void) => ?(Promise<U> | U),
102
- onReject?: ?(error: mixed) => ?(Promise<U> | U),
103
- ) => Promise<U>,
104
- cancel: () => void,
105
- ...
106
- } {
107
- let immediateID: ?$FlowIssue;
108
- const promise = new Promise(resolve => {
109
- immediateID = setImmediate(() => {
110
- if (typeof task === 'object' && task !== null) {
111
- if (typeof task.gen === 'function') {
112
- task.gen().then(resolve, reject);
113
- } else if (typeof task.run === 'function') {
114
- try {
115
- task.run();
116
- resolve();
117
- } catch (error) {
118
- reject(error);
119
- }
120
- } else {
121
- reject(new TypeError(`Task "${task.name}" missing gen or run.`));
122
- }
123
- } else if (typeof task === 'function') {
124
- try {
125
- task();
126
- resolve();
127
- } catch (error) {
128
- reject(error);
129
- }
130
- } else {
131
- reject(new TypeError('Invalid task of type: ' + typeof task));
132
- }
133
- });
134
- });
135
-
136
- return {
137
- // $FlowFixMe[method-unbinding] added when improving typing for this parameters
138
- then: promise.then.bind(promise),
139
- cancel() {
140
- clearImmediate(immediateID);
141
- },
142
- };
143
- },
144
-
145
- /**
146
- * Notify manager that an interaction has started.
147
- *
148
- * @deprecated
149
- */
150
- createInteractionHandle(): Handle {
151
- return -1;
152
- },
153
-
154
- /**
155
- * Notify manager that an interaction has completed.
156
- *
157
- * @deprecated
158
- */
159
- clearInteractionHandle(handle: Handle) {
160
- invariant(!!handle, 'InteractionManager: Must provide a handle to clear.');
161
- },
162
-
163
- /**
164
- * @deprecated
165
- */
166
- addListener(): EventSubscription {
167
- return {
168
- remove() {},
169
- };
170
- },
171
-
172
- /**
173
- * A positive number will use setTimeout to schedule any tasks after the
174
- * eventLoopRunningTime hits the deadline value, otherwise all tasks will be
175
- * executed in one setImmediate batch (default).
176
- *
177
- * @deprecated
178
- */
179
- setDeadline(deadline: number) {
180
- // Do nothing.
181
- },
182
- };
183
-
184
- export default InteractionManagerStub;