@office-iss/react-native-win32 0.70.2 → 0.71.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 (559) hide show
  1. package/.eslintignore +1 -0
  2. package/.eslintrc.js +2 -0
  3. package/.flowconfig +3 -6
  4. package/CHANGELOG.json +281 -43
  5. package/CHANGELOG.md +105 -24
  6. package/IntegrationTests/AccessibilityManagerTest.js +1 -1
  7. package/IntegrationTests/AppEventsTest.js +0 -1
  8. package/IntegrationTests/BUCK +0 -1
  9. package/IntegrationTests/GlobalEvalWithSourceUrlTest.js +1 -1
  10. package/IntegrationTests/ImageSnapshotTest.js +1 -1
  11. package/IntegrationTests/IntegrationTestsApp.js +2 -3
  12. package/IntegrationTests/SimpleSnapshotTest.js +1 -1
  13. package/IntegrationTests/SyncMethodTest.js +1 -1
  14. package/IntegrationTests/TimersTest.js +4 -4
  15. package/IntegrationTests/WebSocketTest.js +3 -3
  16. package/Libraries/ActionSheetIOS/ActionSheetIOS.d.ts +80 -0
  17. package/Libraries/ActionSheetIOS/ActionSheetIOS.js +4 -3
  18. package/Libraries/ActionSheetIOS/NativeActionSheetManager.js +1 -0
  19. package/Libraries/Alert/Alert.d.ts +90 -0
  20. package/Libraries/Alert/Alert.js +7 -1
  21. package/Libraries/Alert/Alert.win32.js +1 -0
  22. package/Libraries/Alert/NativeAlertManager.js +2 -0
  23. package/Libraries/Alert/RCTAlertManager.ios.js +2 -1
  24. package/Libraries/Animated/Animated.d.ts +587 -0
  25. package/Libraries/Animated/Animated.js +13 -11
  26. package/Libraries/Animated/AnimatedEvent.js +12 -17
  27. package/Libraries/Animated/AnimatedImplementation.js +21 -23
  28. package/Libraries/Animated/AnimatedMock.js +11 -13
  29. package/Libraries/Animated/AnimatedWeb.js +2 -2
  30. package/Libraries/Animated/Easing.d.ts +37 -0
  31. package/Libraries/Animated/Easing.js +2 -2
  32. package/Libraries/Animated/NativeAnimatedHelper.js +32 -22
  33. package/Libraries/Animated/NativeAnimatedModule.js +1 -0
  34. package/Libraries/Animated/NativeAnimatedTurboModule.js +1 -0
  35. package/Libraries/Animated/SpringConfig.js +2 -7
  36. package/Libraries/Animated/animations/Animation.js +3 -4
  37. package/Libraries/Animated/animations/DecayAnimation.js +5 -8
  38. package/Libraries/Animated/animations/SpringAnimation.js +9 -14
  39. package/Libraries/Animated/animations/TimingAnimation.js +9 -13
  40. package/Libraries/Animated/bezier.js +2 -2
  41. package/Libraries/Animated/components/AnimatedFlatList.js +5 -6
  42. package/Libraries/Animated/components/AnimatedImage.js +5 -6
  43. package/Libraries/Animated/components/AnimatedScrollView.js +110 -14
  44. package/Libraries/Animated/components/AnimatedSectionList.js +4 -5
  45. package/Libraries/Animated/components/AnimatedText.js +5 -6
  46. package/Libraries/Animated/components/AnimatedView.js +5 -6
  47. package/Libraries/Animated/createAnimatedComponent.js +13 -20
  48. package/Libraries/Animated/createAnimatedComponent_EXPERIMENTAL.js +2 -2
  49. package/Libraries/Animated/nodes/AnimatedAddition.js +6 -8
  50. package/Libraries/Animated/nodes/AnimatedColor.js +7 -7
  51. package/Libraries/Animated/nodes/AnimatedDiffClamp.js +6 -8
  52. package/Libraries/Animated/nodes/AnimatedDivision.js +7 -9
  53. package/Libraries/Animated/nodes/AnimatedInterpolation.js +7 -10
  54. package/Libraries/Animated/nodes/AnimatedModulo.js +6 -8
  55. package/Libraries/Animated/nodes/AnimatedMultiplication.js +7 -9
  56. package/Libraries/Animated/nodes/AnimatedNode.js +10 -8
  57. package/Libraries/Animated/nodes/AnimatedProps.js +12 -30
  58. package/Libraries/Animated/nodes/AnimatedStyle.js +12 -22
  59. package/Libraries/Animated/nodes/AnimatedSubtraction.js +7 -9
  60. package/Libraries/Animated/nodes/AnimatedTracking.js +8 -12
  61. package/Libraries/Animated/nodes/AnimatedTransform.js +38 -31
  62. package/Libraries/Animated/nodes/AnimatedValue.js +9 -10
  63. package/Libraries/Animated/nodes/AnimatedValueXY.js +4 -7
  64. package/Libraries/Animated/nodes/AnimatedWithChildren.js +4 -5
  65. package/Libraries/Animated/useAnimatedProps.js +8 -16
  66. package/Libraries/Animated/useAnimatedValue.d.ts +15 -0
  67. package/Libraries/Animated/useAnimatedValue.js +25 -0
  68. package/Libraries/AppState/AppState.d.ts +58 -0
  69. package/Libraries/AppState/AppState.js +3 -7
  70. package/Libraries/AppState/NativeAppState.js +1 -0
  71. package/Libraries/BatchedBridge/MessageQueue.js +9 -5
  72. package/Libraries/BatchedBridge/NativeModules.d.ts +25 -0
  73. package/Libraries/BatchedBridge/NativeModules.js +1 -0
  74. package/Libraries/Blob/BlobManager.js +5 -3
  75. package/Libraries/Blob/File.js +2 -3
  76. package/Libraries/Blob/FileReader.js +6 -5
  77. package/Libraries/Blob/NativeBlobModule.js +1 -0
  78. package/Libraries/Blob/NativeFileReaderModule.js +1 -0
  79. package/Libraries/Blob/URL.js +11 -9
  80. package/Libraries/BugReporting/NativeBugReporting.js +1 -0
  81. package/Libraries/BugReporting/getReactData.js +1 -1
  82. package/Libraries/Components/AccessibilityInfo/AccessibilityInfo.d.ts +128 -0
  83. package/Libraries/Components/AccessibilityInfo/AccessibilityInfo.flow.js +208 -0
  84. package/Libraries/Components/AccessibilityInfo/AccessibilityInfo.js +40 -8
  85. package/Libraries/Components/AccessibilityInfo/AccessibilityInfo.win32.js +40 -8
  86. package/Libraries/Components/AccessibilityInfo/NativeAccessibilityInfo.js +1 -0
  87. package/Libraries/Components/AccessibilityInfo/NativeAccessibilityManager.js +5 -0
  88. package/Libraries/Components/ActivityIndicator/ActivityIndicator.d.ts +86 -0
  89. package/Libraries/Components/ActivityIndicator/ActivityIndicator.flow.js +58 -0
  90. package/Libraries/Components/ActivityIndicator/ActivityIndicator.js +7 -8
  91. package/Libraries/Components/ActivityIndicator/ActivityIndicatorViewNativeComponent.js +2 -3
  92. package/Libraries/Components/Button.d.ts +42 -0
  93. package/Libraries/Components/Button.flow.js +265 -0
  94. package/Libraries/Components/Button.js +62 -18
  95. package/Libraries/Components/Clipboard/Clipboard.d.ts +28 -0
  96. package/Libraries/Components/Clipboard/NativeClipboard.js +1 -0
  97. package/Libraries/Components/DatePicker/DatePickerIOS.android.js +4 -2
  98. package/Libraries/Components/DatePicker/DatePickerIOS.d.ts +92 -0
  99. package/Libraries/Components/{MaskedView/MaskedViewIOS.android.js → DatePicker/DatePickerIOS.flow.android.js} +3 -2
  100. package/Libraries/Components/DatePicker/DatePickerIOS.flow.ios.js +113 -0
  101. package/Libraries/Components/DatePicker/DatePickerIOS.ios.js +8 -7
  102. package/Libraries/Components/DatePicker/DatePickerIOS.win32.js +4 -2
  103. package/Libraries/Components/DatePicker/RCTDatePickerNativeComponent.js +7 -6
  104. package/Libraries/Components/DatePickerAndroid/NativeDatePickerAndroid.js +1 -0
  105. package/Libraries/Components/DrawerAndroid/AndroidDrawerLayoutNativeComponent.js +9 -8
  106. package/Libraries/Components/DrawerAndroid/DrawerLayoutAndroid.android.js +13 -14
  107. package/Libraries/Components/DrawerAndroid/DrawerLayoutAndroid.d.ts +141 -0
  108. package/Libraries/Components/Keyboard/Keyboard.d.ts +109 -0
  109. package/Libraries/Components/Keyboard/Keyboard.js +35 -8
  110. package/Libraries/Components/Keyboard/KeyboardAvoidingView.d.ts +46 -0
  111. package/Libraries/Components/Keyboard/KeyboardAvoidingView.js +35 -15
  112. package/Libraries/Components/Keyboard/NativeKeyboardObserver.js +1 -0
  113. package/Libraries/Components/Pressable/Pressable.d.ts +167 -0
  114. package/Libraries/Components/Pressable/Pressable.js +73 -15
  115. package/Libraries/Components/Pressable/Pressable.win32.js +77 -19
  116. package/Libraries/Components/Pressable/useAndroidRippleForView.js +6 -3
  117. package/Libraries/Components/ProgressBarAndroid/ProgressBarAndroid.android.js +3 -3
  118. package/Libraries/Components/ProgressBarAndroid/ProgressBarAndroid.d.ts +83 -0
  119. package/Libraries/Components/ProgressBarAndroid/ProgressBarAndroidNativeComponent.js +2 -2
  120. package/Libraries/Components/ProgressViewIOS/ProgressViewIOS.android.js +1 -1
  121. package/Libraries/Components/ProgressViewIOS/ProgressViewIOS.d.ts +62 -0
  122. package/Libraries/Components/ProgressViewIOS/ProgressViewIOS.ios.js +4 -4
  123. package/Libraries/Components/ProgressViewIOS/ProgressViewIOS.win32.js +1 -1
  124. package/Libraries/Components/ProgressViewIOS/RCTProgressViewNativeComponent.js +2 -2
  125. package/Libraries/Components/RefreshControl/AndroidSwipeRefreshLayoutNativeComponent.js +5 -6
  126. package/Libraries/Components/RefreshControl/PullToRefreshViewNativeComponent.js +4 -4
  127. package/Libraries/Components/RefreshControl/RefreshControl.d.ts +87 -0
  128. package/Libraries/Components/RefreshControl/RefreshControl.js +4 -3
  129. package/Libraries/Components/RefreshControl/__mocks__/RefreshControlMock.js +2 -3
  130. package/Libraries/Components/SafeAreaView/RCTSafeAreaViewNativeComponent.js +1 -1
  131. package/Libraries/Components/SafeAreaView/SafeAreaView.d.ts +24 -0
  132. package/Libraries/Components/SafeAreaView/SafeAreaView.flow.js +19 -0
  133. package/Libraries/Components/SafeAreaView/SafeAreaView.js +5 -4
  134. package/Libraries/Components/SafeAreaView/SafeAreaView.win32.js +5 -4
  135. package/Libraries/Components/ScrollView/AndroidHorizontalScrollContentViewNativeComponent.js +2 -1
  136. package/Libraries/Components/ScrollView/AndroidHorizontalScrollViewNativeComponent.js +2 -1
  137. package/Libraries/Components/ScrollView/ScrollContentViewNativeComponent.js +2 -1
  138. package/Libraries/Components/ScrollView/ScrollView.d.ts +911 -0
  139. package/Libraries/Components/ScrollView/ScrollView.js +87 -52
  140. package/Libraries/Components/ScrollView/ScrollViewCommands.js +3 -3
  141. package/Libraries/Components/ScrollView/ScrollViewNativeComponent.js +2 -1
  142. package/Libraries/Components/ScrollView/ScrollViewNativeComponentType.js +3 -3
  143. package/Libraries/Components/ScrollView/ScrollViewStickyHeader.js +243 -269
  144. package/Libraries/Components/Slider/Slider.d.ts +132 -0
  145. package/Libraries/Components/Slider/Slider.js +9 -9
  146. package/Libraries/Components/Slider/SliderNativeComponent.js +4 -5
  147. package/Libraries/Components/Sound/NativeSoundManager.js +1 -0
  148. package/Libraries/Components/StatusBar/NativeStatusBarManagerAndroid.js +1 -0
  149. package/Libraries/Components/StatusBar/NativeStatusBarManagerIOS.js +1 -0
  150. package/Libraries/Components/StatusBar/StatusBar.d.ts +138 -0
  151. package/Libraries/Components/StatusBar/StatusBar.js +7 -7
  152. package/Libraries/Components/Switch/AndroidSwitchNativeComponent.js +10 -10
  153. package/Libraries/Components/Switch/Switch.d.ts +115 -0
  154. package/Libraries/Components/Switch/Switch.js +7 -7
  155. package/Libraries/Components/Switch/SwitchNativeComponent.js +9 -4
  156. package/Libraries/Components/TextInput/AndroidTextInputNativeComponent.js +40 -12
  157. package/Libraries/Components/TextInput/InputAccessoryView.d.ts +34 -0
  158. package/Libraries/Components/TextInput/InputAccessoryView.js +3 -4
  159. package/Libraries/Components/TextInput/RCTInputAccessoryViewNativeComponent.js +1 -1
  160. package/Libraries/Components/TextInput/RCTMultilineTextInputNativeComponent.js +3 -2
  161. package/Libraries/Components/TextInput/RCTSingelineTextInputNativeComponent.js +3 -2
  162. package/Libraries/Components/TextInput/RCTTextInputViewConfig.js +3 -1
  163. package/Libraries/Components/TextInput/TextInput.d.ts +840 -0
  164. package/Libraries/Components/TextInput/TextInput.flow.js +1057 -0
  165. package/Libraries/Components/TextInput/TextInput.js +344 -38
  166. package/Libraries/Components/TextInput/TextInput.win32.d.ts +1 -1
  167. package/Libraries/Components/TextInput/TextInput.win32.js +1 -1
  168. package/Libraries/Components/TextInput/TextInput.win32.js.map +1 -1
  169. package/Libraries/Components/TextInput/TextInputNativeCommands.js +2 -2
  170. package/Libraries/Components/TextInput/TextInputState.js +22 -5
  171. package/Libraries/Components/TextInput/TextInputState.win32.js +24 -5
  172. package/Libraries/Components/ToastAndroid/NativeToastAndroid.js +1 -0
  173. package/Libraries/Components/ToastAndroid/ToastAndroid.d.ts +47 -0
  174. package/Libraries/Components/Touchable/Tests/TouchableWin32Test.js.map +1 -1
  175. package/Libraries/Components/Touchable/Touchable.d.ts +90 -0
  176. package/Libraries/Components/Touchable/Touchable.flow.js +258 -0
  177. package/Libraries/Components/Touchable/Touchable.js +12 -12
  178. package/Libraries/Components/Touchable/Touchable.win32.js +12 -12
  179. package/Libraries/Components/Touchable/TouchableBounce.js +44 -10
  180. package/Libraries/Components/Touchable/TouchableHighlight.d.ts +68 -0
  181. package/Libraries/Components/Touchable/TouchableHighlight.js +32 -9
  182. package/Libraries/Components/Touchable/TouchableNativeFeedback.d.ts +114 -0
  183. package/Libraries/Components/Touchable/TouchableNativeFeedback.js +54 -20
  184. package/Libraries/Components/Touchable/TouchableOpacity.d.ts +109 -0
  185. package/Libraries/Components/Touchable/TouchableOpacity.js +54 -16
  186. package/Libraries/Components/Touchable/TouchableWin32.Props.d.ts +2 -1
  187. package/Libraries/Components/Touchable/TouchableWin32.Props.js.map +1 -1
  188. package/Libraries/Components/Touchable/TouchableWin32.js +0 -1
  189. package/Libraries/Components/Touchable/TouchableWin32.js.map +1 -1
  190. package/Libraries/Components/Touchable/TouchableWithoutFeedback.d.ts +143 -0
  191. package/Libraries/Components/Touchable/TouchableWithoutFeedback.js +64 -10
  192. package/Libraries/Components/UnimplementedViews/UnimplementedNativeViewNativeComponent.js +1 -1
  193. package/Libraries/Components/UnimplementedViews/UnimplementedView.js +1 -1
  194. package/Libraries/Components/View/ReactNativeStyleAttributes.js +13 -2
  195. package/Libraries/Components/View/ReactNativeViewAttributes.win32.js +1 -0
  196. package/Libraries/Components/View/View.d.ts +29 -0
  197. package/Libraries/Components/View/View.js +91 -8
  198. package/Libraries/Components/View/View.win32.js +176 -89
  199. package/Libraries/Components/View/ViewAccessibility.d.ts +360 -0
  200. package/Libraries/Components/View/ViewAccessibility.js +70 -1
  201. package/Libraries/Components/View/ViewNativeComponent.js +3 -3
  202. package/Libraries/Components/View/ViewPropTypes.d.ts +245 -0
  203. package/Libraries/Components/View/ViewPropTypes.js +105 -13
  204. package/Libraries/Components/View/ViewPropTypes.win32.js +105 -13
  205. package/Libraries/Components/View/ViewWin32.Props.d.ts +6 -1
  206. package/Libraries/Components/View/ViewWin32.Props.js.map +1 -1
  207. package/Libraries/Core/Devtools/openFileInEditor.js +3 -0
  208. package/Libraries/Core/Devtools/parseErrorStack.js +1 -1
  209. package/Libraries/Core/Devtools/symbolicateStackTrace.js +2 -2
  210. package/Libraries/Core/ExceptionsManager.js +8 -0
  211. package/Libraries/Core/ExtendedError.js +11 -8
  212. package/Libraries/Core/InitializeCore.js +2 -1
  213. package/Libraries/Core/NativeExceptionsManager.js +3 -4
  214. package/Libraries/Core/RawEventEmitter.js +2 -1
  215. package/Libraries/Core/ReactFiberErrorDialog.js +2 -2
  216. package/Libraries/Core/ReactNativeVersion.js +2 -2
  217. package/Libraries/Core/ReactNativeVersionCheck.js +1 -0
  218. package/Libraries/Core/ReactNativeVersionCheck.win32.js +1 -0
  219. package/Libraries/Core/SegmentFetcher/NativeSegmentFetcher.js +1 -0
  220. package/Libraries/Core/Timers/JSTimers.js +13 -11
  221. package/Libraries/Core/Timers/NativeTiming.js +1 -0
  222. package/Libraries/Core/setUpBatchedBridge.js +1 -5
  223. package/Libraries/Core/setUpDeveloperTools.js +4 -6
  224. package/Libraries/Core/setUpReactDevTools.js +4 -1
  225. package/Libraries/Core/setUpRegeneratorRuntime.js +1 -1
  226. package/Libraries/Core/setUpTimers.js +1 -1
  227. package/Libraries/EventEmitter/NativeEventEmitter.d.ts +70 -0
  228. package/Libraries/EventEmitter/NativeEventEmitter.js +1 -0
  229. package/Libraries/EventEmitter/RCTDeviceEventEmitter.d.ts +30 -0
  230. package/Libraries/EventEmitter/RCTDeviceEventEmitter.js +2 -1
  231. package/Libraries/EventEmitter/RCTNativeAppEventEmitter.d.ts +32 -0
  232. package/Libraries/EventEmitter/__mocks__/NativeEventEmitter.js +1 -0
  233. package/Libraries/Events/EventPolyfill.js +1 -1
  234. package/Libraries/HeapCapture/NativeJSCHeapCapture.js +1 -0
  235. package/Libraries/Image/AssetSourceResolver.js +4 -6
  236. package/Libraries/Image/Image.android.js +63 -45
  237. package/Libraries/Image/Image.d.ts +322 -0
  238. package/Libraries/Image/Image.flow.js +64 -0
  239. package/Libraries/Image/Image.ios.js +55 -28
  240. package/Libraries/Image/Image.win32.js +54 -25
  241. package/Libraries/Image/ImageBackground.js +18 -7
  242. package/Libraries/Image/ImageInjection.js +2 -1
  243. package/Libraries/Image/ImageProps.js +88 -5
  244. package/Libraries/Image/ImageResizeMode.d.ts +49 -0
  245. package/Libraries/Image/ImageSource.d.ts +76 -0
  246. package/Libraries/Image/ImageSourceUtils.js +80 -0
  247. package/Libraries/Image/ImageUtils.js +21 -0
  248. package/Libraries/Image/ImageViewNativeComponent.js +8 -5
  249. package/Libraries/Image/NativeImageEditor.js +1 -0
  250. package/Libraries/Image/NativeImageLoaderAndroid.js +1 -0
  251. package/Libraries/Image/NativeImageLoaderIOS.js +1 -0
  252. package/Libraries/Image/NativeImageLoaderWin32.js +1 -0
  253. package/Libraries/Image/NativeImageStoreAndroid.js +1 -0
  254. package/Libraries/Image/NativeImageStoreIOS.js +1 -0
  255. package/Libraries/Image/TextInlineImageNativeComponent.js +4 -3
  256. package/Libraries/Image/nativeImageSource.js +2 -2
  257. package/Libraries/Image/resolveAssetSource.js +5 -5
  258. package/Libraries/Inspector/BorderBox.js +1 -1
  259. package/Libraries/Inspector/BoxInspector.js +3 -4
  260. package/Libraries/Inspector/DevtoolsOverlay.js +213 -0
  261. package/Libraries/Inspector/ElementBox.js +4 -5
  262. package/Libraries/Inspector/ElementProperties.js +10 -11
  263. package/Libraries/Inspector/Inspector.js +22 -108
  264. package/Libraries/Inspector/Inspector.win32.js +23 -109
  265. package/Libraries/Inspector/InspectorOverlay.js +5 -5
  266. package/Libraries/Inspector/InspectorOverlay.win32.js +5 -5
  267. package/Libraries/Inspector/InspectorPanel.js +12 -10
  268. package/Libraries/Inspector/NetworkOverlay.js +7 -3
  269. package/Libraries/Inspector/PerformanceOverlay.js +3 -3
  270. package/Libraries/Inspector/StyleInspector.js +2 -2
  271. package/Libraries/Inspector/getInspectorDataForViewAtPoint.js +71 -0
  272. package/Libraries/Interaction/BridgeSpyStallHandler.js +1 -1
  273. package/Libraries/Interaction/InteractionManager.d.ts +74 -0
  274. package/Libraries/Interaction/InteractionManager.js +8 -8
  275. package/Libraries/Interaction/NativeFrameRateLogger.js +1 -0
  276. package/Libraries/Interaction/PanResponder.d.ts +202 -0
  277. package/Libraries/Interaction/PanResponder.flow.js +257 -0
  278. package/Libraries/Interaction/PanResponder.js +4 -3
  279. package/Libraries/JSInspector/JSInspector.js +0 -3
  280. package/Libraries/JSInspector/NetworkAgent.js +3 -3
  281. package/Libraries/LayoutAnimation/LayoutAnimation.d.ts +84 -0
  282. package/Libraries/LayoutAnimation/LayoutAnimation.js +4 -3
  283. package/Libraries/Linking/Linking.d.ts +61 -0
  284. package/Libraries/Linking/Linking.js +3 -2
  285. package/Libraries/Linking/NativeIntentAndroid.js +1 -0
  286. package/Libraries/Linking/NativeLinkingManager.js +1 -0
  287. package/Libraries/Lists/CellRenderMask.js +13 -3
  288. package/Libraries/Lists/ChildListCollection.js +72 -0
  289. package/Libraries/Lists/FillRateHelper.js +28 -17
  290. package/Libraries/Lists/FlatList.d.ts +292 -0
  291. package/Libraries/Lists/FlatList.js +70 -70
  292. package/Libraries/Lists/SectionList.d.ts +300 -0
  293. package/Libraries/Lists/SectionList.js +5 -5
  294. package/Libraries/Lists/SectionListModern.js +6 -6
  295. package/Libraries/Lists/StateSafePureComponent.js +85 -0
  296. package/Libraries/Lists/ViewabilityHelper.js +33 -12
  297. package/Libraries/Lists/VirtualizeUtils.js +17 -13
  298. package/Libraries/Lists/VirtualizedList.d.ts +317 -0
  299. package/Libraries/Lists/VirtualizedList.js +548 -890
  300. package/Libraries/Lists/VirtualizedListCellRenderer.js +259 -0
  301. package/Libraries/Lists/VirtualizedListContext.js +7 -48
  302. package/Libraries/Lists/VirtualizedListProps.js +279 -0
  303. package/Libraries/Lists/VirtualizedSectionList.js +6 -3
  304. package/Libraries/Lists/__flowtests__/SectionList-flowtest.js +1 -1
  305. package/Libraries/LogBox/Data/LogBoxData.js +9 -8
  306. package/Libraries/LogBox/Data/LogBoxLog.js +5 -5
  307. package/Libraries/LogBox/Data/LogBoxSymbolication.js +4 -4
  308. package/Libraries/LogBox/Data/parseLogBoxLog.js +5 -3
  309. package/Libraries/LogBox/LogBox.d.ts +28 -0
  310. package/Libraries/LogBox/LogBox.js +11 -11
  311. package/Libraries/LogBox/LogBoxInspectorContainer.js +5 -3
  312. package/Libraries/LogBox/LogBoxNotificationContainer.js +2 -2
  313. package/Libraries/LogBox/UI/AnsiHighlight.js +5 -3
  314. package/Libraries/LogBox/UI/LogBoxButton.js +6 -5
  315. package/Libraries/LogBox/UI/LogBoxInspector.js +6 -6
  316. package/Libraries/LogBox/UI/LogBoxInspectorCodeFrame.js +9 -8
  317. package/Libraries/LogBox/UI/LogBoxInspectorFooter.js +3 -3
  318. package/Libraries/LogBox/UI/LogBoxInspectorHeader.js +7 -6
  319. package/Libraries/LogBox/UI/LogBoxInspectorHeader.win32.js +6 -5
  320. package/Libraries/LogBox/UI/LogBoxInspectorMessageHeader.js +6 -5
  321. package/Libraries/LogBox/UI/LogBoxInspectorReactFrames.js +7 -6
  322. package/Libraries/LogBox/UI/LogBoxInspectorSection.js +2 -2
  323. package/Libraries/LogBox/UI/LogBoxInspectorSourceMapStatus.js +3 -3
  324. package/Libraries/LogBox/UI/LogBoxInspectorStackFrame.js +5 -5
  325. package/Libraries/LogBox/UI/LogBoxInspectorStackFrame.win32.js +5 -5
  326. package/Libraries/LogBox/UI/LogBoxInspectorStackFrames.js +5 -5
  327. package/Libraries/LogBox/UI/LogBoxMessage.js +3 -3
  328. package/Libraries/LogBox/UI/LogBoxNotification.js +6 -5
  329. package/Libraries/Modal/Modal.d.ts +104 -0
  330. package/Libraries/Modal/Modal.js +14 -14
  331. package/Libraries/Modal/NativeModalManager.js +1 -0
  332. package/Libraries/Modal/RCTModalHostViewNativeComponent.js +3 -3
  333. package/Libraries/NativeComponent/BaseViewConfig.android.js +27 -2
  334. package/Libraries/NativeComponent/BaseViewConfig.ios.js +8 -3
  335. package/Libraries/NativeComponent/BaseViewConfig.win32.js +8 -3
  336. package/Libraries/NativeComponent/NativeComponentRegistry.js +5 -4
  337. package/Libraries/NativeComponent/PlatformBaseViewConfig.js +1 -0
  338. package/Libraries/NativeComponent/StaticViewConfigValidator.js +1 -1
  339. package/Libraries/NativeComponent/ViewConfig.js +1 -0
  340. package/Libraries/NativeModules/specs/NativeAnimationsDebugModule.js +1 -0
  341. package/Libraries/NativeModules/specs/NativeDevMenu.js +1 -0
  342. package/Libraries/NativeModules/specs/NativeDevSettings.js +1 -0
  343. package/Libraries/NativeModules/specs/NativeDeviceEventManager.js +1 -0
  344. package/Libraries/NativeModules/specs/NativeDialogManagerAndroid.js +1 -0
  345. package/Libraries/NativeModules/specs/NativeLogBox.js +3 -2
  346. package/Libraries/NativeModules/specs/NativeRedBox.js +1 -0
  347. package/Libraries/NativeModules/specs/NativeSourceCode.js +1 -0
  348. package/Libraries/Network/NativeNetworkingAndroid.js +1 -0
  349. package/Libraries/Network/NativeNetworkingIOS.js +1 -0
  350. package/Libraries/Network/RCTNetworking.android.js +4 -3
  351. package/Libraries/Network/RCTNetworking.ios.js +3 -2
  352. package/Libraries/Network/RCTNetworking.win32.js +1 -0
  353. package/Libraries/Network/convertRequestBody.js +1 -2
  354. package/Libraries/NewAppScreen/components/DebugInstructions.js +4 -1
  355. package/Libraries/NewAppScreen/components/Header.js +6 -2
  356. package/Libraries/NewAppScreen/components/HermesBadge.js +6 -2
  357. package/Libraries/NewAppScreen/components/LearnMoreLinks.js +8 -9
  358. package/Libraries/NewAppScreen/components/ReloadInstructions.js +4 -1
  359. package/Libraries/NewAppScreen/index.js +1 -1
  360. package/Libraries/Performance/NativeJSCSamplingProfiler.js +1 -0
  361. package/Libraries/Performance/QuickPerformanceLogger.js +34 -10
  362. package/Libraries/Performance/Systrace.d.ts +66 -0
  363. package/Libraries/Performance/Systrace.js +110 -195
  364. package/Libraries/PermissionsAndroid/NativePermissionsAndroid.js +1 -0
  365. package/Libraries/PermissionsAndroid/PermissionsAndroid.d.ts +115 -0
  366. package/Libraries/PermissionsAndroid/PermissionsAndroid.js +5 -4
  367. package/Libraries/Pressability/Pressability.js +12 -10
  368. package/Libraries/Pressability/Pressability.win32.js +9 -7
  369. package/Libraries/Pressability/PressabilityDebug.js +2 -2
  370. package/Libraries/PushNotificationIOS/NativePushNotificationManagerIOS.js +1 -0
  371. package/Libraries/PushNotificationIOS/PushNotificationIOS.d.ts +275 -0
  372. package/Libraries/PushNotificationIOS/PushNotificationIOS.js +19 -14
  373. package/Libraries/ReactNative/AppContainer.js +17 -7
  374. package/Libraries/ReactNative/AppRegistry.d.ts +68 -0
  375. package/Libraries/ReactNative/AppRegistry.js +11 -14
  376. package/Libraries/ReactNative/BridgelessUIManager.js +4 -3
  377. package/Libraries/ReactNative/FabricUIManager.js +3 -3
  378. package/Libraries/ReactNative/I18nManager.d.ts +25 -0
  379. package/Libraries/ReactNative/NativeHeadlessJsTaskSupport.js +1 -0
  380. package/Libraries/ReactNative/NativeI18nManager.js +1 -0
  381. package/Libraries/ReactNative/NativeUIManager.js +1 -0
  382. package/Libraries/ReactNative/PaperUIManager.js +2 -2
  383. package/Libraries/ReactNative/PaperUIManager.win32.js +1 -1
  384. package/Libraries/ReactNative/ReactNativeFeatureFlags.js +9 -0
  385. package/Libraries/ReactNative/RendererImplementation.js +112 -0
  386. package/Libraries/ReactNative/RendererProxy.d.ts +20 -0
  387. package/Libraries/ReactNative/RendererProxy.js +26 -0
  388. package/Libraries/ReactNative/RootTag.js +0 -1
  389. package/Libraries/ReactNative/UIManager.d.ts +157 -0
  390. package/Libraries/ReactNative/UIManager.js +1 -1
  391. package/Libraries/ReactNative/getCachedComponentWithDebugName.js +1 -0
  392. package/Libraries/ReactNative/renderApplication.js +38 -20
  393. package/Libraries/ReactNative/requireNativeComponent.d.ts +23 -0
  394. package/Libraries/ReactNative/requireNativeComponent.js +2 -2
  395. package/Libraries/ReactPrivate/ReactNativePrivateInterface.js +10 -9
  396. package/Libraries/Renderer/implementations/ReactFabric-dev.js +312 -217
  397. package/Libraries/Renderer/implementations/ReactFabric-prod.js +212 -177
  398. package/Libraries/Renderer/implementations/ReactFabric-profiling.js +248 -213
  399. package/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js +311 -218
  400. package/Libraries/Renderer/implementations/ReactNativeRenderer-prod.js +226 -196
  401. package/Libraries/Renderer/implementations/ReactNativeRenderer-profiling.js +262 -232
  402. package/Libraries/Renderer/implementations/ReactNativeRenderer.d.ts +149 -0
  403. package/Libraries/Renderer/shims/ReactFabric.js +2 -2
  404. package/Libraries/Renderer/shims/ReactFeatureFlags.js +2 -2
  405. package/Libraries/Renderer/shims/ReactNative.js +2 -2
  406. package/Libraries/Renderer/shims/ReactNativeTypes.d.ts +141 -0
  407. package/Libraries/Renderer/shims/ReactNativeTypes.js +23 -22
  408. package/Libraries/Renderer/shims/ReactNativeViewConfigRegistry.js +8 -8
  409. package/Libraries/Renderer/shims/createReactNativeComponentClass.js +2 -2
  410. package/Libraries/Settings/NativeSettingsManager.js +1 -0
  411. package/Libraries/Settings/Settings.d.ts +18 -0
  412. package/Libraries/Share/NativeShareModule.js +1 -0
  413. package/Libraries/Share/Share.d.ts +80 -0
  414. package/Libraries/Share/Share.js +7 -5
  415. package/Libraries/StyleSheet/PlatformColorValueTypes.android.js +1 -1
  416. package/Libraries/StyleSheet/PlatformColorValueTypes.d.ts +18 -0
  417. package/Libraries/StyleSheet/PlatformColorValueTypes.ios.js +1 -1
  418. package/Libraries/StyleSheet/PlatformColorValueTypesIOS.d.ts +25 -0
  419. package/Libraries/StyleSheet/PlatformColorValueTypesIOS.ios.js +1 -0
  420. package/Libraries/StyleSheet/StyleSheet.d.ts +156 -0
  421. package/Libraries/StyleSheet/StyleSheet.js +15 -11
  422. package/Libraries/StyleSheet/StyleSheet.win32.js +16 -12
  423. package/Libraries/StyleSheet/StyleSheetTypes.d.ts +332 -0
  424. package/Libraries/StyleSheet/StyleSheetTypes.js +101 -24
  425. package/Libraries/StyleSheet/__flowtests__/StyleSheet-flowtest.js +2 -2
  426. package/Libraries/StyleSheet/normalizeColor.js +3 -3
  427. package/Libraries/StyleSheet/private/_TransformStyle.js +26 -24
  428. package/Libraries/StyleSheet/processAspectRatio.js +53 -0
  429. package/Libraries/StyleSheet/processColor.d.ts +16 -0
  430. package/Libraries/StyleSheet/processColor.js +3 -4
  431. package/Libraries/StyleSheet/processColorArray.js +1 -0
  432. package/Libraries/StyleSheet/processFontVariant.js +30 -0
  433. package/Libraries/StyleSheet/processTransform.js +114 -105
  434. package/Libraries/StyleSheet/splitLayoutProps.js +5 -0
  435. package/Libraries/Text/Text.d.ts +209 -0
  436. package/Libraries/Text/Text.js +94 -12
  437. package/Libraries/Text/TextNativeComponent.js +49 -41
  438. package/Libraries/Text/TextNativeComponent.win32.js +67 -48
  439. package/Libraries/Text/TextProps.js +64 -7
  440. package/Libraries/{Components/MaskedView/MaskedViewIOS.win32.js → TurboModule/RCTExport.d.ts} +3 -4
  441. package/Libraries/TurboModule/TurboModuleRegistry.d.ts +15 -0
  442. package/Libraries/TurboModule/TurboModuleRegistry.js +3 -1
  443. package/Libraries/TurboModule/samples/NativeSampleTurboModule.js +1 -0
  444. package/Libraries/Types/CoreEventTypes.d.ts +263 -0
  445. package/Libraries/Types/CoreEventTypes.js +2 -1
  446. package/Libraries/Types/CoreEventTypes.win32.js +2 -1
  447. package/Libraries/Utilities/AcessibilityMapping.js +154 -0
  448. package/Libraries/Utilities/Appearance.d.ts +43 -0
  449. package/Libraries/Utilities/Appearance.js +3 -3
  450. package/Libraries/Utilities/BackHandler.android.js +3 -5
  451. package/Libraries/Utilities/BackHandler.d.ts +38 -0
  452. package/Libraries/Utilities/BackHandler.win32.js +3 -5
  453. package/Libraries/Utilities/DevSettings.d.ts +32 -0
  454. package/Libraries/Utilities/DevSettings.js +4 -2
  455. package/Libraries/Utilities/Dimensions.d.ts +79 -0
  456. package/Libraries/Utilities/Dimensions.js +2 -2
  457. package/Libraries/Utilities/Dimensions.win32.js +2 -2
  458. package/Libraries/Utilities/GlobalPerformanceLogger.js +2 -1
  459. package/Libraries/Utilities/HMRClient.js +23 -8
  460. package/Libraries/Utilities/LoadingView.ios.js +1 -1
  461. package/Libraries/Utilities/NativeAppearance.js +1 -0
  462. package/Libraries/Utilities/NativeDevLoadingView.js +1 -0
  463. package/Libraries/Utilities/NativeDevSplitBundleLoader.js +1 -0
  464. package/Libraries/Utilities/NativeDeviceInfo.js +1 -0
  465. package/Libraries/Utilities/NativePlatformConstantsAndroid.js +1 -0
  466. package/Libraries/Utilities/NativePlatformConstantsIOS.js +1 -0
  467. package/Libraries/Utilities/NativePlatformConstantsWin.js +1 -0
  468. package/Libraries/Utilities/PerformanceLoggerContext.js +3 -2
  469. package/Libraries/Utilities/PixelRatio.d.ts +64 -0
  470. package/Libraries/Utilities/Platform.android.js +11 -5
  471. package/Libraries/Utilities/Platform.d.ts +102 -0
  472. package/Libraries/Utilities/Platform.ios.js +12 -5
  473. package/Libraries/Utilities/Platform.win32.js +11 -5
  474. package/Libraries/Utilities/PolyfillFunctions.js +1 -1
  475. package/Libraries/Utilities/ReactNativeTestTools.js +9 -15
  476. package/Libraries/Utilities/codegenNativeCommands.js +1 -10
  477. package/Libraries/Utilities/codegenNativeComponent.js +4 -1
  478. package/Libraries/Utilities/createPerformanceLogger.js +7 -8
  479. package/Libraries/Utilities/differ/deepDiffer.js +1 -1
  480. package/Libraries/Utilities/groupByEveryN.js +1 -1
  481. package/Libraries/Utilities/stringifySafe.js +3 -1
  482. package/Libraries/Utilities/useColorScheme.js +3 -2
  483. package/Libraries/Utilities/useRefEffect.js +1 -1
  484. package/Libraries/Vibration/NativeVibration.js +1 -0
  485. package/Libraries/Vibration/Vibration.d.ts +43 -0
  486. package/Libraries/Vibration/Vibration.js +1 -0
  487. package/Libraries/WebPerformance/NativePerformanceObserver.js +41 -0
  488. package/Libraries/WebPerformance/PerformanceObserver.js +223 -0
  489. package/Libraries/WebSocket/NativeWebSocketModule.js +1 -0
  490. package/Libraries/WebSocket/WebSocket.js +11 -3
  491. package/Libraries/WebSocket/WebSocketInterceptor.js +1 -1
  492. package/Libraries/YellowBox/YellowBoxDeprecated.d.ts +19 -0
  493. package/Libraries/YellowBox/YellowBoxDeprecated.js +2 -3
  494. package/Libraries/__flowtests__/ReactNativeTypes-flowtest.js +2 -1
  495. package/Libraries/__tests__/ButtonWin32-test.js +16 -0
  496. package/Libraries/platform-types.d.ts +25 -0
  497. package/Libraries/vendor/core/ErrorUtils.d.ts +15 -0
  498. package/Libraries/vendor/emitter/EventEmitter.d.ts +164 -0
  499. package/babel.config.js +3 -0
  500. package/flow/jest.js +2 -2
  501. package/flow-typed/npm/{react-dom_v16.x.x.js → react-dom_v17.x.x.js} +58 -31
  502. package/flow-typed/npm/yargs_v17.x.x.js +341 -0
  503. package/index.js +89 -55
  504. package/index.win32.js +89 -55
  505. package/interface.js +8 -0
  506. package/jest/react-native-env.js +18 -0
  507. package/jest/renderer.js +2 -2
  508. package/jest/setup.js +7 -9
  509. package/jest.config.js +9 -2
  510. package/overrides.json +40 -101
  511. package/package.json +34 -33
  512. package/src/Libraries/Components/TextInput/TextInput.win32.tsx +2 -1
  513. package/src/Libraries/Components/Touchable/Tests/TouchableWin32Test.tsx +2 -2
  514. package/src/Libraries/Components/Touchable/TouchableWin32.Props.tsx +2 -1
  515. package/src/Libraries/Components/Touchable/TouchableWin32.tsx +1 -1
  516. package/src/Libraries/Components/View/ViewWin32.Props.ts +10 -1
  517. package/src/Libraries/__tests__/__snapshots__/ButtonWin32-test.js.snap +22 -0
  518. package/src/Libraries/platform-types.d.ts +25 -0
  519. package/types/index.d.ts +215 -0
  520. package/IntegrationTests/AsyncStorageTest.js +0 -261
  521. package/Libraries/Components/MaskedView/MaskedViewIOS.ios.js +0 -93
  522. package/Libraries/Components/MaskedView/RCTMaskedViewNativeComponent.js +0 -21
  523. package/Libraries/Core/setUpSystrace.js +0 -21
  524. package/Libraries/Image/ImagePickerIOS.js +0 -103
  525. package/Libraries/Image/NativeImagePickerIOS.js +0 -38
  526. package/Libraries/Lists/VirtualizedList.win32.js +0 -9
  527. package/Libraries/Lists/__tests__/CellRenderMask-test.js +0 -179
  528. package/Libraries/Lists/__tests__/FillRateHelper-test.js +0 -120
  529. package/Libraries/Lists/__tests__/FlatList-test.js +0 -155
  530. package/Libraries/Lists/__tests__/SectionList-test.js +0 -109
  531. package/Libraries/Lists/__tests__/ViewabilityHelper-test.js +0 -440
  532. package/Libraries/Lists/__tests__/VirtualizeUtils-test.js +0 -91
  533. package/Libraries/Lists/__tests__/VirtualizedList-test.js +0 -1587
  534. package/Libraries/Lists/__tests__/VirtualizedSectionList-test.js +0 -269
  535. package/Libraries/Storage/AsyncStorage.js +0 -385
  536. package/Libraries/Storage/NativeAsyncLocalStorage.js +0 -44
  537. package/Libraries/Storage/NativeAsyncSQLiteDBStorage.js +0 -44
  538. package/Libraries/Utilities/JSDevSupportModule.js +0 -37
  539. package/Libraries/Utilities/NativeJSDevSupport.js +0 -23
  540. package/rntypes/BatchedBridge.d.ts +0 -23
  541. package/rntypes/Devtools.d.ts +0 -20
  542. package/rntypes/LaunchScreen.d.ts +0 -9
  543. package/rntypes/globals.d.ts +0 -497
  544. package/rntypes/index.d.ts +0 -9754
  545. package/rntypes/legacy-properties.d.ts +0 -238
  546. package/src/Libraries/Lists/__tests__/__snapshots__/FlatList-test.js.snap +0 -427
  547. package/src/Libraries/Lists/__tests__/__snapshots__/SectionList-test.js.snap +0 -391
  548. package/src/Libraries/Lists/__tests__/__snapshots__/VirtualizedList-test.js.snap +0 -4565
  549. package/src/Libraries/Lists/__tests__/__snapshots__/VirtualizedSectionList-test.js.snap +0 -1153
  550. package/src/rntypes/BatchedBridge.d.ts +0 -23
  551. package/src/rntypes/Devtools.d.ts +0 -20
  552. package/src/rntypes/LaunchScreen.d.ts +0 -9
  553. package/src/rntypes/globals.d.ts +0 -497
  554. package/src/rntypes/index.d.ts +0 -9754
  555. package/src/rntypes/legacy-properties.d.ts +0 -238
  556. package/src/typings-index.ts +0 -37
  557. package/typings-index.d.ts +0 -23
  558. package/typings-index.js +0 -47
  559. package/typings-index.js.map +0 -1
