@office-iss/react-native-win32 0.69.0 → 0.70.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 (154) hide show
  1. package/.eslintrc.js +0 -1
  2. package/.flowconfig +5 -1
  3. package/CHANGELOG.json +194 -32
  4. package/CHANGELOG.md +79 -19
  5. package/IntegrationTests/AsyncStorageTest.js +20 -4
  6. package/IntegrationTests/BUCK +2 -2
  7. package/IntegrationTests/LayoutEventsTest.js +4 -1
  8. package/IntegrationTests/{launchWebSocketServer.command → launchWebSocketServer.sh} +3 -9
  9. package/Libraries/Alert/Alert.js +18 -4
  10. package/Libraries/Alert/Alert.win32.js +2 -0
  11. package/Libraries/Alert/NativeAlertManager.js +1 -0
  12. package/Libraries/Animated/Animated.js +2 -2
  13. package/Libraries/Animated/AnimatedEvent.js +7 -4
  14. package/Libraries/Animated/AnimatedImplementation.js +17 -3
  15. package/Libraries/Animated/AnimatedMock.js +7 -2
  16. package/Libraries/Animated/NativeAnimatedHelper.js +220 -95
  17. package/Libraries/Animated/NativeAnimatedModule.js +3 -0
  18. package/Libraries/Animated/NativeAnimatedTurboModule.js +3 -0
  19. package/Libraries/Animated/animations/SpringAnimation.js +3 -3
  20. package/Libraries/Animated/animations/TimingAnimation.js +3 -3
  21. package/Libraries/Animated/createAnimatedComponent.js +8 -1
  22. package/Libraries/Animated/nodes/AnimatedAddition.js +3 -1
  23. package/Libraries/Animated/nodes/AnimatedColor.js +50 -29
  24. package/Libraries/Animated/nodes/AnimatedDiffClamp.js +3 -1
  25. package/Libraries/Animated/nodes/AnimatedDivision.js +3 -1
  26. package/Libraries/Animated/nodes/AnimatedInterpolation.js +22 -21
  27. package/Libraries/Animated/nodes/AnimatedModulo.js +3 -1
  28. package/Libraries/Animated/nodes/AnimatedMultiplication.js +3 -2
  29. package/Libraries/Animated/nodes/AnimatedProps.js +20 -12
  30. package/Libraries/Animated/nodes/AnimatedStyle.js +19 -16
  31. package/Libraries/Animated/nodes/AnimatedSubtraction.js +3 -1
  32. package/Libraries/Animated/nodes/AnimatedTransform.js +5 -5
  33. package/Libraries/Animated/nodes/AnimatedValue.js +14 -5
  34. package/Libraries/Animated/nodes/AnimatedValueXY.js +28 -1
  35. package/Libraries/Animated/useAnimatedProps.js +1 -0
  36. package/Libraries/AppState/AppState.js +0 -32
  37. package/Libraries/BatchedBridge/MessageQueue.js +21 -15
  38. package/Libraries/BatchedBridge/NativeModules.js +3 -4
  39. package/Libraries/Blob/FileReader.js +0 -6
  40. package/Libraries/Components/AccessibilityInfo/AccessibilityInfo.js +0 -20
  41. package/Libraries/Components/AccessibilityInfo/AccessibilityInfo.win32.js +0 -20
  42. package/Libraries/Components/DrawerAndroid/DrawerLayoutAndroid.android.js +4 -0
  43. package/Libraries/Components/Keyboard/Keyboard.js +0 -11
  44. package/Libraries/Components/Pressable/Pressable.js +2 -0
  45. package/Libraries/Components/Pressable/Pressable.win32.js +2 -0
  46. package/Libraries/Components/SafeAreaView/RCTSafeAreaViewNativeComponent.js +1 -3
  47. package/Libraries/Components/SafeAreaView/SafeAreaView.js +3 -30
  48. package/Libraries/Components/SafeAreaView/SafeAreaView.win32.js +4 -32
  49. package/Libraries/Components/ScrollView/ScrollView.js +13 -11
  50. package/Libraries/Components/ScrollView/ScrollViewStickyHeader.js +5 -3
  51. package/Libraries/Components/StatusBar/StatusBar.js +10 -7
  52. package/Libraries/Components/TextInput/InputAccessoryView.js +14 -13
  53. package/Libraries/Components/TextInput/TextInput.js +12 -2
  54. package/Libraries/Components/Touchable/PooledClass.js +16 -4
  55. package/Libraries/Components/Touchable/Touchable.js +50 -1
  56. package/Libraries/Components/Touchable/Touchable.win32.js +972 -0
  57. package/Libraries/Components/Touchable/TouchableNativeFeedback.js +6 -2
  58. package/Libraries/Components/View/ReactNativeStyleAttributes.js +0 -7
  59. package/Libraries/Components/View/ViewPropTypes.js +3 -8
  60. package/Libraries/Components/View/ViewPropTypes.win32.js +3 -8
  61. package/Libraries/Core/ExceptionsManager.js +2 -0
  62. package/Libraries/Core/ReactNativeVersion.js +2 -2
  63. package/Libraries/Core/Timers/JSTimers.js +2 -2
  64. package/Libraries/Core/polyfillPromise.js +0 -32
  65. package/Libraries/Core/setUpBatchedBridge.js +5 -1
  66. package/Libraries/Core/setUpPerformance.js +1 -1
  67. package/Libraries/EventEmitter/NativeEventEmitter.js +0 -13
  68. package/Libraries/Image/AssetSourceResolver.js +2 -2
  69. package/Libraries/Image/Image.android.js +5 -3
  70. package/Libraries/Image/Image.ios.js +6 -3
  71. package/Libraries/Image/Image.win32.js +6 -3
  72. package/Libraries/Image/ImageSource.js +7 -5
  73. package/Libraries/Inspector/ElementBox.js +2 -2
  74. package/Libraries/Inspector/NetworkOverlay.js +13 -8
  75. package/Libraries/Interaction/PanResponder.js +16 -14
  76. package/Libraries/Linking/Linking.js +0 -11
  77. package/Libraries/Lists/FlatList.js +3 -2
  78. package/Libraries/Lists/SectionList.js +2 -0
  79. package/Libraries/Lists/ViewabilityHelper.js +7 -3
  80. package/Libraries/Lists/VirtualizeUtils.js +33 -20
  81. package/Libraries/Lists/VirtualizedList.js +93 -47
  82. package/Libraries/Lists/VirtualizedListContext.js +1 -0
  83. package/Libraries/Lists/VirtualizedSectionList.js +14 -9
  84. package/Libraries/Lists/__tests__/VirtualizeUtils-test.js +19 -18
  85. package/Libraries/Lists/__tests__/VirtualizedList-test.js +10 -6
  86. package/Libraries/LogBox/Data/LogBoxData.js +1 -1
  87. package/Libraries/LogBox/Data/parseLogBoxLog.js +1 -1
  88. package/Libraries/LogBox/LogBox.js +3 -1
  89. package/Libraries/LogBox/UI/AnsiHighlight.js +2 -0
  90. package/Libraries/LogBox/UI/LogBoxInspectorCodeFrame.js +3 -0
  91. package/Libraries/LogBox/UI/LogBoxInspectorSourceMapStatus.js +0 -3
  92. package/Libraries/LogBox/UI/LogBoxInspectorStackFrames.js +8 -3
  93. package/Libraries/NativeComponent/BaseViewConfig.android.js +9 -18
  94. package/Libraries/NativeComponent/BaseViewConfig.ios.js +26 -12
  95. package/Libraries/NativeComponent/BaseViewConfig.win32.js +26 -12
  96. package/Libraries/Network/XMLHttpRequest.js +9 -11
  97. package/Libraries/Performance/PureComponentDebug.js +1 -0
  98. package/Libraries/PermissionsAndroid/NativePermissionsAndroid.js +9 -1
  99. package/Libraries/PermissionsAndroid/PermissionsAndroid.js +16 -0
  100. package/Libraries/Pressability/Pressability.js +26 -16
  101. package/Libraries/Pressability/Pressability.win32.js +26 -16
  102. package/Libraries/Promise.js +0 -1
  103. package/Libraries/ReactNative/AppRegistry.js +16 -13
  104. package/Libraries/ReactNative/BridgelessUIManager.js +2 -0
  105. package/Libraries/ReactNative/PaperUIManager.js +9 -9
  106. package/Libraries/ReactNative/PaperUIManager.win32.js +7 -8
  107. package/Libraries/ReactNative/ReactNativeFeatureFlags.js +12 -0
  108. package/Libraries/ReactNative/ReactNativeRuntimeDiagnostics.js +68 -0
  109. package/Libraries/ReactNative/getNativeComponentAttributes.js +6 -7
  110. package/Libraries/ReactNative/renderApplication.js +1 -1
  111. package/Libraries/Renderer/implementations/ReactFabric-dev.js +4443 -3615
  112. package/Libraries/Renderer/implementations/ReactFabric-prod.js +1496 -1170
  113. package/Libraries/Renderer/implementations/ReactFabric-profiling.js +1694 -1356
  114. package/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js +4439 -3588
  115. package/Libraries/Renderer/implementations/ReactNativeRenderer-prod.js +1583 -1249
  116. package/Libraries/Renderer/implementations/ReactNativeRenderer-profiling.js +1719 -1372
  117. package/Libraries/Storage/AsyncStorage.js +7 -1
  118. package/Libraries/StyleSheet/PlatformColorValueTypes.ios.js +8 -0
  119. package/Libraries/StyleSheet/flattenStyle.js +1 -1
  120. package/Libraries/StyleSheet/processTransform.js +2 -0
  121. package/Libraries/StyleSheet/splitLayoutProps.js +2 -0
  122. package/Libraries/Text/Text.js +15 -7
  123. package/Libraries/Types/CoreEventTypes.js +137 -11
  124. package/Libraries/Types/CoreEventTypes.win32.js +147 -22
  125. package/Libraries/Utilities/Dimensions.js +0 -13
  126. package/Libraries/Utilities/Dimensions.win32.js +0 -9
  127. package/Libraries/Utilities/HMRClient.js +3 -3
  128. package/Libraries/Utilities/Platform.ios.js +0 -7
  129. package/Libraries/Utilities/ReactNativeTestTools.js +3 -1
  130. package/Libraries/Utilities/codegenNativeCommands.js +11 -2
  131. package/Libraries/Utilities/deepFreezeAndThrowOnMutationInDev.js +2 -0
  132. package/Libraries/Utilities/stringifySafe.js +3 -1
  133. package/Libraries/Utilities/truncate.js +1 -1
  134. package/Libraries/Utilities/verifyComponentAttributeEquivalence.js +2 -2
  135. package/Libraries/Vibration/Vibration.js +1 -1
  136. package/Libraries/WebSocket/WebSocket.js +1 -0
  137. package/Libraries/vendor/emitter/EventEmitter.js +105 -12
  138. package/Libraries/vendor/emitter/__flowtests__/EventEmitter-flowtest.js +73 -117
  139. package/flow/JSITimerInternalType.js +30 -0
  140. package/jest/assetFileTransformer.js +3 -2
  141. package/jest/setup.js +4 -0
  142. package/jest.config.js +0 -1
  143. package/overrides.json +23 -16
  144. package/package.json +23 -24
  145. package/rntypes/index.d.ts +0 -1
  146. package/src/rntypes/index.d.ts +0 -1
  147. package/Libraries/vendor/emitter/EventSubscription.js +0 -19
  148. package/Libraries/vendor/emitter/_EmitterSubscription.js +0 -62
  149. package/Libraries/vendor/emitter/_EventEmitter.js +0 -184
  150. package/Libraries/vendor/emitter/_EventSubscription.js +0 -45
  151. package/Libraries/vendor/emitter/_EventSubscriptionVendor.js +0 -108
  152. package/jest/preprocessor.js +0 -40
  153. package/jest/preprocessor_DO_NOT_USE.js +0 -122
  154. package/src/Libraries/Lists/__tests__/__snapshots__/VirtualizeUtils-test.js.snap +0 -3
