react-native-list 1.0.0 → 2.0.0-alpha.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 (200) hide show
  1. package/README.md +190 -32
  2. package/ReactNativeList.podspec +39 -0
  3. package/android/CMakeLists.txt +48 -0
  4. package/android/build.gradle +151 -0
  5. package/android/fix-prefab.gradle +51 -0
  6. package/android/gradle.properties +5 -0
  7. package/android/src/main/AndroidManifest.xml +2 -0
  8. package/android/src/main/cpp/JHybridUiListModule.cpp +192 -0
  9. package/android/src/main/cpp/JHybridUiListModule.h +50 -0
  10. package/android/src/main/cpp/cpp-adapter.cpp +12 -0
  11. package/android/src/main/java/com/hannojg/reactnativelist/ReactNativeListPackage.kt +27 -0
  12. package/android/src/main/java/com/margelo/nitro/reactnativelist/HybridNativeListDataSource.kt +146 -0
  13. package/android/src/main/java/com/margelo/nitro/reactnativelist/HybridNativeListLayout.kt +86 -0
  14. package/android/src/main/java/com/margelo/nitro/reactnativelist/HybridUiListModule.kt +116 -0
  15. package/android/src/main/java/com/margelo/nitro/reactnativelist/HybridUiListView.kt +410 -0
  16. package/android/src/main/java/com/margelo/nitro/reactnativelist/HybridViewHolder.kt +9 -0
  17. package/android/src/main/java/com/margelo/nitro/reactnativelist/NativeListAdapter.kt +217 -0
  18. package/ios/DataSource/HybridNativeListDataSource.swift +213 -0
  19. package/ios/HybridObjects/HybridUiListModule.swift +49 -0
  20. package/ios/HybridObjects/HybridViewHolder.swift +16 -0
  21. package/ios/Layout/HybridNativeListLayout.swift +128 -0
  22. package/ios/Utils/ErrorUtils.h +26 -0
  23. package/ios/Utils/HybridIOSWorkletsModuleProxyHolder.swift +10 -0
  24. package/ios/Utils/SurfaceHelper.h +20 -0
  25. package/ios/Utils/SurfaceHelper.mm +144 -0
  26. package/ios/Utils/SurfacePresenterRegistry.h +17 -0
  27. package/ios/Utils/SurfacePresenterRegistry.m +31 -0
  28. package/ios/Utils/TurboModuleInstaller.h +18 -0
  29. package/ios/Utils/TurboModuleInstaller.mm +267 -0
  30. package/ios/Views/HostCell.swift +216 -0
  31. package/ios/Views/HybridUiListView.swift +695 -0
  32. package/metro/RendererProxyThreadSwitch.js +66 -0
  33. package/metro-config.d.ts +1 -0
  34. package/metro-config.js +52 -0
  35. package/nitro.json +47 -0
  36. package/nitrogen/generated/.gitattributes +1 -0
  37. package/nitrogen/generated/android/ReactNativeList+autolinking.cmake +99 -0
  38. package/nitrogen/generated/android/ReactNativeList+autolinking.gradle +27 -0
  39. package/nitrogen/generated/android/ReactNativeListOnLoad.cpp +156 -0
  40. package/nitrogen/generated/android/ReactNativeListOnLoad.hpp +34 -0
  41. package/nitrogen/generated/android/c++/JFunc_bool_NativeListItem_NativeListItem.hpp +83 -0
  42. package/nitrogen/generated/android/c++/JFunc_bool_double_NativeListItem_double.hpp +83 -0
  43. package/nitrogen/generated/android/c++/JFunc_double_std__string.hpp +78 -0
  44. package/nitrogen/generated/android/c++/JHybridIOSWorkletsModuleProxyHolderSpec.cpp +49 -0
  45. package/nitrogen/generated/android/c++/JHybridIOSWorkletsModuleProxyHolderSpec.hpp +63 -0
  46. package/nitrogen/generated/android/c++/JHybridNativeLinearListLayoutSpec.cpp +63 -0
  47. package/nitrogen/generated/android/c++/JHybridNativeLinearListLayoutSpec.hpp +65 -0
  48. package/nitrogen/generated/android/c++/JHybridNativeListDataSourceSpec.cpp +101 -0
  49. package/nitrogen/generated/android/c++/JHybridNativeListDataSourceSpec.hpp +70 -0
  50. package/nitrogen/generated/android/c++/JHybridNativeListLayoutSpec.cpp +49 -0
  51. package/nitrogen/generated/android/c++/JHybridNativeListLayoutSpec.hpp +63 -0
  52. package/nitrogen/generated/android/c++/JHybridUiListModuleSpec.cpp +65 -0
  53. package/nitrogen/generated/android/c++/JHybridUiListModuleSpec.hpp +64 -0
  54. package/nitrogen/generated/android/c++/JHybridUiListViewSpec.cpp +92 -0
  55. package/nitrogen/generated/android/c++/JHybridUiListViewSpec.hpp +67 -0
  56. package/nitrogen/generated/android/c++/JHybridViewHolderSpec.cpp +49 -0
  57. package/nitrogen/generated/android/c++/JHybridViewHolderSpec.hpp +63 -0
  58. package/nitrogen/generated/android/c++/JNativeItemSizeEstimate.hpp +61 -0
  59. package/nitrogen/generated/android/c++/JNativeLinearListLayoutConfig.hpp +81 -0
  60. package/nitrogen/generated/android/c++/JNativeLinearListLayoutIOSConfig.hpp +59 -0
  61. package/nitrogen/generated/android/c++/JNativeListItem.hpp +76 -0
  62. package/nitrogen/generated/android/c++/JVariant_NullType_HybridIOSWorkletsModuleProxyHolderSpec.cpp +26 -0
  63. package/nitrogen/generated/android/c++/JVariant_NullType_HybridIOSWorkletsModuleProxyHolderSpec.hpp +72 -0
  64. package/nitrogen/generated/android/c++/views/JHybridUiListViewStateUpdater.cpp +53 -0
  65. package/nitrogen/generated/android/c++/views/JHybridUiListViewStateUpdater.hpp +49 -0
  66. package/nitrogen/generated/android/c++/views/JHybridViewHolderStateUpdater.cpp +53 -0
  67. package/nitrogen/generated/android/c++/views/JHybridViewHolderStateUpdater.hpp +49 -0
  68. package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativelist/Func_bool_NativeListItem_NativeListItem.kt +80 -0
  69. package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativelist/Func_bool_double_NativeListItem_double.kt +80 -0
  70. package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativelist/Func_double_std__string.kt +80 -0
  71. package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativelist/HybridIOSWorkletsModuleProxyHolderSpec.kt +52 -0
  72. package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativelist/HybridNativeLinearListLayoutSpec.kt +54 -0
  73. package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativelist/HybridNativeListDataSourceSpec.kt +87 -0
  74. package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativelist/HybridNativeListLayoutSpec.kt +52 -0
  75. package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativelist/HybridUiListModuleSpec.kt +59 -0
  76. package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativelist/HybridUiListViewSpec.kt +76 -0
  77. package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativelist/HybridViewHolderSpec.kt +53 -0
  78. package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativelist/NativeItemSizeEstimate.kt +56 -0
  79. package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativelist/NativeLinearListLayoutConfig.kt +76 -0
  80. package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativelist/NativeLinearListLayoutIOSConfig.kt +51 -0
  81. package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativelist/NativeListItem.kt +71 -0
  82. package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativelist/ReactNativeListOnLoad.kt +35 -0
  83. package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativelist/Variant_NullType_HybridIOSWorkletsModuleProxyHolderSpec.kt +62 -0
  84. package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativelist/views/HybridUiListViewManager.kt +80 -0
  85. package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativelist/views/HybridUiListViewStateUpdater.kt +23 -0
  86. package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativelist/views/HybridViewHolderManager.kt +80 -0
  87. package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativelist/views/HybridViewHolderStateUpdater.kt +23 -0
  88. package/nitrogen/generated/ios/ReactNativeList+autolinking.rb +62 -0
  89. package/nitrogen/generated/ios/ReactNativeList-Swift-Cxx-Bridge.cpp +162 -0
  90. package/nitrogen/generated/ios/ReactNativeList-Swift-Cxx-Bridge.hpp +368 -0
  91. package/nitrogen/generated/ios/ReactNativeList-Swift-Cxx-Umbrella.hpp +92 -0
  92. package/nitrogen/generated/ios/ReactNativeListAutolinking.mm +83 -0
  93. package/nitrogen/generated/ios/ReactNativeListAutolinking.swift +86 -0
  94. package/nitrogen/generated/ios/c++/HybridIOSWorkletsModuleProxyHolderSpecSwift.cpp +11 -0
  95. package/nitrogen/generated/ios/c++/HybridIOSWorkletsModuleProxyHolderSpecSwift.hpp +75 -0
  96. package/nitrogen/generated/ios/c++/HybridNativeLinearListLayoutSpecSwift.cpp +11 -0
  97. package/nitrogen/generated/ios/c++/HybridNativeLinearListLayoutSpecSwift.hpp +92 -0
  98. package/nitrogen/generated/ios/c++/HybridNativeListDataSourceSpecSwift.cpp +11 -0
  99. package/nitrogen/generated/ios/c++/HybridNativeListDataSourceSpecSwift.hpp +132 -0
  100. package/nitrogen/generated/ios/c++/HybridNativeListLayoutSpecSwift.cpp +11 -0
  101. package/nitrogen/generated/ios/c++/HybridNativeListLayoutSpecSwift.hpp +75 -0
  102. package/nitrogen/generated/ios/c++/HybridUiListModuleSpecSwift.cpp +11 -0
  103. package/nitrogen/generated/ios/c++/HybridUiListModuleSpecSwift.hpp +93 -0
  104. package/nitrogen/generated/ios/c++/HybridUiListViewSpecSwift.cpp +11 -0
  105. package/nitrogen/generated/ios/c++/HybridUiListViewSpecSwift.hpp +121 -0
  106. package/nitrogen/generated/ios/c++/HybridViewHolderSpecSwift.cpp +11 -0
  107. package/nitrogen/generated/ios/c++/HybridViewHolderSpecSwift.hpp +75 -0
  108. package/nitrogen/generated/ios/c++/views/HybridUiListViewComponent.mm +118 -0
  109. package/nitrogen/generated/ios/c++/views/HybridViewHolderComponent.mm +118 -0
  110. package/nitrogen/generated/ios/swift/Func_bool_NativeListItem_NativeListItem.swift +47 -0
  111. package/nitrogen/generated/ios/swift/Func_bool_double_NativeListItem_double.swift +47 -0
  112. package/nitrogen/generated/ios/swift/Func_double_std__string.swift +47 -0
  113. package/nitrogen/generated/ios/swift/HybridIOSWorkletsModuleProxyHolderSpec.swift +55 -0
  114. package/nitrogen/generated/ios/swift/HybridIOSWorkletsModuleProxyHolderSpec_cxx.swift +128 -0
  115. package/nitrogen/generated/ios/swift/HybridNativeLinearListLayoutSpec.swift +55 -0
  116. package/nitrogen/generated/ios/swift/HybridNativeLinearListLayoutSpec_cxx.swift +140 -0
  117. package/nitrogen/generated/ios/swift/HybridNativeListDataSourceSpec.swift +62 -0
  118. package/nitrogen/generated/ios/swift/HybridNativeListDataSourceSpec_cxx.swift +222 -0
  119. package/nitrogen/generated/ios/swift/HybridNativeListLayoutSpec.swift +55 -0
  120. package/nitrogen/generated/ios/swift/HybridNativeListLayoutSpec_cxx.swift +128 -0
  121. package/nitrogen/generated/ios/swift/HybridUiListModuleSpec.swift +56 -0
  122. package/nitrogen/generated/ios/swift/HybridUiListModuleSpec_cxx.swift +175 -0
  123. package/nitrogen/generated/ios/swift/HybridUiListViewSpec.swift +59 -0
  124. package/nitrogen/generated/ios/swift/HybridUiListViewSpec_cxx.swift +227 -0
  125. package/nitrogen/generated/ios/swift/HybridViewHolderSpec.swift +55 -0
  126. package/nitrogen/generated/ios/swift/HybridViewHolderSpec_cxx.swift +147 -0
  127. package/nitrogen/generated/ios/swift/NativeItemSizeEstimate.swift +60 -0
  128. package/nitrogen/generated/ios/swift/NativeLinearListLayoutConfig.swift +60 -0
  129. package/nitrogen/generated/ios/swift/NativeLinearListLayoutIOSConfig.swift +35 -0
  130. package/nitrogen/generated/ios/swift/NativeListItem.swift +75 -0
  131. package/nitrogen/generated/ios/swift/Variant_NullType__any_HybridIOSWorkletsModuleProxyHolderSpec_.swift +30 -0
  132. package/nitrogen/generated/shared/c++/HybridIOSWorkletsModuleProxyHolderSpec.cpp +21 -0
  133. package/nitrogen/generated/shared/c++/HybridIOSWorkletsModuleProxyHolderSpec.hpp +62 -0
  134. package/nitrogen/generated/shared/c++/HybridNativeLinearListLayoutSpec.cpp +22 -0
  135. package/nitrogen/generated/shared/c++/HybridNativeLinearListLayoutSpec.hpp +67 -0
  136. package/nitrogen/generated/shared/c++/HybridNativeListDataSourceSpec.cpp +28 -0
  137. package/nitrogen/generated/shared/c++/HybridNativeListDataSourceSpec.hpp +72 -0
  138. package/nitrogen/generated/shared/c++/HybridNativeListLayoutSpec.cpp +21 -0
  139. package/nitrogen/generated/shared/c++/HybridNativeListLayoutSpec.hpp +62 -0
  140. package/nitrogen/generated/shared/c++/HybridUiListModuleSpec.cpp +22 -0
  141. package/nitrogen/generated/shared/c++/HybridUiListModuleSpec.hpp +68 -0
  142. package/nitrogen/generated/shared/c++/HybridUiListViewSpec.cpp +25 -0
  143. package/nitrogen/generated/shared/c++/HybridUiListViewSpec.hpp +79 -0
  144. package/nitrogen/generated/shared/c++/HybridUiManagerHelperSpec.cpp +23 -0
  145. package/nitrogen/generated/shared/c++/HybridUiManagerHelperSpec.hpp +65 -0
  146. package/nitrogen/generated/shared/c++/HybridViewHolderSpec.cpp +21 -0
  147. package/nitrogen/generated/shared/c++/HybridViewHolderSpec.hpp +62 -0
  148. package/nitrogen/generated/shared/c++/NativeItemSizeEstimate.hpp +87 -0
  149. package/nitrogen/generated/shared/c++/NativeLinearListLayoutConfig.hpp +105 -0
  150. package/nitrogen/generated/shared/c++/NativeLinearListLayoutIOSConfig.hpp +85 -0
  151. package/nitrogen/generated/shared/c++/NativeListItem.hpp +101 -0
  152. package/nitrogen/generated/shared/c++/views/HybridUiListViewComponent.cpp +72 -0
  153. package/nitrogen/generated/shared/c++/views/HybridUiListViewComponent.hpp +109 -0
  154. package/nitrogen/generated/shared/c++/views/HybridViewHolderComponent.cpp +72 -0
  155. package/nitrogen/generated/shared/c++/views/HybridViewHolderComponent.hpp +109 -0
  156. package/nitrogen/generated/shared/json/UiListViewConfig.json +9 -0
  157. package/nitrogen/generated/shared/json/ViewHolderConfig.json +9 -0
  158. package/package.json +152 -5
  159. package/react-native.config.js +16 -0
  160. package/src/ListDataSource.ts +232 -0
  161. package/src/ListLayout.ts +95 -0
  162. package/src/UiListModule.ts +5 -0
  163. package/src/hooks/useChangeEffect.ts +50 -0
  164. package/src/index.tsx +49 -0
  165. package/src/privateGlobals.ts +20 -0
  166. package/src/renderer/fabric/RenderHelper.ts +29 -0
  167. package/src/renderer/fabric/UiManagerHelper.ts +5 -0
  168. package/src/renderer/react/ReactFabricMirror.bundle.js +1984 -0
  169. package/src/renderer/react/ReactFabricMirror.ts +766 -0
  170. package/src/renderer/react/ReactFabricRenderer.ts +11 -0
  171. package/src/specs/IOSWorkletsModuleProxyHolder.nitro.ts +6 -0
  172. package/src/specs/NativeLinearListLayout.nitro.ts +23 -0
  173. package/src/specs/NativeListDataSource.nitro.ts +28 -0
  174. package/src/specs/NativeListLayout.nitro.ts +6 -0
  175. package/src/specs/UIListModule.nitro.ts +13 -0
  176. package/src/specs/UIManagerHelper.nitro.ts +34 -0
  177. package/src/specs/UiListView.nitro.ts +31 -0
  178. package/src/specs/ViewHolder.nitro.ts +11 -0
  179. package/src/views/List.tsx +525 -0
  180. package/src/views/UiListHostComponent.ts +8 -0
  181. package/FillRateHelper.js +0 -179
  182. package/FlatList.js +0 -494
  183. package/LICENSE.md +0 -31
  184. package/ListView/__mocks__/ListViewMock.js +0 -55
  185. package/MetroListView.js +0 -166
  186. package/SectionList.js +0 -291
  187. package/ViewabilityHelper.js +0 -260
  188. package/VirtualizeUtils.js +0 -163
  189. package/VirtualizedList.js +0 -861
  190. package/VirtualizedSectionList.js +0 -397
  191. package/__flowtests__/FlatList-flowtest.js +0 -90
  192. package/__flowtests__/SectionList-flowtest.js +0 -89
  193. package/__tests__/FillRateHelper-test.js +0 -106
  194. package/__tests__/FlatList-test.js +0 -64
  195. package/__tests__/SectionList-test.js +0 -67
  196. package/__tests__/ViewabilityHelper-test.js +0 -359
  197. package/__tests__/VirtualizeUtils-test.js +0 -74
  198. package/__tests__/__snapshots__/FlatList-test.js.snap +0 -251
  199. package/__tests__/__snapshots__/SectionList-test.js.snap +0 -283
  200. package/index.js +0 -5
