@office-iss/react-native-win32 0.75.1 → 0.76.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.
Files changed (174) hide show
  1. package/.eslintrc.js +11 -0
  2. package/.flowconfig +5 -4
  3. package/CHANGELOG.json +172 -40
  4. package/CHANGELOG.md +57 -24
  5. package/Libraries/Alert/Alert.js +3 -0
  6. package/Libraries/Animated/AnimatedEvent.js +1 -1
  7. package/Libraries/Animated/AnimatedImplementation.js +7 -7
  8. package/Libraries/Animated/NativeAnimatedAllowlist.js +111 -0
  9. package/Libraries/Animated/animations/Animation.js +11 -1
  10. package/Libraries/Animated/animations/DecayAnimation.js +1 -1
  11. package/Libraries/Animated/animations/SpringAnimation.js +1 -1
  12. package/Libraries/Animated/animations/TimingAnimation.js +2 -1
  13. package/Libraries/Animated/components/AnimatedScrollView.js +3 -2
  14. package/Libraries/Animated/createAnimatedComponent.js +10 -9
  15. package/Libraries/Animated/nodes/AnimatedColor.js +1 -1
  16. package/Libraries/Animated/nodes/AnimatedInterpolation.js +3 -2
  17. package/Libraries/Animated/nodes/AnimatedNode.js +42 -33
  18. package/Libraries/Animated/nodes/AnimatedObject.js +56 -50
  19. package/Libraries/Animated/nodes/AnimatedProps.js +77 -40
  20. package/Libraries/Animated/nodes/AnimatedStyle.js +103 -59
  21. package/Libraries/Animated/nodes/AnimatedTracking.js +1 -1
  22. package/Libraries/Animated/nodes/AnimatedTransform.js +102 -67
  23. package/Libraries/Animated/nodes/AnimatedValue.js +2 -1
  24. package/Libraries/Animated/nodes/AnimatedWithChildren.js +21 -22
  25. package/Libraries/Animated/useAnimatedProps.js +142 -7
  26. package/Libraries/BatchedBridge/NativeModules.js +2 -0
  27. package/Libraries/Blob/FileReader.js +1 -1
  28. package/Libraries/Blob/URL.js +2 -62
  29. package/Libraries/Blob/URLSearchParams.js +71 -0
  30. package/Libraries/Components/DrawerAndroid/DrawerLayoutAndroid.android.js +1 -1
  31. package/Libraries/Components/RefreshControl/__mocks__/RefreshControlMock.js +1 -1
  32. package/Libraries/Components/ScrollView/ScrollView.js +131 -169
  33. package/Libraries/Components/ScrollView/ScrollViewStickyHeader.js +1 -1
  34. package/Libraries/Components/StatusBar/StatusBar.js +3 -1
  35. package/Libraries/Components/TextInput/TextInput.d.ts +32 -2
  36. package/Libraries/Components/TextInput/TextInput.js +230 -94
  37. package/Libraries/Components/TextInput/TextInput.win32.js +230 -100
  38. package/Libraries/Components/View/ReactNativeStyleAttributes.js +22 -0
  39. package/Libraries/Components/View/ReactNativeViewAttributes.js +2 -0
  40. package/Libraries/Components/View/ReactNativeViewAttributes.win32.js +2 -0
  41. package/Libraries/Components/View/ViewAccessibility.d.ts +15 -0
  42. package/Libraries/Components/View/ViewNativeComponent.js +0 -1
  43. package/Libraries/Components/View/ViewPropTypes.js +14 -0
  44. package/Libraries/Components/View/ViewPropTypes.win32.js +14 -0
  45. package/Libraries/Core/ExceptionsManager.js +2 -0
  46. package/Libraries/Core/InitializeCore.js +3 -1
  47. package/Libraries/Core/ReactFiberErrorDialog.js +3 -0
  48. package/Libraries/Core/ReactNativeVersion.js +4 -4
  49. package/Libraries/Core/ReactNativeVersionCheck.win32.js +1 -1
  50. package/Libraries/Core/setUpErrorHandling.js +7 -1
  51. package/Libraries/Core/setUpGlobals.js +1 -0
  52. package/Libraries/Core/setUpReactRefresh.js +0 -4
  53. package/Libraries/Image/AssetSourceResolver.js +28 -1
  54. package/Libraries/Image/Image.android.js +9 -14
  55. package/Libraries/Image/Image.ios.js +11 -22
  56. package/Libraries/Image/Image.win32.js +11 -24
  57. package/Libraries/Image/ImageBackground.js +1 -8
  58. package/Libraries/Image/ImageUtils.js +9 -9
  59. package/Libraries/Image/ImageViewNativeComponent.js +1 -0
  60. package/Libraries/Inspector/Inspector.js +3 -2
  61. package/Libraries/Inspector/Inspector.win32.js +3 -2
  62. package/Libraries/Inspector/InspectorPanel.js +16 -10
  63. package/Libraries/Inspector/NetworkOverlay.js +1 -1
  64. package/Libraries/Interaction/TaskQueue.js +1 -0
  65. package/Libraries/Lists/FlatList.js +1 -1
  66. package/Libraries/Lists/SectionList.js +2 -2
  67. package/Libraries/Lists/SectionListModern.js +3 -3
  68. package/Libraries/LogBox/Data/LogBoxData.js +24 -3
  69. package/Libraries/LogBox/LogBoxNotificationContainer.js +3 -2
  70. package/Libraries/LogBox/UI/LogBoxInspectorHeader.js +9 -8
  71. package/Libraries/LogBox/UI/LogBoxInspectorHeader.win32.js +9 -29
  72. package/Libraries/Modal/Modal.js +0 -1
  73. package/Libraries/NativeComponent/BaseViewConfig.android.js +8 -0
  74. package/Libraries/NativeComponent/BaseViewConfig.ios.js +7 -0
  75. package/Libraries/NativeComponent/BaseViewConfig.win32.js +7 -0
  76. package/Libraries/NativeComponent/NativeComponentRegistry.js +22 -22
  77. package/Libraries/NativeComponent/StaticViewConfigValidator.js +0 -21
  78. package/Libraries/Network/XMLHttpRequest.js +4 -2
  79. package/Libraries/ReactNative/AppContainer-dev.js +1 -5
  80. package/Libraries/ReactNative/AppContainer-prod.js +1 -5
  81. package/Libraries/ReactNative/AppContainer.js +0 -1
  82. package/Libraries/ReactNative/AppRegistry.js +0 -6
  83. package/Libraries/ReactNative/BridgelessUIManager.js +1 -0
  84. package/Libraries/ReactNative/ReactFabricPublicInstance/ReactFabricHostComponent.js +1 -1
  85. package/Libraries/ReactNative/ReactFabricPublicInstance/ReactFabricPublicInstance.js +5 -5
  86. package/Libraries/ReactNative/RendererImplementation.js +26 -4
  87. package/Libraries/ReactNative/getNativeComponentAttributes.js +8 -0
  88. package/Libraries/ReactNative/renderApplication.js +0 -2
  89. package/Libraries/Renderer/shims/ReactNativeTypes.js +11 -4
  90. package/Libraries/StyleSheet/StyleSheet.js +1 -1
  91. package/Libraries/StyleSheet/StyleSheet.win32.js +1 -1
  92. package/Libraries/StyleSheet/StyleSheetTypes.d.ts +74 -15
  93. package/Libraries/StyleSheet/StyleSheetTypes.js +60 -5
  94. package/Libraries/StyleSheet/processBackgroundImage.js +384 -0
  95. package/Libraries/StyleSheet/processBoxShadow.js +211 -0
  96. package/Libraries/StyleSheet/processFilter.js +231 -42
  97. package/Libraries/Text/Text.js +394 -196
  98. package/Libraries/Text/Text.win32.js +442 -229
  99. package/Libraries/Text/TextNativeComponent.js +2 -1
  100. package/Libraries/Text/TextNativeComponent.win32.js +1 -1
  101. package/Libraries/TurboModule/TurboModuleRegistry.js +13 -50
  102. package/Libraries/Types/CodegenTypes.js +3 -1
  103. package/Libraries/Utilities/Appearance.js +108 -84
  104. package/Libraries/Utilities/DevLoadingView.js +2 -4
  105. package/Libraries/Utilities/HMRClient.js +2 -1
  106. package/Libraries/Utilities/ReactNativeTestTools.js +1 -1
  107. package/Libraries/Utilities/createPerformanceLogger.js +0 -9
  108. package/Libraries/Utilities/stringifyViewConfig.js +22 -0
  109. package/Libraries/Utilities/useColorScheme.js +3 -3
  110. package/Libraries/WebSocket/WebSocket.js +1 -1
  111. package/Libraries/promiseRejectionTrackingOptions.js +1 -1
  112. package/Libraries/vendor/emitter/EventEmitter.js +6 -5
  113. package/flow/jest.js +2 -2
  114. package/index.js +3 -1
  115. package/index.win32.js +3 -1
  116. package/jest/mockComponent.js +4 -1
  117. package/jest/mockModal.js +1 -3
  118. package/jest/mockScrollView.js +1 -1
  119. package/jest/renderer.js +2 -2
  120. package/jest/setup.js +16 -13
  121. package/jest.config.js +1 -2
  122. package/overrides.json +22 -22
  123. package/package.json +27 -26
  124. package/src/private/animated/NativeAnimatedHelper.js +438 -0
  125. package/src/private/animated/NativeAnimatedHelper.win32.js +440 -0
  126. package/src/private/animated/NativeAnimatedValidation.js +64 -0
  127. package/src/private/components/HScrollViewNativeComponents.js +56 -0
  128. package/src/private/components/SafeAreaView_INTERNAL_DO_NOT_USE.js +27 -0
  129. package/src/private/components/VScrollViewNativeComponents.js +48 -0
  130. package/src/private/components/useSyncOnScroll.js +48 -0
  131. package/src/private/featureflags/ReactNativeFeatureFlags.js +166 -16
  132. package/src/private/featureflags/specs/NativeReactNativeFeatureFlags.js +29 -5
  133. package/src/private/fusebox/FuseboxSessionObserver.js +42 -0
  134. package/{Libraries/Core → src/private/renderer/errorhandling}/ErrorHandlers.js +14 -4
  135. package/src/private/setup/setUpDOM.js +28 -0
  136. package/src/private/setup/setUpIntersectionObserver.js +27 -0
  137. package/src/private/setup/setUpMutationObserver.js +26 -0
  138. package/src/private/setup/setUpPerformanceObserver.js +64 -0
  139. package/src/private/specs/modules/NativeAppearance.js +3 -3
  140. package/src/private/specs/modules/NativeLinkingManager.js +1 -1
  141. package/src/private/specs/modules/NativePlatformConstantsWin.js +7 -0
  142. package/src/private/specs/modules/NativeSampleTurboModule.js +14 -1
  143. package/src/private/webapis/dom/nodes/ReadOnlyNode.js +6 -4
  144. package/{Libraries/IntersectionObserver → src/private/webapis/intersectionobserver}/IntersectionObserver.js +5 -3
  145. package/{Libraries/IntersectionObserver → src/private/webapis/intersectionobserver}/IntersectionObserverEntry.js +3 -3
  146. package/{Libraries/IntersectionObserver → src/private/webapis/intersectionobserver}/IntersectionObserverManager.js +14 -17
  147. package/src/private/{specs/modules → webapis/intersectionobserver/specs}/NativeIntersectionObserver.js +2 -2
  148. package/{Libraries/IntersectionObserver → src/private/webapis/intersectionobserver/specs}/__mocks__/NativeIntersectionObserver.js +4 -4
  149. package/{Libraries/MutationObserver → src/private/webapis/mutationobserver}/MutationObserver.js +5 -3
  150. package/{Libraries/MutationObserver → src/private/webapis/mutationobserver}/MutationObserverManager.js +24 -15
  151. package/{Libraries/MutationObserver → src/private/webapis/mutationobserver}/MutationRecord.js +4 -6
  152. package/src/private/{specs/modules → webapis/mutationobserver/specs}/NativeMutationObserver.js +2 -2
  153. package/{Libraries/MutationObserver → src/private/webapis/mutationobserver/specs}/__mocks__/NativeMutationObserver.js +5 -5
  154. package/src/private/webapis/performance/{EventCounts.js → EventTiming.js} +65 -3
  155. package/src/private/webapis/performance/LongTasks.js +39 -0
  156. package/src/private/webapis/performance/Performance.js +22 -9
  157. package/src/private/webapis/performance/PerformanceEntry.js +36 -18
  158. package/src/private/webapis/performance/PerformanceObserver.js +29 -43
  159. package/src/private/webapis/performance/RawPerformanceEntry.js +24 -1
  160. package/src/private/webapis/performance/UserTiming.js +17 -12
  161. package/src/private/webapis/performance/specs/NativePerformanceObserver.js +1 -1
  162. package/src-win/Libraries/Components/View/ViewAccessibility.d.ts +15 -0
  163. package/types/experimental.d.ts +20 -1
  164. package/Libraries/Animated/NativeAnimatedHelper.js +0 -615
  165. package/Libraries/Animated/NativeAnimatedHelper.win32.js +0 -617
  166. package/Libraries/Core/setUpIntersectionObserver.js +0 -16
  167. package/Libraries/Core/setUpMutationObserver.js +0 -16
  168. package/Libraries/Core/setUpPerformanceObserver.js +0 -18
  169. package/Libraries/IntersectionObserver/NativeIntersectionObserver.js +0 -13
  170. package/Libraries/MutationObserver/NativeMutationObserver.js +0 -13
  171. package/Libraries/Utilities/verifyComponentAttributeEquivalence.js +0 -135
  172. package/src/private/core/setUpDOM.js +0 -18
  173. package/src/private/webapis/performance/PerformanceEventTiming.js +0 -55
  174. /package/src/private/{core → styles}/composeStyles.js +0 -0