@@ -55,6 +55,7 @@ function createAnimatedComponent<Props: {+[string]: mixed, ...}, Instance>(
55
55
  _prevComponent: any;
56
56
  _propsAnimated: AnimatedProps;
57
57
  _eventDetachers: Array<Function> = [];
58
+ _initialAnimatedProps: Object;
58
59
 
59
60
  // Only to be used in this file, and only in Fabric.
60
61
  _animatedComponentId: string = `${animatedComponentNextId++}:animatedComponent`;
@@ -200,11 +201,17 @@ function createAnimatedComponent<Props: {+[string]: mixed, ...}, Instance>(
200
201
  });
201
202
 
202
203
  render() {
203
- const {style = {}, ...props} = this._propsAnimated.__getValue() || {};
204
+ const animatedProps =
205
+ this._propsAnimated.__getValue(this._initialAnimatedProps) || {};
206
+ const {style = {}, ...props} = animatedProps;
204
207
  const {style: passthruStyle = {}, ...passthruProps} =
205
208
  this.props.passthroughAnimatedPropExplicitValues || {};
206
209
  const mergedStyle = {...style, ...passthruStyle};
207
210
 
211
+ if (!this._initialAnimatedProps) {
212
+ this._initialAnimatedProps = animatedProps;
213
+ }
214
+
208
215
  // Force `collapsable` to be false so that native view is not flattened.
209
216
  // Flattened views cannot be accurately referenced by a native driver.
210
217
  return (
@@ -38,7 +38,9 @@ class AnimatedAddition extends AnimatedWithChildren {
38
38
  return this._a.__getValue() + this._b.__getValue();
39
39
  }
40
40
 
41
- interpolate(config: InterpolationConfigType): AnimatedInterpolation {
41
+ interpolate<OutputT: number | string>(
42
+ config: InterpolationConfigType<OutputT>,
43
+ ): AnimatedInterpolation<OutputT> {
42
44
  return new AnimatedInterpolation(this, config);
43
45
  }
44
46
 
@@ -21,7 +21,12 @@ import type {ColorValue} from '../../StyleSheet/StyleSheet';
21
21
  import type {NativeColorValue} from '../../StyleSheet/PlatformColorValueTypes';
22
22
  import type {ProcessedColorValue} from '../../StyleSheet/processColor';
23
23
 
24
- type ColorListenerCallback = (value: string) => mixed;
24
+ export type AnimatedColorConfig = $ReadOnly<{
25
+ useNativeDriver: boolean,
26
+ }>;
27
+
28
+ type ColorListenerCallback = (value: ColorValue) => mixed;
29
+
25
30
  export type RgbaValue = {
26
31
  +r: number,
27
32
  +g: number,
@@ -29,6 +34,7 @@ export type RgbaValue = {
29
34
  +a: number,
30
35
  ...
31
36
  };
37
+
32
38
  type RgbaAnimatedValue = {
33
39
  +r: AnimatedValue,
34
40
  +g: AnimatedValue,
@@ -37,6 +43,8 @@ type RgbaAnimatedValue = {
37
43
  ...
38
44
  };
39
45
 
46
+ const NativeAnimatedAPI = NativeAnimatedHelper.API;
47
+
40
48
  const defaultColor: RgbaValue = {r: 0, g: 0, b: 0, a: 1.0};
41
49
  let _uniqueId = 1;
42
50
 
@@ -116,7 +124,10 @@ export default class AnimatedColor extends AnimatedWithChildren {
116
124
  ...
117
125
  } = {};
118
126
 
119
- constructor(valueIn?: ?(RgbaValue | RgbaAnimatedValue | ColorValue)) {
127
+ constructor(
128
+ valueIn?: ?(RgbaValue | RgbaAnimatedValue | ColorValue),
129
+ config?: ?AnimatedColorConfig,
130
+ ) {
120
131
  super();
121
132
  let value: RgbaValue | RgbaAnimatedValue | ColorValue =
122
133
  valueIn ?? defaultColor;
@@ -144,12 +155,9 @@ export default class AnimatedColor extends AnimatedWithChildren {
144
155
  this.g = new AnimatedValue(initColor.g);
145
156
  this.b = new AnimatedValue(initColor.b);
146
157
  this.a = new AnimatedValue(initColor.a);
147
-
148
- if (this.nativeColor) {
149
- if (!this.__isNative) {
150
- this.__makeNative();
151
- }
152
- }
158
+ }
159
+ if (this.nativeColor || (config && config.useNativeDriver)) {
160
+ this.__makeNative();
153
161
  }
154
162
  }
155
163
 
@@ -158,34 +166,43 @@ export default class AnimatedColor extends AnimatedWithChildren {
158
166
  * and update all the bound properties.
159
167
  */
160
168
  setValue(value: RgbaValue | ColorValue): void {
161
- this.nativeColor = null;
169
+ let shouldUpdateNodeConfig = false;
170
+ if (this.__isNative) {
171
+ const nativeTag = this.__getNativeTag();
172
+ NativeAnimatedAPI.setWaitingForIdentifier(nativeTag.toString());
173
+ }
162
174
 
163
175
  const processedColor: RgbaValue | NativeColorValue =
164
176
  processColor(value) ?? defaultColor;
165
177
  if (isRgbaValue(processedColor)) {
166
- // $FlowIgnore[incompatible-cast] - Type is verified above
167
- const rgbaValue: RgbaValue = (processedColor: RgbaValue);
178
+ // $FlowIgnore[incompatible-type] - Type is verified above
179
+ const rgbaValue: RgbaValue = processedColor;
168
180
  this.r.setValue(rgbaValue.r);
169
181
  this.g.setValue(rgbaValue.g);
170
182
  this.b.setValue(rgbaValue.b);
171
183
  this.a.setValue(rgbaValue.a);
184
+ if (this.nativeColor != null) {
185
+ this.nativeColor = null;
186
+ shouldUpdateNodeConfig = true;
187
+ }
172
188
  } else {
173
- // $FlowIgnore[incompatible-cast] - Type is verified above
174
- this.nativeColor = (processedColor: NativeColorValue);
175
- }
176
-
177
- if (this.nativeColor) {
178
- if (!this.__isNative) {
179
- this.__makeNative();
189
+ // $FlowIgnore[incompatible-type] - Type is verified above
190
+ const nativeColor: NativeColorValue = processedColor;
191
+ if (this.nativeColor !== nativeColor) {
192
+ this.nativeColor = nativeColor;
193
+ shouldUpdateNodeConfig = true;
180
194
  }
195
+ }
181
196
 
197
+ if (this.__isNative) {
182
198
  const nativeTag = this.__getNativeTag();
183
- NativeAnimatedHelper.API.setWaitingForIdentifier(nativeTag.toString());
184
- NativeAnimatedHelper.API.updateAnimatedNodeConfig(
185
- nativeTag,
186
- this.__getNativeConfig(),
187
- );
188
- NativeAnimatedHelper.API.unsetWaitingForIdentifier(nativeTag.toString());
199
+ if (shouldUpdateNodeConfig) {
200
+ NativeAnimatedAPI.updateAnimatedNodeConfig(
201
+ nativeTag,
202
+ this.__getNativeConfig(),
203
+ );
204
+ }
205
+ NativeAnimatedAPI.unsetWaitingForIdentifier(nativeTag.toString());
189
206
  }
190
207
  }
191
208
 
@@ -232,7 +249,7 @@ export default class AnimatedColor extends AnimatedWithChildren {
232
249
  */
233
250
  addListener(callback: ColorListenerCallback): string {
234
251
  const id = String(_uniqueId++);
235
- const jointCallback = ({value: number}) => {
252
+ const jointCallback = ({value: number}: any) => {
236
253
  callback(this.__getValue());
237
254
  };
238
255
  this._listeners[id] = {
@@ -272,7 +289,7 @@ export default class AnimatedColor extends AnimatedWithChildren {
272
289
  * final value after stopping the animation, which is useful for updating
273
290
  * state to match the animation position with layout.
274
291
  */
275
- stopAnimation(callback?: (value: string) => void): void {
292
+ stopAnimation(callback?: ColorListenerCallback): void {
276
293
  this.r.stopAnimation();
277
294
  this.g.stopAnimation();
278
295
  this.b.stopAnimation();
@@ -283,7 +300,7 @@ export default class AnimatedColor extends AnimatedWithChildren {
283
300
  /**
284
301
  * Stops any animation and resets the value to its original.
285
302
  */
286
- resetAnimation(callback?: (value: string) => void): void {
303
+ resetAnimation(callback?: ColorListenerCallback): void {
287
304
  this.r.resetAnimation();
288
305
  this.g.resetAnimation();
289
306
  this.b.resetAnimation();
@@ -291,8 +308,12 @@ export default class AnimatedColor extends AnimatedWithChildren {
291
308
  callback && callback(this.__getValue());
292
309
  }
293
310
 
294
- __getValue(): string {
295
- return `rgba(${this.r.__getValue()}, ${this.g.__getValue()}, ${this.b.__getValue()}, ${this.a.__getValue()})`;
311
+ __getValue(): ColorValue {
312
+ if (this.nativeColor != null) {
313
+ return this.nativeColor;
314
+ } else {
315
+ return `rgba(${this.r.__getValue()}, ${this.g.__getValue()}, ${this.b.__getValue()}, ${this.a.__getValue()})`;
316
+ }
296
317
  }
297
318
 
298
319
  __attach(): void {
@@ -38,7 +38,9 @@ class AnimatedDiffClamp extends AnimatedWithChildren {
38
38
  super.__makeNative(platformConfig);
39
39
  }
40
40
 
41
- interpolate(config: InterpolationConfigType): AnimatedInterpolation {
41
+ interpolate<OutputT: number | string>(
42
+ config: InterpolationConfigType<OutputT>,
43
+ ): AnimatedInterpolation<OutputT> {
42
44
  return new AnimatedInterpolation(this, config);
43
45
  }
44
46
 
@@ -54,7 +54,9 @@ class AnimatedDivision extends AnimatedWithChildren {
54
54
  return a / b;
55
55
  }
56
56
 
57
- interpolate(config: InterpolationConfigType): AnimatedInterpolation {
57
+ interpolate<OutputT: number | string>(
58
+ config: InterpolationConfigType<OutputT>,
59
+ ): AnimatedInterpolation<OutputT> {
58
60
  return new AnimatedInterpolation(this, config);
59
61
  }
60
62
 
@@ -23,9 +23,9 @@ import type {PlatformConfig} from '../AnimatedPlatformConfig';
23
23
 
24
24
  type ExtrapolateType = 'extend' | 'identity' | 'clamp';
25
25
 
26
- export type InterpolationConfigType = $ReadOnly<{
26
+ export type InterpolationConfigType<OutputT: number | string> = $ReadOnly<{
27
27
  inputRange: $ReadOnlyArray<number>,
28
- outputRange: $ReadOnlyArray<number> | $ReadOnlyArray<string>,
28
+ outputRange: $ReadOnlyArray<OutputT>,
29
29
  easing?: (input: number) => number,
30
30
  extrapolate?: ExtrapolateType,
31
31
  extrapolateLeft?: ExtrapolateType,
@@ -38,14 +38,14 @@ const linear = (t: number) => t;
38
38
  * Very handy helper to map input ranges to output ranges with an easing
39
39
  * function and custom behavior outside of the ranges.
40
40
  */
41
- function createInterpolation(
42
- config: InterpolationConfigType,
43
- ): (input: number) => number | string {
41
+ function createInterpolation<OutputT: number | string>(
42
+ config: InterpolationConfigType<OutputT>,
43
+ ): (input: number) => OutputT {
44
44
  if (config.outputRange && typeof config.outputRange[0] === 'string') {
45
- return createInterpolationFromStringOutputRange(config);
45
+ return (createInterpolationFromStringOutputRange((config: any)): any);
46
46
  }
47
47
 
48
- const outputRange: Array<number> = (config.outputRange: any);
48
+ const outputRange: $ReadOnlyArray<number> = (config.outputRange: any);
49
49
 
50
50
  const inputRange = config.inputRange;
51
51
 
@@ -87,7 +87,7 @@ function createInterpolation(
87
87
  );
88
88
 
89
89
  const range = findRange(input, inputRange);
90
- return interpolate(
90
+ return (interpolate(
91
91
  input,
92
92
  inputRange[range],
93
93
  inputRange[range + 1],
@@ -96,7 +96,7 @@ function createInterpolation(
96
96
  easing,
97
97
  extrapolateLeft,
98
98
  extrapolateRight,
99
- );
99
+ ): any);
100
100
  };
101
101
  }
102
102
 
@@ -195,7 +195,7 @@ const stringShapeRegex = /[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?/g;
195
195
  * -45deg // values with units
196
196
  */
197
197
  function createInterpolationFromStringOutputRange(
198
- config: InterpolationConfigType,
198
+ config: InterpolationConfigType<string>,
199
199
  ): (input: number) => string {
200
200
  let outputRange: Array<string> = (config.outputRange: any);
201
201
  invariant(outputRange.length >= 2, 'Bad output range');
@@ -299,17 +299,19 @@ function checkInfiniteRange(name: string, arr: $ReadOnlyArray<number>) {
299
299
  );
300
300
  }
301
301
 
302
- class AnimatedInterpolation extends AnimatedWithChildren {
302
+ class AnimatedInterpolation<
303
+ OutputT: number | string,
304
+ > extends AnimatedWithChildren {
303
305
  // Export for testing.
304
306
  static __createInterpolation: (
305
- config: InterpolationConfigType,
306
- ) => (input: number) => number | string = createInterpolation;
307
+ config: InterpolationConfigType<OutputT>,
308
+ ) => (input: number) => OutputT = createInterpolation;
307
309
 
308
310
  _parent: AnimatedNode;
309
- _config: InterpolationConfigType;
310
- _interpolation: (input: number) => number | string;
311
+ _config: InterpolationConfigType<OutputT>;
312
+ _interpolation: (input: number) => OutputT;
311
313
 
312
- constructor(parent: AnimatedNode, config: InterpolationConfigType) {
314
+ constructor(parent: AnimatedNode, config: InterpolationConfigType<OutputT>) {
313
315
  super();
314
316
  this._parent = parent;
315
317
  this._config = config;
@@ -330,7 +332,9 @@ class AnimatedInterpolation extends AnimatedWithChildren {
330
332
  return this._interpolation(parentValue);
331
333
  }
332
334
 
333
- interpolate(config: InterpolationConfigType): AnimatedInterpolation {
335
+ interpolate<NewOutputT: number | string>(
336
+ config: InterpolationConfigType<NewOutputT>,
337
+ ): AnimatedInterpolation<NewOutputT> {
334
338
  return new AnimatedInterpolation(this, config);
335
339
  }
336
340
 
@@ -343,7 +347,7 @@ class AnimatedInterpolation extends AnimatedWithChildren {
343
347
  super.__detach();
344
348
  }
345
349
 
346
- __transformDataType(range: Array<any>): Array<any> {
350
+ __transformDataType(range: $ReadOnlyArray<OutputT>): Array<any> {
347
351
  return range.map(NativeAnimatedHelper.transformDataType);
348
352
  }
349
353
 
@@ -355,9 +359,6 @@ class AnimatedInterpolation extends AnimatedWithChildren {
355
359
  return {
356
360
  inputRange: this._config.inputRange,
357
361
  // Only the `outputRange` can contain strings so we don't need to transform `inputRange` here
358
- /* $FlowFixMe[incompatible-call] (>=0.38.0) - Flow error detected during
359
- * the deployment of v0.38.0. To see the error, remove this comment and
360
- * run flow */
361
362
  outputRange: this.__transformDataType(this._config.outputRange),
362
363
  extrapolateLeft:
363
364
  this._config.extrapolateLeft || this._config.extrapolate || 'extend',
@@ -38,7 +38,9 @@ class AnimatedModulo extends AnimatedWithChildren {
38
38
  );
39
39
  }
40
40
 
41
- interpolate(config: InterpolationConfigType): AnimatedInterpolation {
41
+ interpolate<OutputT: number | string>(
42
+ config: InterpolationConfigType<OutputT>,
43
+ ): AnimatedInterpolation<OutputT> {
42
44
  return new AnimatedInterpolation(this, config);
43
45
  }
44
46
 
@@ -38,10 +38,11 @@ class AnimatedMultiplication extends AnimatedWithChildren {
38
38
  return this._a.__getValue() * this._b.__getValue();
39
39
  }
40
40
 
41
- interpolate(config: InterpolationConfigType): AnimatedInterpolation {
41
+ interpolate<OutputT: number | string>(
42
+ config: InterpolationConfigType<OutputT>,
43
+ ): AnimatedInterpolation<OutputT> {
42
44
  return new AnimatedInterpolation(this, config);
43
45
  }
44
-
45
46
  __attach(): void {
46
47
  this._a.__addChild(this);
47
48
  this._b.__addChild(this);
@@ -10,16 +10,15 @@
10
10
 
11
11
  'use strict';
12
12
 
13
+ import type {PlatformConfig} from '../AnimatedPlatformConfig';
14
+
15
+ const ReactNative = require('../../Renderer/shims/ReactNative');
13
16
  const {AnimatedEvent} = require('../AnimatedEvent');
17
+ const NativeAnimatedHelper = require('../NativeAnimatedHelper');
14
18
  const AnimatedNode = require('./AnimatedNode');
15
19
  const AnimatedStyle = require('./AnimatedStyle');
16
- const NativeAnimatedHelper = require('../NativeAnimatedHelper');
17
- const ReactNative = require('../../Renderer/shims/ReactNative');
18
-
19
20
  const invariant = require('invariant');
20
21
 
21
- import type {PlatformConfig} from '../AnimatedPlatformConfig';
22
-
23
22
  class AnimatedProps extends AnimatedNode {
24
23
  _props: Object;
25
24
  _animatedView: any;
@@ -37,15 +36,23 @@ class AnimatedProps extends AnimatedNode {
37
36
  this._callback = callback;
38
37
  }
39
38
 
40
- __getValue(): Object {
41
- const props = {};
39
+ __getValue(initialProps: ?Object): Object {
40
+ const props: {[string]: any | ((...args: any) => void)} = {};
42
41
  for (const key in this._props) {
43
42
  const value = this._props[key];
44
43
  if (value instanceof AnimatedNode) {
45
- if (!value.__isNative || value instanceof AnimatedStyle) {
46
- // We cannot use value of natively driven nodes this way as the value we have access from
47
- // JS may not be up to date.
44
+ // During initial render we want to use the initial value of both natively and non-natively
45
+ // driven nodes. On subsequent renders, we cannot use the value of natively driven nodes
46
+ // as they may not be up to date, so we use the initial value to ensure that values of
47
+ // native animated nodes do not impact rerenders.
48
+ if (value instanceof AnimatedStyle) {
49
+ props[key] = value.__getValue(
50
+ initialProps ? initialProps.style : null,
51
+ );
52
+ } else if (!initialProps || !value.__isNative) {
48
53
  props[key] = value.__getValue();
54
+ } else if (initialProps.hasOwnProperty(key)) {
55
+ props[key] = initialProps[key];
49
56
  }
50
57
  } else if (value instanceof AnimatedEvent) {
51
58
  props[key] = value.__getHandler();
@@ -53,11 +60,12 @@ class AnimatedProps extends AnimatedNode {
53
60
  props[key] = value;
54
61
  }
55
62
  }
63
+
56
64
  return props;
57
65
  }
58
66
 
59
67
  __getAnimatedValue(): Object {
60
- const props = {};
68
+ const props: {[string]: any} = {};
61
69
  for (const key in this._props) {
62
70
  const value = this._props[key];
63
71
  if (value instanceof AnimatedNode) {
@@ -165,7 +173,7 @@ class AnimatedProps extends AnimatedNode {
165
173
  }
166
174
 
167
175
  __getNativeConfig(): Object {
168
- const propsConfig = {};
176
+ const propsConfig: {[string]: number} = {};
169
177
  for (const propKey in this._props) {
170
178
  const value = this._props[propKey];
171
179
  if (value instanceof AnimatedNode) {
@@ -10,21 +10,20 @@
10
10
 
11
11
  'use strict';
12
12
 
13
+ import type {PlatformConfig} from '../AnimatedPlatformConfig';
14
+
15
+ const flattenStyle = require('../../StyleSheet/flattenStyle');
16
+ const NativeAnimatedHelper = require('../NativeAnimatedHelper');
13
17
  const AnimatedNode = require('./AnimatedNode');
14
18
  const AnimatedTransform = require('./AnimatedTransform');
15
19
  const AnimatedWithChildren = require('./AnimatedWithChildren');
16
- const NativeAnimatedHelper = require('../NativeAnimatedHelper');
17
-
18
- const flattenStyle = require('../../StyleSheet/flattenStyle');
19
-
20
- import type {PlatformConfig} from '../AnimatedPlatformConfig';
21
20
 
22
21
  class AnimatedStyle extends AnimatedWithChildren {
23
22
  _style: Object;
24
23
 
25
24
  constructor(style: any) {
26
25
  super();
27
- style = flattenStyle(style) || {};
26
+ style = flattenStyle(style) || ({}: {[string]: any});
28
27
  if (style.transform) {
29
28
  style = {
30
29
  ...style,
@@ -35,19 +34,23 @@ class AnimatedStyle extends AnimatedWithChildren {
35
34
  }
36
35
 
37
36
  // Recursively get values for nested styles (like iOS's shadowOffset)
38
- _walkStyleAndGetValues(style: any) {
39
- const updatedStyle = {};
37
+ _walkStyleAndGetValues(style: any, initialStyle: ?Object) {
38
+ const updatedStyle: {[string]: any | {...}} = {};
40
39
  for (const key in style) {
41
40
  const value = style[key];
42
41
  if (value instanceof AnimatedNode) {
43
- if (!value.__isNative) {
44
- // We cannot use value of natively driven nodes this way as the value we have access from
45
- // JS may not be up to date.
42
+ // During initial render we want to use the initial value of both natively and non-natively
43
+ // driven nodes. On subsequent renders, we cannot use the value of natively driven nodes
44
+ // as they may not be up to date, so we use the initial value to ensure that values of
45
+ // native animated nodes do not impact rerenders.
46
+ if (!initialStyle || !value.__isNative) {
46
47
  updatedStyle[key] = value.__getValue();
48
+ } else if (initialStyle.hasOwnProperty(key)) {
49
+ updatedStyle[key] = initialStyle[key];
47
50
  }
48
51
  } else if (value && !Array.isArray(value) && typeof value === 'object') {
49
52
  // Support animating nested values (for example: shadowOffset.height)
50
- updatedStyle[key] = this._walkStyleAndGetValues(value);
53
+ updatedStyle[key] = this._walkStyleAndGetValues(value, initialStyle);
51
54
  } else {
52
55
  updatedStyle[key] = value;
53
56
  }
@@ -55,13 +58,13 @@ class AnimatedStyle extends AnimatedWithChildren {
55
58
  return updatedStyle;
56
59
  }
57
60
 
58
- __getValue(): Object {
59
- return this._walkStyleAndGetValues(this._style);
61
+ __getValue(initialStyle: ?Object): Object {
62
+ return this._walkStyleAndGetValues(this._style, initialStyle);
60
63
  }
61
64
 
62
65
  // Recursively get animated values for nested styles (like iOS's shadowOffset)
63
66
  _walkStyleAndGetAnimatedValues(style: any) {
64
- const updatedStyle = {};
67
+ const updatedStyle: {[string]: any | {...}} = {};
65
68
  for (const key in style) {
66
69
  const value = style[key];
67
70
  if (value instanceof AnimatedNode) {
@@ -108,7 +111,7 @@ class AnimatedStyle extends AnimatedWithChildren {
108
111
  }
109
112
 
110
113
  __getNativeConfig(): Object {
111
- const styleConfig = {};
114
+ const styleConfig: {[string]: ?number} = {};
112
115
  for (const styleKey in this._style) {
113
116
  if (this._style[styleKey] instanceof AnimatedNode) {
114
117
  const style = this._style[styleKey];
@@ -38,7 +38,9 @@ class AnimatedSubtraction extends AnimatedWithChildren {
38
38
  return this._a.__getValue() - this._b.__getValue();
39
39
  }
40
40
 
41
- interpolate(config: InterpolationConfigType): AnimatedInterpolation {
41
+ interpolate<OutputT: number | string>(
42
+ config: InterpolationConfigType<OutputT>,
43
+ ): AnimatedInterpolation<OutputT> {
42
44
  return new AnimatedInterpolation(this, config);
43
45
  }
44
46
 
@@ -10,11 +10,11 @@
10
10
 
11
11
  'use strict';
12
12
 
13
+ import type {PlatformConfig} from '../AnimatedPlatformConfig';
14
+
15
+ const NativeAnimatedHelper = require('../NativeAnimatedHelper');
13
16
  const AnimatedNode = require('./AnimatedNode');
14
17
  const AnimatedWithChildren = require('./AnimatedWithChildren');
15
- const NativeAnimatedHelper = require('../NativeAnimatedHelper');
16
-
17
- import type {PlatformConfig} from '../AnimatedPlatformConfig';
18
18
 
19
19
  class AnimatedTransform extends AnimatedWithChildren {
20
20
  _transforms: $ReadOnlyArray<Object>;
@@ -38,7 +38,7 @@ class AnimatedTransform extends AnimatedWithChildren {
38
38
 
39
39
  __getValue(): $ReadOnlyArray<Object> {
40
40
  return this._transforms.map(transform => {
41
- const result = {};
41
+ const result: {[string]: any} = {};
42
42
  for (const key in transform) {
43
43
  const value = transform[key];
44
44
  if (value instanceof AnimatedNode) {
@@ -53,7 +53,7 @@ class AnimatedTransform extends AnimatedWithChildren {
53
53
 
54
54
  __getAnimatedValue(): $ReadOnlyArray<Object> {
55
55
  return this._transforms.map(transform => {
56
- const result = {};
56
+ const result: {[string]: any} = {};
57
57
  for (const key in transform) {
58
58
  const value = transform[key];
59
59
  if (value instanceof AnimatedNode) {
@@ -20,6 +20,10 @@ import type Animation, {EndCallback} from '../animations/Animation';
20
20
  import type {InterpolationConfigType} from './AnimatedInterpolation';
21
21
  import type AnimatedTracking from './AnimatedTracking';
22
22
 
23
+ export type AnimatedValueConfig = $ReadOnly<{
24
+ useNativeDriver: boolean,
25
+ }>;
26
+
23
27
  const NativeAnimatedAPI = NativeAnimatedHelper.API;
24
28
 
25
29
  /**
@@ -87,7 +91,7 @@ class AnimatedValue extends AnimatedWithChildren {
87
91
  _animation: ?Animation;
88
92
  _tracking: ?AnimatedTracking;
89
93
 
90
- constructor(value: number) {
94
+ constructor(value: number, config?: ?AnimatedValueConfig) {
91
95
  super();
92
96
  if (typeof value !== 'number') {
93
97
  throw new Error('AnimatedValue: Attempting to set value to undefined');
@@ -95,6 +99,9 @@ class AnimatedValue extends AnimatedWithChildren {
95
99
  this._startingValue = this._value = value;
96
100
  this._offset = 0;
97
101
  this._animation = null;
102
+ if (config && config.useNativeDriver) {
103
+ this.__makeNative();
104
+ }
98
105
  }
99
106
 
100
107
  __detach() {
@@ -127,9 +134,9 @@ class AnimatedValue extends AnimatedWithChildren {
127
134
  !this.__isNative /* don't perform a flush for natively driven values */,
128
135
  );
129
136
  if (this.__isNative) {
130
- _executeAsAnimatedBatch(this.__getNativeTag().toString(), () => {
131
- NativeAnimatedAPI.setAnimatedNodeValue(this.__getNativeTag(), value);
132
- });
137
+ _executeAsAnimatedBatch(this.__getNativeTag().toString(), () =>
138
+ NativeAnimatedAPI.setAnimatedNodeValue(this.__getNativeTag(), value),
139
+ );
133
140
  }
134
141
  }
135
142
 
@@ -219,7 +226,9 @@ class AnimatedValue extends AnimatedWithChildren {
219
226
  * Interpolates the value before updating the property, e.g. mapping 0-1 to
220
227
  * 0-10.
221
228
  */
222
- interpolate(config: InterpolationConfigType): AnimatedInterpolation {
229
+ interpolate<OutputT: number | string>(
230
+ config: InterpolationConfigType<OutputT>,
231
+ ): AnimatedInterpolation<OutputT> {
223
232
  return new AnimatedInterpolation(this, config);
224
233
  }
225
234