@@ -1,64 +0,0 @@
1
- /**
2
- * Copyright (c) 2015-present, Facebook, Inc.
3
- * All rights reserved.
4
- *
5
- * This source code is licensed under the BSD-style license found in the
6
- * LICENSE file in the root directory of this source tree. An additional grant
7
- * of patent rights can be found in the PATENTS file in the same directory.
8
- *
9
- */
10
- 'use strict';
11
-
12
- jest.disableAutomock();
13
-
14
- const React = require('React');
15
- const ReactTestRenderer = require('react-test-renderer');
16
-
17
- const FlatList = require('FlatList');
18
-
19
- describe('FlatList', () => {
20
- it('renders simple list', () => {
21
- const component = ReactTestRenderer.create(
22
- <FlatList
23
- data={[{key: 'i1'}, {key: 'i2'}, {key: 'i3'}]}
24
- renderItem={({item}) => <item value={item.key} />}
25
- />
26
- );
27
- expect(component).toMatchSnapshot();
28
- });
29
- it('renders empty list', () => {
30
- const component = ReactTestRenderer.create(
31
- <FlatList
32
- data={[]}
33
- renderItem={({item}) => <item value={item.key} />}
34
- />
35
- );
36
- expect(component).toMatchSnapshot();
37
- });
38
- it('renders null list', () => {
39
- const component = ReactTestRenderer.create(
40
- <FlatList
41
- data={undefined}
42
- renderItem={({item}) => <item value={item.key} />}
43
- />
44
- );
45
- expect(component).toMatchSnapshot();
46
- });
47
- it('renders all the bells and whistles', () => {
48
- const component = ReactTestRenderer.create(
49
- <FlatList
50
- ItemSeparatorComponent={() => <separator />}
51
- ListFooterComponent={() => <footer />}
52
- ListHeaderComponent={() => <header />}
53
- data={new Array(5).fill().map((_, ii) => ({id: String(ii)}))}
54
- keyExtractor={(item, index) => item.id}
55
- getItemLayout={({index}) => ({length: 50, offset: index * 50})}
56
- numColumns={2}
57
- refreshing={false}
58
- onRefresh={jest.fn()}
59
- renderItem={({item}) => <item value={item.id} />}
60
- />
61
- );
62
- expect(component).toMatchSnapshot();
63
- });
64
- });
@@ -1,67 +0,0 @@
1
- /**
2
- * Copyright (c) 2015-present, Facebook, Inc.
3
- * All rights reserved.
4
- *
5
- * This source code is licensed under the BSD-style license found in the
6
- * LICENSE file in the root directory of this source tree. An additional grant
7
- * of patent rights can be found in the PATENTS file in the same directory.
8
- *
9
- */
10
- 'use strict';
11
-
12
- jest.disableAutomock();
13
-
14
- const React = require('React');
15
- const ReactTestRenderer = require('react-test-renderer');
16
-
17
- const SectionList = require('SectionList');
18
-
19
- describe('SectionList', () => {
20
- it('renders empty list', () => {
21
- const component = ReactTestRenderer.create(
22
- <SectionList
23
- sections={[]}
24
- renderItem={({item}) => <item value={item.key} />}
25
- />
26
- );
27
- expect(component).toMatchSnapshot();
28
- });
29
- it('rendering empty section headers is fine', () => {
30
- const component = ReactTestRenderer.create(
31
- <SectionList
32
- sections={[{key: 's1', data: [{key: 'i1'}, {key: 'i2'}]}]}
33
- renderItem={({item}) => <item value={item.key} />}
34
- renderSectionHeader={() => null}
35
- />
36
- );
37
- expect(component).toMatchSnapshot();
38
- });
39
- it('renders all the bells and whistles', () => {
40
- const component = ReactTestRenderer.create(
41
- <SectionList
42
- ItemSeparatorComponent={() => <defaultItemSeparator />}
43
- ListFooterComponent={() => <footer />}
44
- ListHeaderComponent={() => <header />}
45
- SectionSeparatorComponent={() => <sectionSeparator />}
46
- sections={[
47
- {
48
- renderItem: ({item}) => <itemForSection1 value={item.id} />,
49
- key: '1st Section',
50
- keyExtractor: (item, index) => item.id,
51
- ItemSeparatorComponent: () => <itemSeparatorForSection1 />,
52
- data: [{id: 'i1s1'}, {id: 'i2s1'}],
53
- },
54
- {
55
- key: '2nd Section',
56
- data: [{key: 'i1s2'}, {key: 'i2s2'}],
57
- },
58
- ]}
59
- refreshing={false}
60
- onRefresh={jest.fn()}
61
- renderItem={({item}) => <defaultItem value={item.key} />}
62
- renderSectionHeader={({section}) => <sectionHeader value={section.key} />}
63
- />
64
- );
65
- expect(component).toMatchSnapshot();
66
- });
67
- });
@@ -1,359 +0,0 @@
1
- /**
2
- * Copyright (c) 2015-present, Facebook, Inc.
3
- * All rights reserved.
4
- *
5
- * This source code is licensed under the BSD-style license found in the
6
- * LICENSE file in the root directory of this source tree. An additional grant
7
- * of patent rights can be found in the PATENTS file in the same directory.
8
- *
9
- */
10
- 'use strict';
11
-
12
- jest.unmock('ViewabilityHelper');
13
-
14
- const ViewabilityHelper = require('ViewabilityHelper');
15
-
16
- let rowFrames;
17
- let data;
18
- function getFrameMetrics(index: number) {
19
- const frame = rowFrames[data[index].key];
20
- return {length: frame.height, offset: frame.y};
21
- }
22
- function createViewToken(index: number, isViewable: boolean) {
23
- return {key: data[index].key, isViewable};
24
- }
25
-
26
- describe('computeViewableItems', function() {
27
- it('returns all 4 entirely visible rows as viewable', function() {
28
- const helper = new ViewabilityHelper({viewAreaCoveragePercentThreshold: 50});
29
- rowFrames = {
30
- a: {y: 0, height: 50},
31
- b: {y: 50, height: 50},
32
- c: {y: 100, height: 50},
33
- d: {y: 150, height: 50},
34
- };
35
- data = [{key: 'a'}, {key: 'b'}, {key: 'c'}, {key: 'd'}];
36
- expect(helper.computeViewableItems(data.length, 0, 200, getFrameMetrics))
37
- .toEqual([0, 1, 2, 3]);
38
- });
39
-
40
- it(
41
- 'returns top 2 rows as viewable (1. entirely visible and 2. majority)',
42
- function() {
43
- const helper = new ViewabilityHelper({viewAreaCoveragePercentThreshold: 50});
44
- rowFrames = {
45
- a: {y: 0, height: 50},
46
- b: {y: 50, height: 150},
47
- c: {y: 200, height: 50},
48
- d: {y: 250, height: 50},
49
- };
50
- data = [{key: 'a'}, {key: 'b'}, {key: 'c'}, {key: 'd'}];
51
- expect(helper.computeViewableItems(data.length, 0, 200, getFrameMetrics))
52
- .toEqual([0, 1]);
53
- });
54
-
55
- it(
56
- 'returns only 2nd row as viewable (majority)',
57
- function() {
58
- const helper = new ViewabilityHelper({viewAreaCoveragePercentThreshold: 50});
59
- rowFrames = {
60
- a: {y: 0, height: 50},
61
- b: {y: 50, height: 150},
62
- c: {y: 200, height: 50},
63
- d: {y: 250, height: 50},
64
- };
65
- data = [{key: 'a'}, {key: 'b'}, {key: 'c'}, {key: 'd'}];
66
- expect(helper.computeViewableItems(data.length, 25, 200, getFrameMetrics))
67
- .toEqual([1]);
68
- });
69
-
70
- it(
71
- 'handles empty input',
72
- function() {
73
- const helper = new ViewabilityHelper({viewAreaCoveragePercentThreshold: 50});
74
- rowFrames = {};
75
- data = [];
76
- expect(helper.computeViewableItems(data.length, 0, 200, getFrameMetrics))
77
- .toEqual([]);
78
- });
79
-
80
- it(
81
- 'handles different view area coverage percent thresholds',
82
- function() {
83
- rowFrames = {
84
- a: {y: 0, height: 50},
85
- b: {y: 50, height: 150},
86
- c: {y: 200, height: 500},
87
- d: {y: 700, height: 50},
88
- };
89
- data = [{key: 'a'}, {key: 'b'}, {key: 'c'}, {key: 'd'}];
90
-
91
- let helper = new ViewabilityHelper({viewAreaCoveragePercentThreshold: 0});
92
- expect(helper.computeViewableItems(data.length, 0, 50, getFrameMetrics))
93
- .toEqual([0]);
94
- expect(helper.computeViewableItems(data.length, 1, 50, getFrameMetrics))
95
- .toEqual([0, 1]);
96
- expect(helper.computeViewableItems(data.length, 199, 50, getFrameMetrics))
97
- .toEqual([1, 2]);
98
- expect(helper.computeViewableItems(data.length, 250, 50, getFrameMetrics))
99
- .toEqual([2]);
100
-
101
- helper = new ViewabilityHelper({viewAreaCoveragePercentThreshold: 100});
102
- expect(helper.computeViewableItems(data.length, 0, 200, getFrameMetrics))
103
- .toEqual([0, 1]);
104
- expect(helper.computeViewableItems(data.length, 1, 200, getFrameMetrics))
105
- .toEqual([1]);
106
- expect(helper.computeViewableItems(data.length, 400, 200, getFrameMetrics))
107
- .toEqual([2]);
108
- expect(helper.computeViewableItems(data.length, 600, 200, getFrameMetrics))
109
- .toEqual([3]);
110
-
111
- helper = new ViewabilityHelper({viewAreaCoveragePercentThreshold: 10});
112
- expect(helper.computeViewableItems(data.length, 30, 200, getFrameMetrics))
113
- .toEqual([0, 1, 2]);
114
- expect(helper.computeViewableItems(data.length, 31, 200, getFrameMetrics))
115
- .toEqual([1, 2]);
116
- });
117
-
118
- it(
119
- 'handles different item visible percent thresholds',
120
- function() {
121
- rowFrames = {
122
- a: {y: 0, height: 50},
123
- b: {y: 50, height: 150},
124
- c: {y: 200, height: 50},
125
- d: {y: 250, height: 50},
126
- };
127
- data = [{key: 'a'}, {key: 'b'}, {key: 'c'}, {key: 'd'}];
128
- let helper = new ViewabilityHelper({itemVisiblePercentThreshold: 0});
129
- expect(helper.computeViewableItems(data.length, 0, 50, getFrameMetrics))
130
- .toEqual([0]);
131
- expect(helper.computeViewableItems(data.length, 1, 50, getFrameMetrics))
132
- .toEqual([0, 1]);
133
-
134
- helper = new ViewabilityHelper({itemVisiblePercentThreshold: 100});
135
- expect(helper.computeViewableItems(data.length, 0, 250, getFrameMetrics))
136
- .toEqual([0, 1, 2]);
137
- expect(helper.computeViewableItems(data.length, 1, 250, getFrameMetrics))
138
- .toEqual([1, 2]);
139
-
140
- helper = new ViewabilityHelper({itemVisiblePercentThreshold: 10});
141
- expect(helper.computeViewableItems(data.length, 184, 20, getFrameMetrics))
142
- .toEqual([1]);
143
- expect(helper.computeViewableItems(data.length, 185, 20, getFrameMetrics))
144
- .toEqual([1, 2]);
145
- expect(helper.computeViewableItems(data.length, 186, 20, getFrameMetrics))
146
- .toEqual([2]);
147
- });
148
- });
149
-
150
- describe('onUpdate', function() {
151
- it(
152
- 'returns 1 visible row as viewable then scrolls away',
153
- function() {
154
- const helper = new ViewabilityHelper();
155
- rowFrames = {
156
- a: {y: 0, height: 50},
157
- };
158
- data = [{key: 'a'}];
159
- const onViewableItemsChanged = jest.fn();
160
- helper.onUpdate(
161
- data.length,
162
- 0,
163
- 200,
164
- getFrameMetrics,
165
- createViewToken,
166
- onViewableItemsChanged,
167
- );
168
- expect(onViewableItemsChanged.mock.calls.length).toBe(1);
169
- expect(onViewableItemsChanged.mock.calls[0][0]).toEqual({
170
- changed: [{isViewable: true, key: 'a'}],
171
- viewableItems: [{isViewable: true, key: 'a'}],
172
- });
173
- helper.onUpdate(
174
- data.length,
175
- 0,
176
- 200,
177
- getFrameMetrics,
178
- createViewToken,
179
- onViewableItemsChanged,
180
- );
181
- expect(onViewableItemsChanged.mock.calls.length).toBe(1); // nothing changed!
182
- helper.onUpdate(
183
- data.length,
184
- 100,
185
- 200,
186
- getFrameMetrics,
187
- createViewToken,
188
- onViewableItemsChanged,
189
- );
190
- expect(onViewableItemsChanged.mock.calls.length).toBe(2);
191
- expect(onViewableItemsChanged.mock.calls[1][0]).toEqual({
192
- changed: [{isViewable: false, key: 'a'}],
193
- viewableItems: [],
194
- });
195
- },
196
- );
197
-
198
- it(
199
- 'returns 1st visible row then 1st and 2nd then just 2nd',
200
- function() {
201
- const helper = new ViewabilityHelper();
202
- rowFrames = {
203
- a: {y: 0, height: 200},
204
- b: {y: 200, height: 200},
205
- };
206
- data = [{key: 'a'}, {key: 'b'}];
207
- const onViewableItemsChanged = jest.fn();
208
- helper.onUpdate(
209
- data.length,
210
- 0,
211
- 200,
212
- getFrameMetrics,
213
- createViewToken,
214
- onViewableItemsChanged,
215
- );
216
- expect(onViewableItemsChanged.mock.calls.length).toBe(1);
217
- expect(onViewableItemsChanged.mock.calls[0][0]).toEqual({
218
- changed: [{isViewable: true, key: 'a'}],
219
- viewableItems: [{isViewable: true, key: 'a'}],
220
- });
221
- helper.onUpdate(
222
- data.length,
223
- 100,
224
- 200,
225
- getFrameMetrics,
226
- createViewToken,
227
- onViewableItemsChanged,
228
- );
229
- expect(onViewableItemsChanged.mock.calls.length).toBe(2);
230
- // Both visible with 100px overlap each
231
- expect(onViewableItemsChanged.mock.calls[1][0]).toEqual({
232
- changed: [{isViewable: true, key: 'b'}],
233
- viewableItems: [{isViewable: true, key: 'a'}, {isViewable: true, key: 'b'}],
234
- });
235
- helper.onUpdate(
236
- data.length,
237
- 200,
238
- 200,
239
- getFrameMetrics,
240
- createViewToken,
241
- onViewableItemsChanged,
242
- );
243
- expect(onViewableItemsChanged.mock.calls.length).toBe(3);
244
- expect(onViewableItemsChanged.mock.calls[2][0]).toEqual({
245
- changed: [{isViewable: false, key: 'a'}],
246
- viewableItems: [{isViewable: true, key: 'b'}],
247
- });
248
- },
249
- );
250
-
251
- it(
252
- 'minimumViewTime delays callback',
253
- function() {
254
- const helper = new ViewabilityHelper({minimumViewTime: 350, viewAreaCoveragePercentThreshold: 0});
255
- rowFrames = {
256
- a: {y: 0, height: 200},
257
- b: {y: 200, height: 200},
258
- };
259
- data = [{key: 'a'}, {key: 'b'}];
260
- const onViewableItemsChanged = jest.fn();
261
- helper.onUpdate(
262
- data.length,
263
- 0,
264
- 200,
265
- getFrameMetrics,
266
- createViewToken,
267
- onViewableItemsChanged,
268
- );
269
- expect(onViewableItemsChanged).not.toBeCalled();
270
-
271
- jest.runAllTimers();
272
-
273
- expect(onViewableItemsChanged.mock.calls.length).toBe(1);
274
- expect(onViewableItemsChanged.mock.calls[0][0]).toEqual({
275
- changed: [{isViewable: true, key: 'a'}],
276
- viewableItems: [{isViewable: true, key: 'a'}],
277
- });
278
- }
279
- );
280
-
281
- it(
282
- 'minimumViewTime skips briefly visible items',
283
- function() {
284
- const helper = new ViewabilityHelper({minimumViewTime: 350, viewAreaCoveragePercentThreshold: 0});
285
- rowFrames = {
286
- a: {y: 0, height: 250},
287
- b: {y: 250, height: 200},
288
- };
289
- data = [{key: 'a'}, {key: 'b'}];
290
- const onViewableItemsChanged = jest.fn();
291
- helper.onUpdate(
292
- data.length,
293
- 0,
294
- 200,
295
- getFrameMetrics,
296
- createViewToken,
297
- onViewableItemsChanged,
298
- );
299
- helper.onUpdate(
300
- data.length,
301
- 300, // scroll past item 'a'
302
- 200,
303
- getFrameMetrics,
304
- createViewToken,
305
- onViewableItemsChanged,
306
- );
307
-
308
- jest.runAllTimers();
309
-
310
- expect(onViewableItemsChanged.mock.calls.length).toBe(1);
311
- expect(onViewableItemsChanged.mock.calls[0][0]).toEqual({
312
- changed: [{isViewable: true, key: 'b'}],
313
- viewableItems: [{isViewable: true, key: 'b'}],
314
- });
315
- }
316
- );
317
-
318
- it(
319
- 'waitForInteraction blocks callback until interaction',
320
- function() {
321
- const helper = new ViewabilityHelper({
322
- waitForInteraction: true,
323
- viewAreaCoveragePercentThreshold: 0,
324
- });
325
- rowFrames = {
326
- a: {y: 0, height: 200},
327
- b: {y: 200, height: 200},
328
- };
329
- data = [{key: 'a'}, {key: 'b'}];
330
- const onViewableItemsChanged = jest.fn();
331
- helper.onUpdate(
332
- data.length,
333
- 0,
334
- 100,
335
- getFrameMetrics,
336
- createViewToken,
337
- onViewableItemsChanged,
338
- );
339
- expect(onViewableItemsChanged).not.toBeCalled();
340
-
341
- helper.recordInteraction();
342
-
343
- helper.onUpdate(
344
- data.length,
345
- 20,
346
- 100,
347
- getFrameMetrics,
348
- createViewToken,
349
- onViewableItemsChanged,
350
- );
351
- expect(onViewableItemsChanged.mock.calls.length).toBe(1);
352
- expect(onViewableItemsChanged.mock.calls[0][0]).toEqual({
353
- changed: [{isViewable: true, key: 'a'}],
354
- viewableItems: [{isViewable: true, key: 'a'}],
355
- });
356
- }
357
- );
358
-
359
- });
@@ -1,74 +0,0 @@
1
- /**
2
- * Copyright (c) 2015-present, Facebook, Inc.
3
- * All rights reserved.
4
- *
5
- * This source code is licensed under the BSD-style license found in the
6
- * LICENSE file in the root directory of this source tree. An additional grant
7
- * of patent rights can be found in the PATENTS file in the same directory.
8
- *
9
- */
10
- 'use strict';
11
-
12
- jest.unmock('VirtualizeUtils');
13
-
14
- const { elementsThatOverlapOffsets, newRangeCount } = require('VirtualizeUtils');
15
-
16
- describe('newRangeCount', function() {
17
- it('handles subset', function() {
18
- expect(newRangeCount({first: 1, last: 4}, {first: 2, last: 3})).toBe(0);
19
- });
20
- it('handles forward disjoint set', function() {
21
- expect(newRangeCount({first: 1, last: 4}, {first: 6, last: 9})).toBe(4);
22
- });
23
- it('handles reverse disjoint set', function() {
24
- expect(newRangeCount({first: 6, last: 8}, {first: 1, last: 4})).toBe(4);
25
- });
26
- it('handles superset', function() {
27
- expect(newRangeCount({first: 1, last: 4}, {first: 0, last: 5})).toBe(2);
28
- });
29
- it('handles end extension', function() {
30
- expect(newRangeCount({first: 1, last: 4}, {first: 1, last: 8})).toBe(4);
31
- });
32
- it('handles front extension', function() {
33
- expect(newRangeCount({first: 1, last: 4}, {first: 0, last: 4})).toBe(1);
34
- });
35
- it('handles forward insersect', function() {
36
- expect(newRangeCount({first: 1, last: 4}, {first: 3, last: 6})).toBe(2);
37
- });
38
- it('handles reverse intersect', function() {
39
- expect(newRangeCount({first: 3, last: 6}, {first: 1, last: 4})).toBe(2);
40
- });
41
- });
42
-
43
- describe('elementsThatOverlapOffsets', function() {
44
- it('handles fixed length', function() {
45
- const offsets = [0, 250, 350, 450];
46
- function getFrameMetrics(index: number) {
47
- return {
48
- length: 100,
49
- offset: (100 * index),
50
- };
51
- }
52
- expect(elementsThatOverlapOffsets(offsets, 100, getFrameMetrics)).toEqual([0, 2, 3, 4]);
53
- });
54
- it('handles variable length', function() {
55
- const offsets = [150, 250, 900];
56
- const frames = [
57
- {offset: 0, length: 50},
58
- {offset: 50, length: 200},
59
- {offset: 250, length: 600},
60
- {offset: 850, length: 100},
61
- {offset: 950, length: 150},
62
- ];
63
- expect(elementsThatOverlapOffsets(offsets, frames.length, (ii) => frames[ii])).toEqual([1,1,3]);
64
- });
65
- it('handles out of bounds', function() {
66
- const offsets = [150, 900];
67
- const frames = [
68
- {offset: 0, length: 50},
69
- {offset: 50, length: 150},
70
- {offset: 250, length: 100},
71
- ];
72
- expect(elementsThatOverlapOffsets(offsets, frames.length, (ii) => frames[ii])).toEqual([1]);
73
- });
74
- });