@@ -1,1587 +0,0 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- * @format
8
- * @emails oncall+react_native
9
- */
10
-
11
- 'use strict';
12
-
13
- const React = require('react');
14
- const ReactTestRenderer = require('react-test-renderer');
15
-
16
- const VirtualizedList = require('../VirtualizedList');
17
-
18
- describe('VirtualizedList', () => {
19
- it('renders simple list', () => {
20
- const component = ReactTestRenderer.create(
21
- <VirtualizedList
22
- data={[{key: 'i1'}, {key: 'i2'}, {key: 'i3'}]}
23
- renderItem={({item}) => <item value={item.key} />}
24
- getItem={(data, index) => data[index]}
25
- getItemCount={data => data.length}
26
- />,
27
- );
28
- expect(component).toMatchSnapshot();
29
- });
30
-
31
- it('renders simple list using ListItemComponent', () => {
32
- function ListItemComponent({item}) {
33
- return <item value={item.key} />;
34
- }
35
- const component = ReactTestRenderer.create(
36
- <VirtualizedList
37
- data={[{key: 'i1'}, {key: 'i2'}, {key: 'i3'}]}
38
- ListItemComponent={ListItemComponent}
39
- getItem={(data, index) => data[index]}
40
- getItemCount={data => data.length}
41
- />,
42
- );
43
- expect(component).toMatchSnapshot();
44
- });
45
-
46
- it('warns if both renderItem or ListItemComponent are specified. Uses ListItemComponent', () => {
47
- jest.spyOn(console, 'warn').mockImplementationOnce(() => {});
48
- function ListItemComponent({item}) {
49
- return <item value={item.key} testID={`${item.key}-ListItemComponent`} />;
50
- }
51
- const component = ReactTestRenderer.create(
52
- <VirtualizedList
53
- data={[{key: 'i1'}]}
54
- ListItemComponent={ListItemComponent}
55
- renderItem={({item}) => (
56
- <item value={item.key} testID={`${item.key}-renderItem`} />
57
- )}
58
- getItem={(data, index) => data[index]}
59
- getItemCount={data => data.length}
60
- />,
61
- );
62
-
63
- expect(console.warn).toBeCalledWith(
64
- 'VirtualizedList: Both ListItemComponent and renderItem props are present. ListItemComponent will take precedence over renderItem.',
65
- );
66
- expect(component).toMatchSnapshot();
67
- console.warn.mockRestore();
68
- });
69
-
70
- it('throws if no renderItem or ListItemComponent', () => {
71
- // Silence the React error boundary warning; we expect an uncaught error.
72
- const consoleError = console.error;
73
- jest.spyOn(console, 'error').mockImplementation(message => {
74
- if (message.startsWith('The above error occurred in the ')) {
75
- return;
76
- }
77
- consoleError(message);
78
- });
79
-
80
- const componentFactory = () =>
81
- ReactTestRenderer.create(
82
- <VirtualizedList
83
- data={[{key: 'i1'}, {key: 'i2'}, {key: 'i3'}]}
84
- getItem={(data, index) => data[index]}
85
- getItemCount={data => data.length}
86
- />,
87
- );
88
- expect(componentFactory).toThrow(
89
- 'VirtualizedList: Either ListItemComponent or renderItem props are required but none were found.',
90
- );
91
-
92
- console.error.mockRestore();
93
- });
94
-
95
- it('renders empty list', () => {
96
- const component = ReactTestRenderer.create(
97
- <VirtualizedList
98
- data={[]}
99
- renderItem={({item}) => <item value={item.key} />}
100
- getItem={(data, index) => data[index]}
101
- getItemCount={data => data.length}
102
- />,
103
- );
104
- expect(component).toMatchSnapshot();
105
- });
106
-
107
- it('renders empty list after batch', () => {
108
- const component = ReactTestRenderer.create(
109
- <VirtualizedList
110
- data={[]}
111
- renderItem={({item}) => <item value={item.key} />}
112
- getItem={(data, index) => data[index]}
113
- getItemCount={data => data.length}
114
- />,
115
- );
116
-
117
- ReactTestRenderer.act(() => {
118
- simulateLayout(component, {
119
- viewport: {width: 10, height: 50},
120
- content: {width: 10, height: 200},
121
- });
122
-
123
- performAllBatches();
124
- });
125
-
126
- expect(component).toMatchSnapshot();
127
- });
128
-
129
- it('renders null list', () => {
130
- const component = ReactTestRenderer.create(
131
- <VirtualizedList
132
- data={undefined}
133
- renderItem={({item}) => <item value={item.key} />}
134
- getItem={(data, index) => data[index]}
135
- getItemCount={data => 0}
136
- />,
137
- );
138
- expect(component).toMatchSnapshot();
139
- });
140
-
141
- it('renders empty list with empty component', () => {
142
- const component = ReactTestRenderer.create(
143
- <VirtualizedList
144
- data={[]}
145
- ListEmptyComponent={() => <empty />}
146
- ListFooterComponent={() => <footer />}
147
- ListHeaderComponent={() => <header />}
148
- getItem={(data, index) => data[index]}
149
- getItemCount={data => data.length}
150
- renderItem={({item}) => <item value={item.key} />}
151
- />,
152
- );
153
- expect(component).toMatchSnapshot();
154
- });
155
-
156
- it('renders list with empty component', () => {
157
- const component = ReactTestRenderer.create(
158
- <VirtualizedList
159
- data={[{key: 'hello'}]}
160
- ListEmptyComponent={() => <empty />}
161
- getItem={(data, index) => data[index]}
162
- getItemCount={data => data.length}
163
- renderItem={({item}) => <item value={item.key} />}
164
- />,
165
- );
166
- expect(component).toMatchSnapshot();
167
- });
168
-
169
- it('renders all the bells and whistles', () => {
170
- const component = ReactTestRenderer.create(
171
- <VirtualizedList
172
- ItemSeparatorComponent={() => <separator />}
173
- ListEmptyComponent={() => <empty />}
174
- ListFooterComponent={() => <footer />}
175
- ListHeaderComponent={() => <header />}
176
- data={new Array(5).fill().map((_, ii) => ({id: String(ii)}))}
177
- getItem={(data, index) => data[index]}
178
- getItemCount={data => data.length}
179
- getItemLayout={({index}) => ({length: 50, offset: index * 50})}
180
- inverted={true}
181
- keyExtractor={(item, index) => item.id}
182
- onRefresh={jest.fn()}
183
- refreshing={false}
184
- renderItem={({item}) => <item value={item.id} />}
185
- />,
186
- );
187
- expect(component).toMatchSnapshot();
188
- });
189
-
190
- it('test getItem functionality where data is not an Array', () => {
191
- const component = ReactTestRenderer.create(
192
- <VirtualizedList
193
- data={new Map([['id_0', {key: 'item_0'}]])}
194
- getItem={(data, index) => data.get('id_' + index)}
195
- getItemCount={(data: Map) => data.size}
196
- renderItem={({item}) => <item value={item.key} />}
197
- />,
198
- );
199
- expect(component).toMatchSnapshot();
200
- });
201
-
202
- it('handles separators correctly', () => {
203
- const infos = [];
204
- const component = ReactTestRenderer.create(
205
- <VirtualizedList
206
- ItemSeparatorComponent={props => <separator {...props} />}
207
- data={[{key: 'i0'}, {key: 'i1'}, {key: 'i2'}]}
208
- renderItem={info => {
209
- infos.push(info);
210
- return <item title={info.item.key} />;
211
- }}
212
- getItem={(data, index) => data[index]}
213
- getItemCount={data => data.length}
214
- />,
215
- );
216
- expect(component).toMatchSnapshot();
217
- infos[1].separators.highlight();
218
- expect(component).toMatchSnapshot();
219
- infos[2].separators.updateProps('leading', {press: true});
220
- expect(component).toMatchSnapshot();
221
- infos[1].separators.unhighlight();
222
- });
223
-
224
- it('handles nested lists', () => {
225
- const component = ReactTestRenderer.create(
226
- <VirtualizedList
227
- data={[{key: 'outer0'}, {key: 'outer1'}]}
228
- renderItem={outerInfo => (
229
- <VirtualizedList
230
- data={[
231
- {key: outerInfo.item.key + ':inner0'},
232
- {key: outerInfo.item.key + ':inner1'},
233
- ]}
234
- horizontal={outerInfo.item.key === 'outer1'}
235
- renderItem={innerInfo => {
236
- return <item title={innerInfo.item.key} />;
237
- }}
238
- getItem={(data, index) => data[index]}
239
- getItemCount={data => data.length}
240
- />
241
- )}
242
- getItem={(data, index) => data[index]}
243
- getItemCount={data => data.length}
244
- />,
245
- );
246
- expect(component).toMatchSnapshot();
247
- });
248
-
249
- it('returns the viewableItems correctly in the onViewableItemsChanged callback after changing the data', () => {
250
- const ITEM_HEIGHT = 800;
251
- let data = [{key: 'i1'}, {key: 'i2'}, {key: 'i3'}];
252
- const nativeEvent = {
253
- contentOffset: {y: 0, x: 0},
254
- layoutMeasurement: {width: 300, height: 600},
255
- contentSize: {width: 300, height: data.length * ITEM_HEIGHT},
256
- zoomScale: 1,
257
- contentInset: {right: 0, top: 0, left: 0, bottom: 0},
258
- };
259
- const onViewableItemsChanged = jest.fn();
260
- const props = {
261
- data,
262
- renderItem: ({item}) => <item value={item.key} />,
263
- getItem: (items, index) => items[index],
264
- getItemCount: items => items.length,
265
- getItemLayout: (items, index) => ({
266
- length: ITEM_HEIGHT,
267
- offset: ITEM_HEIGHT * index,
268
- index,
269
- }),
270
- onViewableItemsChanged,
271
- };
272
-
273
- const component = ReactTestRenderer.create(<VirtualizedList {...props} />);
274
-
275
- const instance = component.getInstance();
276
-
277
- instance._onScrollBeginDrag({nativeEvent});
278
- instance._onScroll({
279
- timeStamp: 1000,
280
- nativeEvent,
281
- });
282
-
283
- expect(onViewableItemsChanged).toHaveBeenCalledTimes(1);
284
- expect(onViewableItemsChanged).toHaveBeenLastCalledWith(
285
- expect.objectContaining({
286
- viewableItems: [expect.objectContaining({isViewable: true, key: 'i1'})],
287
- }),
288
- );
289
- data = [{key: 'i4'}, ...data];
290
- component.update(<VirtualizedList {...props} data={data} />);
291
-
292
- instance._onScroll({
293
- timeStamp: 2000,
294
- nativeEvent: {
295
- ...nativeEvent,
296
- contentOffset: {y: 100, x: 0},
297
- },
298
- });
299
-
300
- expect(onViewableItemsChanged).toHaveBeenCalledTimes(2);
301
- expect(onViewableItemsChanged).toHaveBeenLastCalledWith(
302
- expect.objectContaining({
303
- viewableItems: [expect.objectContaining({isViewable: true, key: 'i4'})],
304
- }),
305
- );
306
- });
307
-
308
- it('getScrollRef for case where it returns a ScrollView', () => {
309
- const listRef = React.createRef(null);
310
-
311
- ReactTestRenderer.create(
312
- <VirtualizedList
313
- data={[{key: 'i1'}, {key: 'i2'}, {key: 'i3'}]}
314
- renderItem={({item}) => <item value={item.key} />}
315
- getItem={(data, index) => data[index]}
316
- getItemCount={data => data.length}
317
- ref={listRef}
318
- />,
319
- );
320
-
321
- const scrollRef = listRef.current.getScrollRef();
322
-
323
- // This is checking if the ref acts like a ScrollView. If we had an
324
- // `isScrollView(ref)` method, that would be preferred.
325
- expect(scrollRef.scrollTo).toBeInstanceOf(jest.fn().constructor);
326
- });
327
-
328
- it('getScrollRef for case where it returns a View', () => {
329
- const listRef = React.createRef(null);
330
-
331
- ReactTestRenderer.create(
332
- <VirtualizedList
333
- data={[{key: 'outer0'}, {key: 'outer1'}]}
334
- renderItem={outerInfo => (
335
- <VirtualizedList
336
- data={[
337
- {key: outerInfo.item.key + ':inner0'},
338
- {key: outerInfo.item.key + ':inner1'},
339
- ]}
340
- renderItem={innerInfo => {
341
- return <item title={innerInfo.item.key} />;
342
- }}
343
- getItem={(data, index) => data[index]}
344
- getItemCount={data => data.length}
345
- ref={listRef}
346
- />
347
- )}
348
- getItem={(data, index) => data[index]}
349
- getItemCount={data => data.length}
350
- />,
351
- );
352
- const scrollRef = listRef.current.getScrollRef();
353
-
354
- // This is checking if the ref acts like a host component. If we had an
355
- // `isHostComponent(ref)` method, that would be preferred.
356
- expect(scrollRef.measure).toBeInstanceOf(jest.fn().constructor);
357
- expect(scrollRef.measureLayout).toBeInstanceOf(jest.fn().constructor);
358
- expect(scrollRef.measureInWindow).toBeInstanceOf(jest.fn().constructor);
359
- });
360
- it('does not call onEndReached when onContentSizeChange happens after onLayout', () => {
361
- const ITEM_HEIGHT = 40;
362
- const layout = {width: 300, height: 600};
363
- let data = Array(20)
364
- .fill()
365
- .map((_, index) => ({key: `key-${index}`}));
366
- const onEndReached = jest.fn();
367
- const props = {
368
- data,
369
- initialNumToRender: 10,
370
- onEndReachedThreshold: 2,
371
- windowSize: 21,
372
- renderItem: ({item}) => <item value={item.key} />,
373
- getItem: (items, index) => items[index],
374
- getItemCount: items => items.length,
375
- getItemLayout: (items, index) => ({
376
- length: ITEM_HEIGHT,
377
- offset: ITEM_HEIGHT * index,
378
- index,
379
- }),
380
- onEndReached,
381
- };
382
-
383
- const component = ReactTestRenderer.create(<VirtualizedList {...props} />);
384
-
385
- const instance = component.getInstance();
386
-
387
- instance._onLayout({nativeEvent: {layout, zoomScale: 1}});
388
-
389
- const initialContentHeight = props.initialNumToRender * ITEM_HEIGHT;
390
-
391
- // We want to test the unusual case of onContentSizeChange firing after
392
- // onLayout, which can cause https://github.com/facebook/react-native/issues/16067
393
- instance._onContentSizeChange(300, initialContentHeight);
394
- instance._onContentSizeChange(300, data.length * ITEM_HEIGHT);
395
- performAllBatches();
396
-
397
- expect(onEndReached).not.toHaveBeenCalled();
398
-
399
- instance._onScroll({
400
- timeStamp: 1000,
401
- nativeEvent: {
402
- contentOffset: {y: initialContentHeight, x: 0},
403
- layoutMeasurement: layout,
404
- contentSize: {...layout, height: data.length * ITEM_HEIGHT},
405
- zoomScale: 1,
406
- contentInset: {right: 0, top: 0, left: 0, bottom: 0},
407
- },
408
- });
409
- performAllBatches();
410
-
411
- expect(onEndReached).toHaveBeenCalled();
412
- });
413
-
414
- it('provides a trace when a listKey collision occurs', () => {
415
- const errors = [];
416
- jest.spyOn(console, 'error').mockImplementation((...args) => {
417
- // Silence the DEV-only React error boundary warning.
418
- if ((args[0] || '').startsWith('The above error occurred in the ')) {
419
- return;
420
- }
421
- errors.push(args);
422
- });
423
- const commonProps = {
424
- data: [{key: 'cell0'}],
425
- getItem: (data, index) => data[index],
426
- getItemCount: data => data.length,
427
- renderItem: ({item}) => <item value={item.key} />,
428
- };
429
- try {
430
- ReactTestRenderer.create(
431
- <VirtualizedList
432
- {...commonProps}
433
- horizontal={false}
434
- listKey="level0"
435
- renderItem={() => (
436
- <VirtualizedList
437
- {...commonProps}
438
- horizontal={true}
439
- listKey="level1"
440
- renderItem={() => (
441
- <>
442
- {/* Force a collision */}
443
- <VirtualizedList
444
- {...commonProps}
445
- horizontal={true}
446
- listKey="level2"
447
- />
448
- <VirtualizedList
449
- {...commonProps}
450
- horizontal={true}
451
- listKey="level2"
452
- />
453
- </>
454
- )}
455
- />
456
- )}
457
- />,
458
- );
459
- expect(errors).toMatchInlineSnapshot(`
460
- Array [
461
- Array [
462
- "A VirtualizedList contains a cell which itself contains more than one VirtualizedList of the same orientation as the parent list. You must pass a unique listKey prop to each sibling list.
463
-
464
- VirtualizedList trace:
465
- Child (horizontal):
466
- listKey: level2
467
- cellKey: cell0
468
- Parent (horizontal):
469
- listKey: level1
470
- cellKey: cell0
471
- Parent (vertical):
472
- listKey: level0
473
- cellKey: rootList",
474
- ],
475
- ]
476
- `);
477
- } finally {
478
- console.error.mockRestore();
479
- }
480
- });
481
-
482
- it('throws if using scrollToIndex with index less than 0', () => {
483
- const component = ReactTestRenderer.create(
484
- <VirtualizedList
485
- data={[{key: 'i1'}, {key: 'i2'}, {key: 'i3'}]}
486
- renderItem={({item}) => <item value={item.key} />}
487
- getItem={(data, index) => data[index]}
488
- getItemCount={data => data.length}
489
- />,
490
- );
491
- const instance = component.getInstance();
492
-
493
- expect(() => instance.scrollToIndex({index: -1})).toThrow(
494
- 'scrollToIndex out of range: requested index -1 but minimum is 0',
495
- );
496
- });
497
-
498
- it('throws if using scrollToIndex when item length is less than 1', () => {
499
- const component = ReactTestRenderer.create(
500
- <VirtualizedList
501
- data={[]}
502
- renderItem={({item}) => <item value={item.key} />}
503
- getItem={(data, index) => data[index]}
504
- getItemCount={data => data.length}
505
- />,
506
- );
507
- const instance = component.getInstance();
508
-
509
- expect(() => instance.scrollToIndex({index: 1})).toThrow(
510
- 'scrollToIndex out of range: item length 0 but minimum is 1',
511
- );
512
- });
513
-
514
- it('throws if using scrollToIndex when requested index is bigger than or equal to item length', () => {
515
- const component = ReactTestRenderer.create(
516
- <VirtualizedList
517
- data={[{key: 'i1'}, {key: 'i2'}, {key: 'i3'}]}
518
- renderItem={({item}) => <item value={item.key} />}
519
- getItem={(data, index) => data[index]}
520
- getItemCount={data => data.length}
521
- />,
522
- );
523
- const instance = component.getInstance();
524
-
525
- expect(() => instance.scrollToIndex({index: 3})).toThrow(
526
- 'scrollToIndex out of range: requested index 3 is out of 0 to 2',
527
- );
528
- });
529
-
530
- it('forwards correct stickyHeaderIndices when all in initial render window', () => {
531
- const items = generateItemsStickyEveryN(10, 3);
532
- const ITEM_HEIGHT = 10;
533
-
534
- const component = ReactTestRenderer.create(
535
- <VirtualizedList
536
- initialNumToRender={10}
537
- {...baseItemProps(items)}
538
- {...fixedHeightItemLayoutProps(ITEM_HEIGHT)}
539
- />,
540
- );
541
-
542
- // The initial render is specified to be the length of items provided.
543
- // Expect that all sticky items (1 every 3) are passed to the underlying
544
- // scrollview.
545
- expect(component).toMatchSnapshot();
546
- });
547
-
548
- it('forwards correct stickyHeaderIndices when ListHeaderComponent present', () => {
549
- const items = generateItemsStickyEveryN(10, 3);
550
- const ITEM_HEIGHT = 10;
551
-
552
- const component = ReactTestRenderer.create(
553
- <VirtualizedList
554
- ListHeaderComponent={() => React.createElement('Header')}
555
- initialNumToRender={10}
556
- {...baseItemProps(items)}
557
- {...fixedHeightItemLayoutProps(ITEM_HEIGHT)}
558
- />,
559
- );
560
-
561
- // The initial render is specified to be the length of items provided.
562
- // Expect that all sticky items (1 every 3) are passed to the underlying
563
- // scrollview, indices offset by 1 to account for the the header component.
564
- expect(component).toMatchSnapshot();
565
- });
566
-
567
- it('forwards correct stickyHeaderIndices when partially in initial render window', () => {
568
- const items = generateItemsStickyEveryN(10, 3);
569
-
570
- const ITEM_HEIGHT = 10;
571
-
572
- const component = ReactTestRenderer.create(
573
- <VirtualizedList
574
- initialNumToRender={5}
575
- {...baseItemProps(items)}
576
- {...fixedHeightItemLayoutProps(ITEM_HEIGHT)}
577
- />,
578
- );
579
-
580
- // The initial render is specified to be half the length of items provided.
581
- // Expect that all sticky items of index < 5 are passed to the underlying
582
- // scrollview.
583
- expect(component).toMatchSnapshot();
584
- });
585
-
586
- it('renders sticky headers in viewport on batched render', () => {
587
- const items = generateItemsStickyEveryN(10, 3);
588
- const ITEM_HEIGHT = 10;
589
-
590
- let component;
591
- ReactTestRenderer.act(() => {
592
- component = ReactTestRenderer.create(
593
- <VirtualizedList
594
- initialNumToRender={1}
595
- windowSize={1}
596
- {...baseItemProps(items)}
597
- {...fixedHeightItemLayoutProps(ITEM_HEIGHT)}
598
- />,
599
- );
600
- });
601
-
602
- ReactTestRenderer.act(() => {
603
- simulateLayout(component, {
604
- viewport: {width: 10, height: 50},
605
- content: {width: 10, height: 100},
606
- });
607
- performAllBatches();
608
- });
609
-
610
- // A windowSize of 1 means we will render just the viewport height (50dip).
611
- // Expect 5 10dip items to eventually be rendered, with sticky headers in
612
- // the first 5 propagated.
613
- expect(component).toMatchSnapshot();
614
- });
615
-
616
- it('keeps sticky headers above viewport visualized', () => {
617
- const items = generateItemsStickyEveryN(20, 3);
618
- const ITEM_HEIGHT = 10;
619
-
620
- let component;
621
- ReactTestRenderer.act(() => {
622
- component = ReactTestRenderer.create(
623
- <VirtualizedList
624
- initialNumToRender={1}
625
- windowSize={1}
626
- {...baseItemProps(items)}
627
- {...fixedHeightItemLayoutProps(ITEM_HEIGHT)}
628
- />,
629
- );
630
- });
631
-
632
- ReactTestRenderer.act(() => {
633
- simulateLayout(component, {
634
- viewport: {width: 10, height: 50},
635
- content: {width: 10, height: 200},
636
- });
637
- performAllBatches();
638
- });
639
-
640
- ReactTestRenderer.act(() => {
641
- simulateScroll(component, {x: 0, y: 150});
642
- performAllBatches();
643
- });
644
-
645
- // Scroll to the bottom 50 dip (last five items) of the content. Expect the
646
- // last five items to be rendered (possibly more if realization window is
647
- // larger), along with the most recent sticky header above the realization
648
- // region, even though they are out of the viewport window in layout
649
- // coordinates. This is because they will remain rendered even once
650
- // scrolled-past in layout space.
651
- expect(component).toMatchSnapshot();
652
- });
653
- });
654
-
655
- it('unmounts sticky headers moved below viewport', () => {
656
- const items = generateItemsStickyEveryN(20, 3);
657
- const ITEM_HEIGHT = 10;
658
-
659
- let component;
660
- ReactTestRenderer.act(() => {
661
- component = ReactTestRenderer.create(
662
- <VirtualizedList
663
- initialNumToRender={1}
664
- windowSize={1}
665
- {...baseItemProps(items)}
666
- {...fixedHeightItemLayoutProps(ITEM_HEIGHT)}
667
- />,
668
- );
669
- });
670
-
671
- ReactTestRenderer.act(() => {
672
- simulateLayout(component, {
673
- viewport: {width: 10, height: 50},
674
- content: {width: 10, height: 200},
675
- });
676
- performAllBatches();
677
- });
678
-
679
- ReactTestRenderer.act(() => {
680
- simulateScroll(component, {x: 0, y: 150});
681
- performAllBatches();
682
- });
683
-
684
- ReactTestRenderer.act(() => {
685
- simulateScroll(component, {x: 0, y: 0});
686
- performAllBatches();
687
- });
688
-
689
- // Scroll to the bottom 50 dip (last five items) of the content, then back up
690
- // to the first 5. Ensure that sticky items are unmounted once they are below
691
- // the render area.
692
- expect(component).toMatchSnapshot();
693
- });
694
-
695
- it('renders offset cells in initial render when initialScrollIndex set', () => {
696
- const items = generateItems(10);
697
- const ITEM_HEIGHT = 10;
698
-
699
- const component = ReactTestRenderer.create(
700
- <VirtualizedList
701
- initialScrollIndex={4}
702
- initialNumToRender={4}
703
- {...baseItemProps(items)}
704
- {...fixedHeightItemLayoutProps(ITEM_HEIGHT)}
705
- />,
706
- );
707
-
708
- // Check that the first render respects initialScrollIndex
709
- expect(component).toMatchSnapshot();
710
- });
711
-
712
- it('does not over-render when there is less than initialNumToRender cells', () => {
713
- const items = generateItems(10);
714
- const ITEM_HEIGHT = 10;
715
-
716
- const component = ReactTestRenderer.create(
717
- <VirtualizedList
718
- initialScrollIndex={4}
719
- initialNumToRender={20}
720
- {...baseItemProps(items)}
721
- {...fixedHeightItemLayoutProps(ITEM_HEIGHT)}
722
- />,
723
- );
724
-
725
- // Check that the first render clamps to the last item when intialNumToRender
726
- // goes over it.
727
- expect(component).toMatchSnapshot();
728
- });
729
-
730
- it('retains intitial render if initialScrollIndex == 0', () => {
731
- const items = generateItems(20);
732
- const ITEM_HEIGHT = 10;
733
-
734
- let component;
735
- ReactTestRenderer.act(() => {
736
- component = ReactTestRenderer.create(
737
- <VirtualizedList
738
- initialNumToRender={5}
739
- initialScrollIndex={0}
740
- windowSize={1}
741
- {...baseItemProps(items)}
742
- {...fixedHeightItemLayoutProps(ITEM_HEIGHT)}
743
- />,
744
- );
745
- });
746
-
747
- ReactTestRenderer.act(() => {
748
- simulateLayout(component, {
749
- viewport: {width: 10, height: 50},
750
- content: {width: 10, height: 200},
751
- });
752
- performAllBatches();
753
- });
754
-
755
- ReactTestRenderer.act(() => {
756
- simulateScroll(component, {x: 0, y: 150});
757
- performAllBatches();
758
- });
759
-
760
- // If initialScrollIndex is 0 (the default), we should never unmount the top
761
- // initialNumToRender as part of the "scroll to top optimization", even after
762
- // scrolling to the bottom five items.
763
- expect(component).toMatchSnapshot();
764
- });
765
-
766
- it('discards intitial render if initialScrollIndex != 0', () => {
767
- const items = generateItems(20);
768
- const ITEM_HEIGHT = 10;
769
-
770
- let component;
771
- ReactTestRenderer.act(() => {
772
- component = ReactTestRenderer.create(
773
- <VirtualizedList
774
- initialScrollIndex={5}
775
- initialNumToRender={5}
776
- windowSize={1}
777
- {...baseItemProps(items)}
778
- {...fixedHeightItemLayoutProps(ITEM_HEIGHT)}
779
- />,
780
- );
781
- });
782
-
783
- ReactTestRenderer.act(() => {
784
- simulateLayout(component, {
785
- viewport: {width: 10, height: 50},
786
- content: {width: 10, height: 200},
787
- });
788
- performAllBatches();
789
- });
790
-
791
- ReactTestRenderer.act(() => {
792
- simulateScroll(component, {x: 0, y: 150});
793
- performAllBatches();
794
- });
795
-
796
- // If initialScrollIndex is not 0, we do not enable retaining initial render
797
- // as part of "scroll to top" optimization.
798
- expect(component).toMatchSnapshot();
799
- });
800
-
801
- it('expands render area by maxToRenderPerBatch on tick', () => {
802
- const items = generateItems(20);
803
- const ITEM_HEIGHT = 10;
804
-
805
- const props = {
806
- initialNumToRender: 5,
807
- maxToRenderPerBatch: 2,
808
- };
809
-
810
- let component;
811
- ReactTestRenderer.act(() => {
812
- component = ReactTestRenderer.create(
813
- <VirtualizedList
814
- {...baseItemProps(items)}
815
- {...fixedHeightItemLayoutProps(ITEM_HEIGHT)}
816
- {...props}
817
- />,
818
- );
819
- });
820
-
821
- ReactTestRenderer.act(() => {
822
- simulateLayout(component, {
823
- viewport: {width: 10, height: 50},
824
- content: {width: 10, height: 200},
825
- });
826
- performNextBatch();
827
- });
828
-
829
- // We start by rendering 5 items in the initial render, but have default
830
- // windowSize, enabling eventual rendering up to 20 viewports worth of
831
- // content. We limit this to rendering 2 items per-batch via
832
- // maxToRenderPerBatch, so we should only have 7 items rendered after the
833
- // initial timer tick.
834
- expect(component).toMatchSnapshot();
835
- });
836
-
837
- it('does not adjust render area until content area layed out', () => {
838
- const items = generateItems(20);
839
- const ITEM_HEIGHT = 10;
840
-
841
- let component;
842
-
843
- ReactTestRenderer.act(() => {
844
- component = ReactTestRenderer.create(
845
- <VirtualizedList
846
- initialNumToRender={5}
847
- windowSize={10}
848
- {...baseItemProps(items)}
849
- {...fixedHeightItemLayoutProps(ITEM_HEIGHT)}
850
- />,
851
- );
852
- });
853
-
854
- ReactTestRenderer.act(() => {
855
- simulateViewportLayout(component, {width: 10, height: 50});
856
- performAllBatches();
857
- });
858
-
859
- // We should not start layout-based logic to expand rendered area until
860
- // content is layed out. Expect only the 5 initial items to be rendered after
861
- // processing all batch work, even though the windowSize allows for more.
862
- expect(component).toMatchSnapshot();
863
- });
864
-
865
- it('adjusts render area with non-zero initialScrollIndex', () => {
866
- const items = generateItems(20);
867
- const ITEM_HEIGHT = 10;
868
-
869
- let component;
870
- ReactTestRenderer.act(() => {
871
- component = ReactTestRenderer.create(
872
- <VirtualizedList
873
- initialNumToRender={5}
874
- initialScrollIndex={1}
875
- windowSize={10}
876
- maxToRenderPerBatch={10}
877
- {...baseItemProps(items)}
878
- {...fixedHeightItemLayoutProps(ITEM_HEIGHT)}
879
- />,
880
- );
881
- });
882
-
883
- ReactTestRenderer.act(() => {
884
- simulateLayout(component, {
885
- viewport: {width: 10, height: 50},
886
- content: {width: 10, height: 200},
887
- });
888
- simulateScroll(component, {x: 0, y: 10}); // simulate scroll offset for initialScrollIndex
889
-
890
- performAllBatches();
891
- });
892
-
893
- // We should expand the render area after receiving a message indcating we
894
- // arrived at initialScrollIndex.
895
- expect(component).toMatchSnapshot();
896
- });
897
-
898
- it('renders new items when data is updated with non-zero initialScrollIndex', () => {
899
- const items = generateItems(2);
900
- const ITEM_HEIGHT = 10;
901
-
902
- let component;
903
- ReactTestRenderer.act(() => {
904
- component = ReactTestRenderer.create(
905
- <VirtualizedList
906
- initialNumToRender={5}
907
- initialScrollIndex={1}
908
- windowSize={10}
909
- maxToRenderPerBatch={10}
910
- {...baseItemProps(items)}
911
- {...fixedHeightItemLayoutProps(ITEM_HEIGHT)}
912
- />,
913
- );
914
- });
915
-
916
- ReactTestRenderer.act(() => {
917
- simulateLayout(component, {
918
- viewport: {width: 10, height: 20},
919
- content: {width: 10, height: 20},
920
- });
921
- performAllBatches();
922
- });
923
-
924
- const newItems = generateItems(4);
925
-
926
- ReactTestRenderer.act(() => {
927
- component.update(
928
- <VirtualizedList
929
- initialNumToRender={5}
930
- initialScrollIndex={1}
931
- windowSize={10}
932
- maxToRenderPerBatch={10}
933
- {...baseItemProps(newItems)}
934
- {...fixedHeightItemLayoutProps(ITEM_HEIGHT)}
935
- />,
936
- );
937
- });
938
-
939
- ReactTestRenderer.act(() => {
940
- performAllBatches();
941
- });
942
-
943
- // We expect all the items to be rendered
944
- expect(component).toMatchSnapshot();
945
- });
946
-
947
- it('renders initialNumToRender cells when virtualization disabled', () => {
948
- const items = generateItems(10);
949
- const ITEM_HEIGHT = 10;
950
-
951
- const component = ReactTestRenderer.create(
952
- <VirtualizedList
953
- initialNumToRender={5}
954
- initialScrollIndex={1}
955
- disableVirtualization
956
- {...baseItemProps(items)}
957
- {...fixedHeightItemLayoutProps(ITEM_HEIGHT)}
958
- />,
959
- );
960
-
961
- // We should render initialNumToRender items with no spacers on initial render
962
- // when virtualization is disabled
963
- expect(component).toMatchSnapshot();
964
- });
965
-
966
- it('renders no spacers up to initialScrollIndex on first render when virtualization disabled', () => {
967
- const items = generateItems(10);
968
- const ITEM_HEIGHT = 10;
969
-
970
- let component;
971
- ReactTestRenderer.act(() => {
972
- component = ReactTestRenderer.create(
973
- <VirtualizedList
974
- initialNumToRender={2}
975
- initialScrollIndex={4}
976
- maxToRenderPerBatch={1}
977
- disableVirtualization
978
- {...baseItemProps(items)}
979
- {...fixedHeightItemLayoutProps(ITEM_HEIGHT)}
980
- />,
981
- );
982
- });
983
-
984
- // There should be no spacers present in an offset initial render with
985
- // virtualiztion disabled. Only initialNumToRender items starting at
986
- // initialScrollIndex.
987
- expect(component).toMatchSnapshot();
988
- });
989
-
990
- it('expands first in viewport to render up to maxToRenderPerBatch on initial render', () => {
991
- const items = generateItems(10);
992
- const ITEM_HEIGHT = 10;
993
-
994
- let component;
995
- ReactTestRenderer.act(() => {
996
- component = ReactTestRenderer.create(
997
- <VirtualizedList
998
- initialNumToRender={2}
999
- initialScrollIndex={4}
1000
- maxToRenderPerBatch={10}
1001
- {...baseItemProps(items)}
1002
- {...fixedHeightItemLayoutProps(ITEM_HEIGHT)}
1003
- />,
1004
- );
1005
- });
1006
-
1007
- // When virtualization is disabled we may render items before initialItemIndex
1008
- // if initialItemIndex + initialNumToRender < maToRenderPerBatch. Expect cells
1009
- // 0-3 to be rendered in this example, even though initialScrollIndex is 4.
1010
- expect(component).toMatchSnapshot();
1011
- });
1012
-
1013
- it('renders items before initialScrollIndex on first batch tick when virtualization disabled', () => {
1014
- const items = generateItems(10);
1015
- const ITEM_HEIGHT = 10;
1016
-
1017
- let component;
1018
- ReactTestRenderer.act(() => {
1019
- component = ReactTestRenderer.create(
1020
- <VirtualizedList
1021
- initialNumToRender={1}
1022
- initialScrollIndex={5}
1023
- maxToRenderPerBatch={1}
1024
- disableVirtualization
1025
- {...baseItemProps(items)}
1026
- {...fixedHeightItemLayoutProps(ITEM_HEIGHT)}
1027
- />,
1028
- );
1029
- });
1030
-
1031
- ReactTestRenderer.act(() => {
1032
- simulateLayout(component, {
1033
- viewport: {width: 10, height: 50},
1034
- content: {width: 10, height: 100},
1035
- });
1036
- performNextBatch();
1037
- });
1038
-
1039
- // When virtualization is disabled, we render "maxToRenderPerBatch" items
1040
- // sequentially per batch tick. Any items not yet rendered before
1041
- // initialScrollIndex are currently rendered at this time. Expect the first
1042
- // tick to render all items before initialScrollIndex, along with
1043
- // maxToRenderPerBatch after.
1044
- expect(component).toMatchSnapshot();
1045
- });
1046
-
1047
- it('eventually renders all items when virtualization disabled', () => {
1048
- const items = generateItems(10);
1049
- const ITEM_HEIGHT = 10;
1050
-
1051
- let component;
1052
- ReactTestRenderer.act(() => {
1053
- component = ReactTestRenderer.create(
1054
- <VirtualizedList
1055
- initialNumToRender={5}
1056
- initialScrollIndex={1}
1057
- windowSize={1}
1058
- maxToRenderPerBatch={10}
1059
- disableVirtualization
1060
- {...baseItemProps(items)}
1061
- {...fixedHeightItemLayoutProps(ITEM_HEIGHT)}
1062
- />,
1063
- );
1064
- });
1065
-
1066
- ReactTestRenderer.act(() => {
1067
- simulateLayout(component, {
1068
- viewport: {width: 10, height: 50},
1069
- content: {width: 10, height: 100},
1070
- });
1071
- performAllBatches();
1072
- });
1073
-
1074
- // After all batch ticks, all items should eventually be rendered when\
1075
- // virtualization is disabled.
1076
- expect(component).toMatchSnapshot();
1077
- });
1078
-
1079
- it('retains initial render region when an item is appended', () => {
1080
- const items = generateItems(10);
1081
- const ITEM_HEIGHT = 10;
1082
-
1083
- let component;
1084
- ReactTestRenderer.act(() => {
1085
- component = ReactTestRenderer.create(
1086
- <VirtualizedList
1087
- initialNumToRender={3}
1088
- {...baseItemProps(items)}
1089
- {...fixedHeightItemLayoutProps(ITEM_HEIGHT)}
1090
- />,
1091
- );
1092
- });
1093
-
1094
- ReactTestRenderer.act(() => {
1095
- component.update(
1096
- <VirtualizedList
1097
- initialNumToRender={3}
1098
- {...baseItemProps(items)}
1099
- {...fixedHeightItemLayoutProps(ITEM_HEIGHT)}
1100
- data={generateItems(11)}
1101
- />,
1102
- );
1103
- });
1104
-
1105
- // Adding an item to the list before batch render should keep the existing
1106
- // rendered items rendered. Expect the first 3 items rendered, and a spacer
1107
- // for 8 items (including the 11th, added item).
1108
- expect(component).toMatchSnapshot();
1109
- });
1110
-
1111
- it('retains batch render region when an item is appended', () => {
1112
- const items = generateItems(10);
1113
- const ITEM_HEIGHT = 10;
1114
-
1115
- let component;
1116
- ReactTestRenderer.act(() => {
1117
- component = ReactTestRenderer.create(
1118
- <VirtualizedList
1119
- initialNumToRender={1}
1120
- maxToRenderPerBatch={1}
1121
- {...baseItemProps(items)}
1122
- {...fixedHeightItemLayoutProps(ITEM_HEIGHT)}
1123
- />,
1124
- );
1125
- });
1126
-
1127
- ReactTestRenderer.act(() => {
1128
- simulateLayout(component, {
1129
- viewport: {width: 10, height: 50},
1130
- content: {width: 10, height: 100},
1131
- });
1132
- performAllBatches();
1133
- });
1134
-
1135
- jest.runAllTimers();
1136
-
1137
- ReactTestRenderer.act(() => {
1138
- component.update(
1139
- <VirtualizedList
1140
- initialNumToRender={1}
1141
- maxToRenderPerBatch={1}
1142
- {...baseItemProps(items)}
1143
- {...fixedHeightItemLayoutProps(ITEM_HEIGHT)}
1144
- data={generateItems(11)}
1145
- />,
1146
- );
1147
- });
1148
-
1149
- // Adding an item to the list after batch render should keep the existing
1150
- // rendered items rendered. We batch render 10 items, then add an 11th. Expect
1151
- // the first ten items to be present, with a spacer for the 11th until the
1152
- // next batch render.
1153
- expect(component).toMatchSnapshot();
1154
- });
1155
-
1156
- it('constrains batch render region when an item is removed', () => {
1157
- const items = generateItems(10);
1158
- const ITEM_HEIGHT = 10;
1159
-
1160
- let component;
1161
- ReactTestRenderer.act(() => {
1162
- component = ReactTestRenderer.create(
1163
- <VirtualizedList
1164
- initialNumToRender={1}
1165
- maxToRenderPerBatch={1}
1166
- {...baseItemProps(items)}
1167
- {...fixedHeightItemLayoutProps(ITEM_HEIGHT)}
1168
- />,
1169
- );
1170
- });
1171
-
1172
- ReactTestRenderer.act(() => {
1173
- simulateLayout(component, {
1174
- viewport: {width: 10, height: 50},
1175
- content: {width: 10, height: 100},
1176
- });
1177
- performAllBatches();
1178
- });
1179
-
1180
- ReactTestRenderer.act(() => {
1181
- component.update(
1182
- <VirtualizedList
1183
- initialNumToRender={1}
1184
- maxToRenderPerBatch={1}
1185
- {...baseItemProps(items)}
1186
- {...fixedHeightItemLayoutProps(ITEM_HEIGHT)}
1187
- data={generateItems(5)}
1188
- />,
1189
- );
1190
- });
1191
-
1192
- // If the number of items is reduced, we should remove the corresponding
1193
- // already rendered items. Expect there to be 5 items present. New items in a
1194
- // previously occupied index may also be immediately rendered.
1195
- expect(component).toMatchSnapshot();
1196
- });
1197
-
1198
- it('renders a zero-height tail spacer on initial render if getItemLayout not defined', () => {
1199
- const items = generateItems(10);
1200
-
1201
- const component = ReactTestRenderer.create(
1202
- <VirtualizedList initialNumToRender={3} {...baseItemProps(items)} />,
1203
- );
1204
-
1205
- // Do not add space for out-of-viewport content on initial render when we do
1206
- // not yet know how large it should be (no getItemLayout and cell onLayout not
1207
- // yet called). Expect the tail spacer not to occupy space.
1208
- expect(component).toMatchSnapshot();
1209
- });
1210
-
1211
- it('renders zero-height tail spacer on batch render if cells not yet measured and getItemLayout not defined', () => {
1212
- const items = generateItems(10);
1213
-
1214
- let component;
1215
- ReactTestRenderer.act(() => {
1216
- component = ReactTestRenderer.create(
1217
- <VirtualizedList
1218
- initialNumToRender={3}
1219
- maxToRenderPerBatch={1}
1220
- windowSize={1}
1221
- {...baseItemProps(items)}
1222
- />,
1223
- );
1224
- });
1225
-
1226
- ReactTestRenderer.act(() => {
1227
- simulateLayout(component, {
1228
- viewport: {width: 10, height: 50},
1229
- content: {width: 10, height: 200},
1230
- });
1231
- performNextBatch();
1232
- });
1233
-
1234
- // Do not add space for out-of-viewport content unless the cell has previously
1235
- // been layed out and measurements cached. Expect the tail spacer not to
1236
- // occupy space.
1237
- expect(component).toMatchSnapshot();
1238
- });
1239
-
1240
- it('renders tail spacer up to last measured index if getItemLayout not defined', () => {
1241
- const items = generateItems(10);
1242
-
1243
- let component;
1244
- ReactTestRenderer.act(() => {
1245
- component = ReactTestRenderer.create(
1246
- <VirtualizedList
1247
- initialNumToRender={3}
1248
- maxToRenderPerBatch={1}
1249
- windowSize={1}
1250
- {...baseItemProps(items)}
1251
- />,
1252
- );
1253
- });
1254
-
1255
- ReactTestRenderer.act(() => {
1256
- const LAST_MEASURED_CELL = 6;
1257
- for (let i = 0; i <= LAST_MEASURED_CELL; ++i) {
1258
- simulateCellLayout(component, items, i, {
1259
- width: 10,
1260
- height: 10,
1261
- x: 0,
1262
- y: 10 * i,
1263
- });
1264
- }
1265
-
1266
- simulateLayout(component, {
1267
- viewport: {width: 10, height: 50},
1268
- content: {width: 10, height: 30},
1269
- });
1270
- performNextBatch();
1271
- });
1272
-
1273
- // If cells in the out-of-viewport area have been measured, their space can be
1274
- // incorporated into the tail spacer, without space for the cells we can not
1275
- // measure until layout. Expect there to be a tail spacer occupying the space
1276
- // for measured, but not yet rendered items (up to and including item 6).
1277
- expect(component).toMatchSnapshot();
1278
- });
1279
-
1280
- it('renders tail spacer up to last measured with irregular layout when getItemLayout undefined', () => {
1281
- const items = generateItems(10);
1282
-
1283
- let component;
1284
- ReactTestRenderer.act(() => {
1285
- component = ReactTestRenderer.create(
1286
- <VirtualizedList
1287
- initialNumToRender={3}
1288
- maxToRenderPerBatch={1}
1289
- windowSize={1}
1290
- {...baseItemProps(items)}
1291
- />,
1292
- );
1293
- });
1294
-
1295
- ReactTestRenderer.act(() => {
1296
- const LAST_MEASURED_CELL = 6;
1297
-
1298
- let currentY = 0;
1299
- for (let i = 0; i <= LAST_MEASURED_CELL; ++i) {
1300
- simulateCellLayout(component, items, i, {
1301
- width: 10,
1302
- height: i,
1303
- x: 0,
1304
- y: currentY + i,
1305
- });
1306
- currentY += i;
1307
- }
1308
-
1309
- simulateLayout(component, {
1310
- viewport: {width: 10, height: 50},
1311
- content: {width: 10, height: 30},
1312
- });
1313
- performNextBatch();
1314
- });
1315
-
1316
- // If cells in the out-of-viewport area have been measured, their space can be
1317
- // incorporated into the tail spacer, without space for the cells we can not
1318
- // measure until layout. Expect there to be a tail spacer occupying the space
1319
- // for measured, but not yet rendered items (up to and including item 6).
1320
- expect(component).toMatchSnapshot();
1321
- });
1322
-
1323
- it('renders full tail spacer if all cells measured', () => {
1324
- const items = generateItems(10);
1325
-
1326
- let component;
1327
- ReactTestRenderer.act(() => {
1328
- component = ReactTestRenderer.create(
1329
- <VirtualizedList
1330
- initialNumToRender={3}
1331
- maxToRenderPerBatch={1}
1332
- windowSize={1}
1333
- {...baseItemProps(items)}
1334
- />,
1335
- );
1336
- });
1337
-
1338
- ReactTestRenderer.act(() => {
1339
- const LAST_MEASURED_CELL = 9;
1340
- for (let i = 0; i <= LAST_MEASURED_CELL; ++i) {
1341
- simulateCellLayout(component, items, i, {
1342
- width: 10,
1343
- height: 10,
1344
- x: 0,
1345
- y: 10 * i,
1346
- });
1347
- }
1348
-
1349
- simulateLayout(component, {
1350
- viewport: {width: 10, height: 50},
1351
- content: {width: 10, height: 30},
1352
- });
1353
- performNextBatch();
1354
- });
1355
-
1356
- // The tail-spacer should occupy the space of all non-rendered items if all
1357
- // items have been measured.
1358
- expect(component).toMatchSnapshot();
1359
- });
1360
-
1361
- it('renders windowSize derived region at top', () => {
1362
- const items = generateItems(10);
1363
- const ITEM_HEIGHT = 10;
1364
-
1365
- let component;
1366
- ReactTestRenderer.act(() => {
1367
- component = ReactTestRenderer.create(
1368
- <VirtualizedList
1369
- initialNumToRender={1}
1370
- maxToRenderPerBatch={1}
1371
- windowSize={3}
1372
- {...baseItemProps(items)}
1373
- {...fixedHeightItemLayoutProps(ITEM_HEIGHT)}
1374
- />,
1375
- );
1376
- });
1377
-
1378
- ReactTestRenderer.act(() => {
1379
- simulateLayout(component, {
1380
- viewport: {width: 10, height: 20},
1381
- content: {width: 10, height: 100},
1382
- });
1383
- performAllBatches();
1384
- });
1385
-
1386
- jest.runAllTimers();
1387
- // A windowSize of 3 means that we should render a viewport's worth of content
1388
- // above and below the current. A 20 dip viewport at the top of the list means
1389
- // we should render the top 4 10-dip items (for the current viewport, and
1390
- // 20dip below).
1391
- expect(component).toMatchSnapshot();
1392
- });
1393
-
1394
- it('renders windowSize derived region in middle', () => {
1395
- const items = generateItems(10);
1396
- const ITEM_HEIGHT = 10;
1397
-
1398
- let component;
1399
- ReactTestRenderer.act(() => {
1400
- component = ReactTestRenderer.create(
1401
- <VirtualizedList
1402
- initialNumToRender={1}
1403
- maxToRenderPerBatch={1}
1404
- windowSize={3}
1405
- {...baseItemProps(items)}
1406
- {...fixedHeightItemLayoutProps(ITEM_HEIGHT)}
1407
- />,
1408
- );
1409
- });
1410
-
1411
- ReactTestRenderer.act(() => {
1412
- simulateLayout(component, {
1413
- viewport: {width: 10, height: 20},
1414
- content: {width: 10, height: 100},
1415
- });
1416
- performAllBatches();
1417
- });
1418
-
1419
- ReactTestRenderer.act(() => {
1420
- simulateScroll(component, {x: 0, y: 50});
1421
- performAllBatches();
1422
- });
1423
-
1424
- jest.runAllTimers();
1425
- // A windowSize of 3 means that we should render a viewport's worth of content
1426
- // above and below the current. A 20 dip viewport in the top of the list means
1427
- // we should render the 6 10-dip items (for the current viewport, 20 dip above
1428
- // and below), along with retaining the top initialNumToRenderItems. We seem
1429
- // to actually render 7 in the middle due to rounding at the moment.
1430
- expect(component).toMatchSnapshot();
1431
- });
1432
-
1433
- it('renders windowSize derived region at bottom', () => {
1434
- const items = generateItems(10);
1435
- const ITEM_HEIGHT = 10;
1436
-
1437
- let component;
1438
- ReactTestRenderer.act(() => {
1439
- component = ReactTestRenderer.create(
1440
- <VirtualizedList
1441
- initialNumToRender={1}
1442
- maxToRenderPerBatch={1}
1443
- windowSize={3}
1444
- {...baseItemProps(items)}
1445
- {...fixedHeightItemLayoutProps(ITEM_HEIGHT)}
1446
- />,
1447
- );
1448
- });
1449
-
1450
- ReactTestRenderer.act(() => {
1451
- simulateLayout(component, {
1452
- viewport: {width: 10, height: 20},
1453
- content: {width: 10, height: 100},
1454
- });
1455
- performAllBatches();
1456
- });
1457
- ReactTestRenderer.act(() => {
1458
- simulateScroll(component, {x: 0, y: 80});
1459
- performAllBatches();
1460
- });
1461
-
1462
- jest.runAllTimers();
1463
- // A windowSize of 3 means that we should render a viewport's worth of content
1464
- // above and below the current. A 20 dip viewport at the bottom of the list
1465
- // means we should render the bottom 4 10-dip items (for the current viewport,
1466
- // and 20dip above), along with retaining the top initialNumToRenderItems. We
1467
- // seem to actually render 4 at the bottom due to rounding at the moment.
1468
- expect(component).toMatchSnapshot();
1469
- });
1470
-
1471
- it('calls _onCellLayout properly', () => {
1472
- const items = [{key: 'i1'}, {key: 'i2'}, {key: 'i3'}];
1473
- const mock = jest.fn();
1474
- const component = ReactTestRenderer.create(
1475
- <VirtualizedList
1476
- data={items}
1477
- renderItem={({item}) => <item value={item.key} />}
1478
- getItem={(data, index) => data[index]}
1479
- getItemCount={data => data.length}
1480
- />,
1481
- );
1482
- const virtualList: VirtualizedList = component.getInstance();
1483
- virtualList._onCellLayout = mock;
1484
- component.update(
1485
- <VirtualizedList
1486
- data={[...items, {key: 'i4'}]}
1487
- renderItem={({item}) => <item value={item.key} />}
1488
- getItem={(data, index) => data[index]}
1489
- getItemCount={data => data.length}
1490
- />,
1491
- );
1492
- const cell = virtualList._cellRefs.i4;
1493
- const event = {
1494
- nativeEvent: {layout: {x: 0, y: 0, width: 50, height: 50}, zoomScale: 1},
1495
- };
1496
- cell._onLayout(event);
1497
- expect(mock).toHaveBeenCalledWith(event, 'i4', 3);
1498
- expect(mock).not.toHaveBeenCalledWith(event, 'i3', 2);
1499
- });
1500
-
1501
- function generateItems(count) {
1502
- return Array(count)
1503
- .fill()
1504
- .map((_, i) => ({key: i}));
1505
- }
1506
-
1507
- function generateItemsStickyEveryN(count, n) {
1508
- return Array(count)
1509
- .fill()
1510
- .map((_, i) => (i % n === 0 ? {key: i, sticky: true} : {key: i}));
1511
- }
1512
-
1513
- function baseItemProps(items) {
1514
- return {
1515
- data: items,
1516
- renderItem: ({item}) =>
1517
- React.createElement('MockCellItem', {value: item.key, ...item}),
1518
- getItem: (data, index) => data[index],
1519
- getItemCount: data => data.length,
1520
- stickyHeaderIndices: stickyHeaderIndices(items),
1521
- };
1522
- }
1523
-
1524
- function stickyHeaderIndices(items) {
1525
- return items.filter(item => item.sticky).map(item => item.key);
1526
- }
1527
-
1528
- function fixedHeightItemLayoutProps(height) {
1529
- return {
1530
- getItemLayout: (_, index) => ({
1531
- length: height,
1532
- offset: height * index,
1533
- index,
1534
- }),
1535
- };
1536
- }
1537
-
1538
- let lastViewportLayout;
1539
- let lastContentLayout;
1540
-
1541
- function simulateLayout(component, args) {
1542
- simulateViewportLayout(component, args.viewport);
1543
- simulateContentLayout(component, args.content);
1544
- }
1545
-
1546
- function simulateViewportLayout(component, dimensions) {
1547
- lastViewportLayout = dimensions;
1548
- component
1549
- .getInstance()
1550
- ._onLayout({nativeEvent: {layout: dimensions}, zoomScale: 1});
1551
- }
1552
-
1553
- function simulateContentLayout(component, dimensions) {
1554
- lastContentLayout = dimensions;
1555
- component
1556
- .getInstance()
1557
- ._onContentSizeChange(dimensions.width, dimensions.height);
1558
- }
1559
-
1560
- function simulateCellLayout(component, items, itemIndex, dimensions) {
1561
- const instance = component.getInstance();
1562
- const cellKey = instance._keyExtractor(items[itemIndex], itemIndex);
1563
- instance._onCellLayout(
1564
- {nativeEvent: {layout: dimensions, zoomScale: 1}},
1565
- cellKey,
1566
- itemIndex,
1567
- );
1568
- }
1569
-
1570
- function simulateScroll(component, position) {
1571
- component.getInstance()._onScroll({
1572
- nativeEvent: {
1573
- contentOffset: position,
1574
- contentSize: lastContentLayout,
1575
- layoutMeasurement: lastViewportLayout,
1576
- zoomScale: 1,
1577
- },
1578
- });
1579
- }
1580
-
1581
- function performAllBatches() {
1582
- jest.runAllTimers();
1583
- }
1584
-
1585
- function performNextBatch() {
1586
- jest.runOnlyPendingTimers();
1587
- }