@@ -14,44 +14,74 @@ import type {PlatformConfig} from '../AnimatedPlatformConfig';
14
14
 
15
15
  import {findNodeHandle} from '../../ReactNative/RendererProxy';
16
16
  import {AnimatedEvent} from '../AnimatedEvent';
17
- import NativeAnimatedHelper from '../NativeAnimatedHelper';
17
+ import NativeAnimatedHelper from '../../../src/private/animated/NativeAnimatedHelper';
18
18
  import AnimatedNode from './AnimatedNode';
19
- import AnimatedObject, {hasAnimatedNode} from './AnimatedObject';
19
+ import AnimatedObject from './AnimatedObject';
20
20
  import AnimatedStyle from './AnimatedStyle';
21
21
  import invariant from 'invariant';
22
22
 
23
- function createAnimatedProps(inputProps: Object): Object {
23
+ function createAnimatedProps(
24
+ inputProps: Object,
25
+ ): [$ReadOnlyArray<string>, $ReadOnlyArray<AnimatedNode>, Object] {
26
+ const nodeKeys: Array<string> = [];
27
+ const nodes: Array<AnimatedNode> = [];
24
28
  const props: Object = {};
25
- for (const key in inputProps) {
29
+
30
+ const keys = Object.keys(inputProps);
31
+ for (let ii = 0, length = keys.length; ii < length; ii++) {
32
+ const key = keys[ii];
26
33
  const value = inputProps[key];
34
+
27
35
  if (key === 'style') {
28
- props[key] = new AnimatedStyle(value);
36
+ const node = new AnimatedStyle(value);
37
+ nodeKeys.push(key);
38
+ nodes.push(node);
39
+ props[key] = node;
29
40
  } else if (value instanceof AnimatedNode) {
30
- props[key] = value;
31
- } else if (hasAnimatedNode(value)) {
32
- props[key] = new AnimatedObject(value);
41
+ const node = value;
42
+ nodeKeys.push(key);
43
+ nodes.push(node);
44
+ props[key] = node;
33
45
  } else {
34
- props[key] = value;
46
+ const node = AnimatedObject.from(value);
47
+ if (node == null) {
48
+ props[key] = value;
49
+ } else {
50
+ nodeKeys.push(key);
51
+ nodes.push(node);
52
+ props[key] = node;
53
+ }
35
54
  }
36
55
  }
37
- return props;
56
+
57
+ return [nodeKeys, nodes, props];
38
58
  }
39
59
 
40
60
  export default class AnimatedProps extends AnimatedNode {
61
+ #nodeKeys: $ReadOnlyArray<string>;
62
+ #nodes: $ReadOnlyArray<AnimatedNode>;
63
+
64
+ _animatedView: any = null;
41
65
  _props: Object;
42
- _animatedView: any;
43
66
  _callback: () => void;
44
67
 
45
- constructor(props: Object, callback: () => void) {
68
+ constructor(inputProps: Object, callback: () => void) {
46
69
  super();
47
- this._props = createAnimatedProps(props);
70
+ const [nodeKeys, nodes, props] = createAnimatedProps(inputProps);
71
+ this.#nodeKeys = nodeKeys;
72
+ this.#nodes = nodes;
73
+ this._props = props;
48
74
  this._callback = callback;
49
75
  }
50
76
 
51
77
  __getValue(): Object {
52
78
  const props: {[string]: any | ((...args: any) => void)} = {};
53
- for (const key in this._props) {
79
+
80
+ const keys = Object.keys(this._props);
81
+ for (let ii = 0, length = keys.length; ii < length; ii++) {
82
+ const key = keys[ii];
54
83
  const value = this._props[key];
84
+
55
85
  if (value instanceof AnimatedNode) {
56
86
  props[key] = value.__getValue();
57
87
  } else if (value instanceof AnimatedEvent) {
@@ -66,21 +96,23 @@ export default class AnimatedProps extends AnimatedNode {
66
96
 
67
97
  __getAnimatedValue(): Object {
68
98
  const props: {[string]: any} = {};
69
- for (const key in this._props) {
70
- const value = this._props[key];
71
- if (value instanceof AnimatedNode) {
72
- props[key] = value.__getAnimatedValue();
73
- }
99
+
100
+ const nodeKeys = this.#nodeKeys;
101
+ const nodes = this.#nodes;
102
+ for (let ii = 0, length = nodes.length; ii < length; ii++) {
103
+ const key = nodeKeys[ii];
104
+ const node = nodes[ii];
105
+ props[key] = node.__getAnimatedValue();
74
106
  }
107
+
75
108
  return props;
76
109
  }
77
110
 
78
111
  __attach(): void {
79
- for (const key in this._props) {
80
- const value = this._props[key];
81
- if (value instanceof AnimatedNode) {
82
- value.__addChild(this);
83
- }
112
+ const nodes = this.#nodes;
113
+ for (let ii = 0, length = nodes.length; ii < length; ii++) {
114
+ const node = nodes[ii];
115
+ node.__addChild(this);
84
116
  }
85
117
  }
86
118
 
@@ -88,12 +120,14 @@ export default class AnimatedProps extends AnimatedNode {
88
120
  if (this.__isNative && this._animatedView) {
89
121
  this.__disconnectAnimatedView();
90
122
  }
91
- for (const key in this._props) {
92
- const value = this._props[key];
93
- if (value instanceof AnimatedNode) {
94
- value.__removeChild(this);
95
- }
123
+ this._animatedView = null;
124
+
125
+ const nodes = this.#nodes;
126
+ for (let ii = 0, length = nodes.length; ii < length; ii++) {
127
+ const node = nodes[ii];
128
+ node.__removeChild(this);
96
129
  }
130
+
97
131
  super.__detach();
98
132
  }
99
133
 
@@ -102,11 +136,10 @@ export default class AnimatedProps extends AnimatedNode {
102
136
  }
103
137
 
104
138
  __makeNative(platformConfig: ?PlatformConfig): void {
105
- for (const key in this._props) {
106
- const value = this._props[key];
107
- if (value instanceof AnimatedNode) {
108
- value.__makeNative(platformConfig);
109
- }
139
+ const nodes = this.#nodes;
140
+ for (let ii = 0, length = nodes.length; ii < length; ii++) {
141
+ const node = nodes[ii];
142
+ node.__makeNative(platformConfig);
110
143
  }
111
144
 
112
145
  if (!this.__isNative) {
@@ -170,14 +203,18 @@ export default class AnimatedProps extends AnimatedNode {
170
203
  }
171
204
 
172
205
  __getNativeConfig(): Object {
206
+ const platformConfig = this.__getPlatformConfig();
173
207
  const propsConfig: {[string]: number} = {};
174
- for (const propKey in this._props) {
175
- const value = this._props[propKey];
176
- if (value instanceof AnimatedNode) {
177
- value.__makeNative(this.__getPlatformConfig());
178
- propsConfig[propKey] = value.__getNativeTag();
179
- }
208
+
209
+ const nodeKeys = this.#nodeKeys;
210
+ const nodes = this.#nodes;
211
+ for (let ii = 0, length = nodes.length; ii < length; ii++) {
212
+ const key = nodeKeys[ii];
213
+ const node = nodes[ii];
214
+ node.__makeNative(platformConfig);
215
+ propsConfig[key] = node.__getNativeTag();
180
216
  }
217
+
181
218
  return {
182
219
  type: 'props',
183
220
  props: propsConfig,
@@ -12,116 +12,160 @@
12
12
 
13
13
  import type {PlatformConfig} from '../AnimatedPlatformConfig';
14
14
 
15
+ import {validateStyles} from '../../../src/private/animated/NativeAnimatedValidation';
15
16
  import * as ReactNativeFeatureFlags from '../../../src/private/featureflags/ReactNativeFeatureFlags';
16
17
  import flattenStyle from '../../StyleSheet/flattenStyle';
17
18
  import Platform from '../../Utilities/Platform';
18
- import NativeAnimatedHelper from '../NativeAnimatedHelper';
19
19
  import AnimatedNode from './AnimatedNode';
20
- import AnimatedObject, {hasAnimatedNode} from './AnimatedObject';
20
+ import AnimatedObject from './AnimatedObject';
21
21
  import AnimatedTransform from './AnimatedTransform';
22
22
  import AnimatedWithChildren from './AnimatedWithChildren';
23
23
 
24
24
  function createAnimatedStyle(
25
- inputStyle: any,
25
+ inputStyle: {[string]: mixed},
26
26
  keepUnanimatedValues: boolean,
27
- ): Object {
28
- // $FlowFixMe[underconstrained-implicit-instantiation]
29
- const style = flattenStyle(inputStyle);
30
- const animatedStyles: any = {};
31
- for (const key in style) {
32
- const value = style[key];
27
+ ): [$ReadOnlyArray<string>, $ReadOnlyArray<AnimatedNode>, Object] {
28
+ const nodeKeys: Array<string> = [];
29
+ const nodes: Array<AnimatedNode> = [];
30
+ const style: {[string]: any} = {};
31
+
32
+ const keys = Object.keys(inputStyle);
33
+ for (let ii = 0, length = keys.length; ii < length; ii++) {
34
+ const key = keys[ii];
35
+ const value = inputStyle[key];
36
+
33
37
  if (value != null && key === 'transform') {
34
- animatedStyles[key] =
35
- ReactNativeFeatureFlags.shouldUseAnimatedObjectForTransform()
36
- ? new AnimatedObject(value)
37
- : new AnimatedTransform(value);
38
+ const node = ReactNativeFeatureFlags.shouldUseAnimatedObjectForTransform()
39
+ ? AnimatedObject.from(value)
40
+ : // $FlowFixMe[incompatible-call] - `value` is mixed.
41
+ new AnimatedTransform(value);
42
+ if (node == null) {
43
+ if (keepUnanimatedValues) {
44
+ style[key] = value;
45
+ }
46
+ } else {
47
+ nodeKeys.push(key);
48
+ nodes.push(node);
49
+ style[key] = node;
50
+ }
38
51
  } else if (value instanceof AnimatedNode) {
39
- animatedStyles[key] = value;
40
- } else if (hasAnimatedNode(value)) {
41
- animatedStyles[key] = new AnimatedObject(value);
42
- } else if (keepUnanimatedValues) {
43
- animatedStyles[key] = value;
52
+ const node = value;
53
+ nodeKeys.push(key);
54
+ nodes.push(node);
55
+ style[key] = value;
56
+ } else {
57
+ const node = AnimatedObject.from(value);
58
+ if (node == null) {
59
+ if (keepUnanimatedValues) {
60
+ style[key] = value;
61
+ }
62
+ } else {
63
+ nodeKeys.push(key);
64
+ nodes.push(node);
65
+ style[key] = node;
66
+ }
44
67
  }
45
68
  }
46
- return animatedStyles;
69
+
70
+ return [nodeKeys, nodes, style];
47
71
  }
48
72
 
49
73
  export default class AnimatedStyle extends AnimatedWithChildren {
74
+ #nodeKeys: $ReadOnlyArray<string>;
75
+ #nodes: $ReadOnlyArray<AnimatedNode>;
76
+
50
77
  _inputStyle: any;
51
- _style: Object;
78
+ _style: {[string]: any};
52
79
 
53
- constructor(style: any) {
80
+ constructor(inputStyle: any) {
54
81
  super();
55
- this._inputStyle = style;
56
- this._style = createAnimatedStyle(style, Platform.OS !== 'web');
82
+ this._inputStyle = inputStyle;
83
+ const [nodeKeys, nodes, style] = createAnimatedStyle(
84
+ // NOTE: This null check should not be necessary, but the types are not
85
+ // strong nor enforced as of this writing. This check should be hoisted
86
+ // to instantiation sites.
87
+ flattenStyle(inputStyle) ?? {},
88
+ Platform.OS !== 'web',
89
+ );
90
+ this.#nodeKeys = nodeKeys;
91
+ this.#nodes = nodes;
92
+ this._style = style;
57
93
  }
58
94
 
59
95
  __getValue(): Object | Array<Object> {
60
- const result: {[string]: any} = {};
61
- for (const key in this._style) {
96
+ const style: {[string]: any} = {};
97
+
98
+ const keys = Object.keys(this._style);
99
+ for (let ii = 0, length = keys.length; ii < length; ii++) {
100
+ const key = keys[ii];
62
101
  const value = this._style[key];
102
+
63
103
  if (value instanceof AnimatedNode) {
64
- result[key] = value.__getValue();
104
+ style[key] = value.__getValue();
65
105
  } else {
66
- result[key] = value;
106
+ style[key] = value;
67
107
  }
68
108
  }
69
109
 
70
- return Platform.OS === 'web' ? [this._inputStyle, result] : result;
110
+ return Platform.OS === 'web' ? [this._inputStyle, style] : style;
71
111
  }
72
112
 
73
113
  __getAnimatedValue(): Object {
74
- const result: {[string]: any} = {};
75
- for (const key in this._style) {
76
- const value = this._style[key];
77
- if (value instanceof AnimatedNode) {
78
- result[key] = value.__getAnimatedValue();
79
- }
114
+ const style: {[string]: any} = {};
115
+
116
+ const nodeKeys = this.#nodeKeys;
117
+ const nodes = this.#nodes;
118
+ for (let ii = 0, length = nodes.length; ii < length; ii++) {
119
+ const key = nodeKeys[ii];
120
+ const node = nodes[ii];
121
+ style[key] = node.__getAnimatedValue();
80
122
  }
81
- return result;
123
+
124
+ return style;
82
125
  }
83
126
 
84
127
  __attach(): void {
85
- for (const key in this._style) {
86
- const value = this._style[key];
87
- if (value instanceof AnimatedNode) {
88
- value.__addChild(this);
89
- }
128
+ const nodes = this.#nodes;
129
+ for (let ii = 0, length = nodes.length; ii < length; ii++) {
130
+ const node = nodes[ii];
131
+ node.__addChild(this);
90
132
  }
91
133
  }
92
134
 
93
135
  __detach(): void {
94
- for (const key in this._style) {
95
- const value = this._style[key];
96
- if (value instanceof AnimatedNode) {
97
- value.__removeChild(this);
98
- }
136
+ const nodes = this.#nodes;
137
+ for (let ii = 0, length = nodes.length; ii < length; ii++) {
138
+ const node = nodes[ii];
139
+ node.__removeChild(this);
99
140
  }
100
141
  super.__detach();
101
142
  }
102
143
 
103
144
  __makeNative(platformConfig: ?PlatformConfig) {
104
- for (const key in this._style) {
105
- const value = this._style[key];
106
- if (value instanceof AnimatedNode) {
107
- value.__makeNative(platformConfig);
108
- }
145
+ const nodes = this.#nodes;
146
+ for (let ii = 0, length = nodes.length; ii < length; ii++) {
147
+ const node = nodes[ii];
148
+ node.__makeNative(platformConfig);
109
149
  }
110
150
  super.__makeNative(platformConfig);
111
151
  }
112
152
 
113
153
  __getNativeConfig(): Object {
154
+ const platformConfig = this.__getPlatformConfig();
114
155
  const styleConfig: {[string]: ?number} = {};
115
- for (const styleKey in this._style) {
116
- if (this._style[styleKey] instanceof AnimatedNode) {
117
- const style = this._style[styleKey];
118
- style.__makeNative(this.__getPlatformConfig());
119
- styleConfig[styleKey] = style.__getNativeTag();
120
- }
121
- // Non-animated styles are set using `setNativeProps`, no need
122
- // to pass those as a part of the node config
156
+
157
+ const nodeKeys = this.#nodeKeys;
158
+ const nodes = this.#nodes;
159
+ for (let ii = 0, length = nodes.length; ii < length; ii++) {
160
+ const key = nodeKeys[ii];
161
+ const node = nodes[ii];
162
+ node.__makeNative(platformConfig);
163
+ styleConfig[key] = node.__getNativeTag();
164
+ }
165
+
166
+ if (__DEV__) {
167
+ validateStyles(styleConfig);
123
168
  }
124
- NativeAnimatedHelper.validateStyles(styleConfig);
125
169
  return {
126
170
  type: 'style',
127
171
  style: styleConfig,
@@ -14,7 +14,7 @@ import type {PlatformConfig} from '../AnimatedPlatformConfig';
14
14
  import type {EndCallback} from '../animations/Animation';
15
15
  import type AnimatedValue from './AnimatedValue';
16
16
 
17
- import NativeAnimatedHelper from '../NativeAnimatedHelper';
17
+ import NativeAnimatedHelper from '../../../src/private/animated/NativeAnimatedHelper';
18
18
  import AnimatedNode from './AnimatedNode';
19
19
 
20
20
  export default class AnimatedTracking extends AnimatedNode {
@@ -12,119 +12,154 @@
12
12
 
13
13
  import type {PlatformConfig} from '../AnimatedPlatformConfig';
14
14
 
15
- import NativeAnimatedHelper from '../NativeAnimatedHelper';
15
+ import {validateTransform} from '../../../src/private/animated/NativeAnimatedValidation';
16
+ import NativeAnimatedHelper from '../../../src/private/animated/NativeAnimatedHelper';
16
17
  import AnimatedNode from './AnimatedNode';
17
18
  import AnimatedWithChildren from './AnimatedWithChildren';
18
19
 
20
+ type Transform<T = AnimatedNode> = {
21
+ [string]:
22
+ | number
23
+ | string
24
+ | T
25
+ | $ReadOnlyArray<number | string | T>
26
+ | {[string]: number | string | T},
27
+ };
28
+
19
29
  export default class AnimatedTransform extends AnimatedWithChildren {
20
- _transforms: $ReadOnlyArray<Object>;
30
+ // NOTE: For potentially historical reasons, some operations only operate on
31
+ // the first level of AnimatedNode instances. This optimizes that bevavior.
32
+ #shallowNodes: $ReadOnlyArray<AnimatedNode>;
33
+
34
+ _transforms: $ReadOnlyArray<Transform<>>;
21
35
 
22
- constructor(transforms: $ReadOnlyArray<Object>) {
36
+ constructor(transforms: $ReadOnlyArray<Transform<>>) {
23
37
  super();
24
38
  this._transforms = transforms;
25
- }
26
39
 
27
- __makeNative(platformConfig: ?PlatformConfig) {
28
- this._transforms.forEach(transform => {
29
- for (const key in transform) {
30
- const value = transform[key];
31
- if (value instanceof AnimatedNode) {
32
- value.__makeNative(platformConfig);
40
+ const shallowNodes = [];
41
+ // NOTE: This check should not be necessary, but the types are not enforced
42
+ // as of this writing. This check should be hoisted to instantiation sites.
43
+ if (Array.isArray(transforms)) {
44
+ for (let ii = 0, length = transforms.length; ii < length; ii++) {
45
+ const transform = transforms[ii];
46
+ // There should be exactly one property in `transform`.
47
+ for (const key in transform) {
48
+ const value = transform[key];
49
+ if (value instanceof AnimatedNode) {
50
+ shallowNodes.push(value);
51
+ }
33
52
  }
34
53
  }
35
- });
54
+ }
55
+ this.#shallowNodes = shallowNodes;
56
+ }
57
+
58
+ __makeNative(platformConfig: ?PlatformConfig) {
59
+ const nodes = this.#shallowNodes;
60
+ for (let ii = 0, length = nodes.length; ii < length; ii++) {
61
+ const node = nodes[ii];
62
+ node.__makeNative(platformConfig);
63
+ }
36
64
  super.__makeNative(platformConfig);
37
65
  }
38
66
 
39
- __getValue(): $ReadOnlyArray<Object> {
40
- return this._get(animatedNode => animatedNode.__getValue());
67
+ __getValue(): $ReadOnlyArray<Transform<any>> {
68
+ return mapTransforms(this._transforms, animatedNode =>
69
+ animatedNode.__getValue(),
70
+ );
41
71
  }
42
72
 
43
- __getAnimatedValue(): $ReadOnlyArray<Object> {
44
- return this._get(animatedNode => animatedNode.__getAnimatedValue());
73
+ __getAnimatedValue(): $ReadOnlyArray<Transform<any>> {
74
+ return mapTransforms(this._transforms, animatedNode =>
75
+ animatedNode.__getAnimatedValue(),
76
+ );
45
77
  }
46
78
 
47
79
  __attach(): void {
48
- this._transforms.forEach(transform => {
49
- for (const key in transform) {
50
- const value = transform[key];
51
- if (value instanceof AnimatedNode) {
52
- value.__addChild(this);
53
- }
54
- }
55
- });
80
+ const nodes = this.#shallowNodes;
81
+ for (let ii = 0, length = nodes.length; ii < length; ii++) {
82
+ const node = nodes[ii];
83
+ node.__addChild(this);
84
+ }
56
85
  }
57
86
 
58
87
  __detach(): void {
59
- this._transforms.forEach(transform => {
60
- for (const key in transform) {
61
- const value = transform[key];
62
- if (value instanceof AnimatedNode) {
63
- value.__removeChild(this);
64
- }
65
- }
66
- });
88
+ const nodes = this.#shallowNodes;
89
+ for (let ii = 0, length = nodes.length; ii < length; ii++) {
90
+ const node = nodes[ii];
91
+ node.__removeChild(this);
92
+ }
67
93
  super.__detach();
68
94
  }
69
95
 
70
96
  __getNativeConfig(): any {
71
- const transConfigs: Array<any> = [];
97
+ const transformsConfig: Array<any> = [];
72
98
 
73
- this._transforms.forEach(transform => {
99
+ const transforms = this._transforms;
100
+ for (let ii = 0, length = transforms.length; ii < length; ii++) {
101
+ const transform = transforms[ii];
102
+ // There should be exactly one property in `transform`.
74
103
  for (const key in transform) {
75
104
  const value = transform[key];
76
105
  if (value instanceof AnimatedNode) {
77
- transConfigs.push({
106
+ transformsConfig.push({
78
107
  type: 'animated',
79
108
  property: key,
80
109
  nodeTag: value.__getNativeTag(),
81
110
  });
82
111
  } else {
83
- transConfigs.push({
112
+ transformsConfig.push({
84
113
  type: 'static',
85
114
  property: key,
115
+ /* $FlowFixMe[incompatible-call] - `value` can be an array or an
116
+ object. This is not currently handled by `transformDataType`.
117
+ Migrating to `TransformObject` might solve this. */
86
118
  value: NativeAnimatedHelper.transformDataType(value),
87
119
  });
88
120
  }
89
121
  }
90
- });
122
+ }
91
123
 
92
- NativeAnimatedHelper.validateTransform(transConfigs);
124
+ if (__DEV__) {
125
+ validateTransform(transformsConfig);
126
+ }
93
127
  return {
94
128
  type: 'transform',
95
- transforms: transConfigs,
129
+ transforms: transformsConfig,
96
130
  };
97
131
  }
132
+ }
98
133
 
99
- _get(getter: AnimatedNode => any): $ReadOnlyArray<Object> {
100
- return this._transforms.map(transform => {
101
- const result: {[string]: any} = {};
102
- for (const key in transform) {
103
- const value = transform[key];
104
- if (value instanceof AnimatedNode) {
105
- result[key] = getter(value);
106
- } else if (Array.isArray(value)) {
107
- result[key] = value.map(element => {
108
- if (element instanceof AnimatedNode) {
109
- return getter(element);
110
- } else {
111
- return element;
112
- }
113
- });
114
- } else if (typeof value === 'object') {
115
- result[key] = {};
116
- for (const [nestedKey, nestedValue] of Object.entries(value)) {
117
- if (nestedValue instanceof AnimatedNode) {
118
- result[key][nestedKey] = getter(nestedValue);
119
- } else {
120
- result[key][nestedKey] = nestedValue;
121
- }
122
- }
123
- } else {
124
- result[key] = value;
134
+ function mapTransforms<T>(
135
+ transforms: $ReadOnlyArray<Transform<>>,
136
+ mapFunction: AnimatedNode => T,
137
+ ): $ReadOnlyArray<Transform<T>> {
138
+ return transforms.map(transform => {
139
+ const result: Transform<T> = {};
140
+ // There should be exactly one property in `transform`.
141
+ for (const key in transform) {
142
+ const value = transform[key];
143
+ if (value instanceof AnimatedNode) {
144
+ result[key] = mapFunction(value);
145
+ } else if (Array.isArray(value)) {
146
+ result[key] = value.map(element =>
147
+ element instanceof AnimatedNode ? mapFunction(element) : element,
148
+ );
149
+ } else if (typeof value === 'object') {
150
+ const object: {[string]: number | string | T} = {};
151
+ for (const propertyName in value) {
152
+ const propertyValue = value[propertyName];
153
+ object[propertyName] =
154
+ propertyValue instanceof AnimatedNode
155
+ ? mapFunction(propertyValue)
156
+ : propertyValue;
125
157
  }
158
+ result[key] = object;
159
+ } else {
160
+ result[key] = value;
126
161
  }
127
- return result;
128
- });
129
- }
162
+ }
163
+ return result;
164
+ });
130
165
  }
@@ -16,7 +16,7 @@ import type AnimatedNode from './AnimatedNode';
16
16
  import type AnimatedTracking from './AnimatedTracking';
17
17
 
18
18
  import InteractionManager from '../../Interaction/InteractionManager';
19
- import NativeAnimatedHelper from '../NativeAnimatedHelper';
19
+ import NativeAnimatedHelper from '../../../src/private/animated/NativeAnimatedHelper';
20
20
  import AnimatedInterpolation from './AnimatedInterpolation';
21
21
  import AnimatedWithChildren from './AnimatedWithChildren';
22
22
 
@@ -49,6 +49,7 @@ const NativeAnimatedAPI = NativeAnimatedHelper.API;
49
49
  * transform which can receive values from multiple parents.
50
50
  */
51
51
  export function flushValue(rootNode: AnimatedNode): void {
52
+ // eslint-disable-next-line func-call-spacing
52
53
  const leaves = new Set<{update: () => void, ...}>();
53
54
  function findAnimatedStyles(node: AnimatedNode) {
54
55
  // $FlowFixMe[prop-missing]