react-native-list 1.0.1 → 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 (190) hide show
  1. package/README.md +188 -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/MetroListView.js +0 -166
  185. package/SectionList.js +0 -291
  186. package/ViewabilityHelper.js +0 -260
  187. package/VirtualizeUtils.js +0 -163
  188. package/VirtualizedList.js +0 -861
  189. package/VirtualizedSectionList.js +0 -397
  190. package/index.js +0 -5
@@ -0,0 +1,8 @@
1
+ import { getHostComponent } from 'react-native-nitro-modules'
2
+ import { UiListViewMethods, UiListViewProps } from '../specs/UiListView.nitro'
3
+ import UiListViewConfig from '../../nitrogen/generated/shared/json/UiListViewConfig.json'
4
+
5
+ export const UiListHostComponent = getHostComponent<
6
+ UiListViewProps,
7
+ UiListViewMethods
8
+ >('UiListView', () => UiListViewConfig)
package/FillRateHelper.js DELETED
@@ -1,179 +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
- * @providesModule FillRateHelper
10
- * @flow
11
- */
12
-
13
- 'use strict';
14
-
15
- const performanceNow = require('fbjs/lib/performanceNow');
16
- const warning = require('fbjs/lib/warning');
17
-
18
- export type FillRateExceededInfo = {
19
- event: {
20
- sample_type: string,
21
- blankness: number,
22
- blank_pixels_top: number,
23
- blank_pixels_bottom: number,
24
- scroll_offset: number,
25
- visible_length: number,
26
- scroll_speed: number,
27
- first_frame: Object,
28
- last_frame: Object,
29
- },
30
- aggregate: {
31
- avg_blankness: number,
32
- min_speed_when_blank: number,
33
- avg_speed_when_blank: number,
34
- avg_blankness_when_any_blank: number,
35
- fraction_any_blank: number,
36
- all_samples_timespan_sec: number,
37
- fill_rate_sample_counts: {[key: string]: number},
38
- },
39
- };
40
-
41
- type FrameMetrics = {inLayout?: boolean, length: number, offset: number};
42
-
43
- let _listeners: Array<(FillRateExceededInfo) => void> = [];
44
- let _sampleRate = null;
45
-
46
- /**
47
- * A helper class for detecting when the maximem fill rate of `VirtualizedList` is exceeded.
48
- * By default the sampling rate is set to zero and this will do nothing. If you want to collect
49
- * samples (e.g. to log them), make sure to call `FillRateHelper.setSampleRate(0.0-1.0)`.
50
- *
51
- * Listeners and sample rate are global for all `VirtualizedList`s - typical usage will combine with
52
- * `SceneTracker.getActiveScene` to determine the context of the events.
53
- */
54
- class FillRateHelper {
55
- _getFrameMetrics: (index: number) => ?FrameMetrics;
56
- _anyBlankCount = 0;
57
- _anyBlankMinSpeed = Number.MAX_SAFE_INTEGER;
58
- _anyBlankSpeedSum = 0;
59
- _sampleCounts = {};
60
- _fractionBlankSum = 0;
61
- _samplesStartTime = 0;
62
-
63
- static addFillRateExceededListener(
64
- callback: (FillRateExceededInfo) => void
65
- ): {remove: () => void} {
66
- warning(
67
- _sampleRate !== null,
68
- 'Call `FillRateHelper.setSampleRate` before `addFillRateExceededListener`.'
69
- );
70
- _listeners.push(callback);
71
- return {
72
- remove: () => {
73
- _listeners = _listeners.filter((listener) => callback !== listener);
74
- },
75
- };
76
- }
77
-
78
- static setSampleRate(sampleRate: number) {
79
- _sampleRate = sampleRate;
80
- }
81
-
82
- static enabled(): boolean {
83
- return (_sampleRate || 0) > 0.0;
84
- }
85
-
86
- constructor(getFrameMetrics: (index: number) => ?FrameMetrics) {
87
- this._getFrameMetrics = getFrameMetrics;
88
- }
89
-
90
- computeInfoSampled(
91
- sampleType: string,
92
- props: {
93
- data: Array<any>,
94
- getItemCount: (data: Array<any>) => number,
95
- initialNumToRender: number,
96
- },
97
- state: {
98
- first: number,
99
- last: number,
100
- },
101
- scrollMetrics: {
102
- offset: number,
103
- velocity: number,
104
- visibleLength: number,
105
- },
106
- ): ?FillRateExceededInfo {
107
- if (!FillRateHelper.enabled() || (_sampleRate || 0) <= Math.random()) {
108
- return null;
109
- }
110
- const start = performanceNow();
111
- if (props.getItemCount(props.data) === 0) {
112
- return null;
113
- }
114
- if (!this._samplesStartTime) {
115
- this._samplesStartTime = start;
116
- }
117
- const {offset, velocity, visibleLength} = scrollMetrics;
118
- let blankTop = 0;
119
- let first = state.first;
120
- let firstFrame = this._getFrameMetrics(first);
121
- while (first <= state.last && (!firstFrame || !firstFrame.inLayout)) {
122
- firstFrame = this._getFrameMetrics(first);
123
- first++;
124
- }
125
- if (firstFrame) {
126
- blankTop = Math.min(visibleLength, Math.max(0, firstFrame.offset - offset));
127
- }
128
- let blankBottom = 0;
129
- let last = state.last;
130
- let lastFrame = this._getFrameMetrics(last);
131
- while (last >= state.first && (!lastFrame || !lastFrame.inLayout)) {
132
- lastFrame = this._getFrameMetrics(last);
133
- last--;
134
- }
135
- if (lastFrame) {
136
- const bottomEdge = lastFrame.offset + lastFrame.length;
137
- blankBottom = Math.min(visibleLength, Math.max(0, offset + visibleLength - bottomEdge));
138
- }
139
- this._sampleCounts.all = (this._sampleCounts.all || 0) + 1;
140
- this._sampleCounts[sampleType] = (this._sampleCounts[sampleType] || 0) + 1;
141
- const blankness = (blankTop + blankBottom) / visibleLength;
142
- if (blankness > 0) {
143
- const scrollSpeed = Math.abs(velocity);
144
- if (scrollSpeed && sampleType === 'onScroll') {
145
- this._anyBlankMinSpeed = Math.min(this._anyBlankMinSpeed, scrollSpeed);
146
- }
147
- this._anyBlankSpeedSum += scrollSpeed;
148
- this._anyBlankCount++;
149
- this._fractionBlankSum += blankness;
150
- const event = {
151
- sample_type: sampleType,
152
- blankness: blankness,
153
- blank_pixels_top: blankTop,
154
- blank_pixels_bottom: blankBottom,
155
- scroll_offset: offset,
156
- visible_length: visibleLength,
157
- scroll_speed: scrollSpeed,
158
- first_frame: {...firstFrame},
159
- last_frame: {...lastFrame},
160
- };
161
- const aggregate = {
162
- avg_blankness: this._fractionBlankSum / this._sampleCounts.all,
163
- min_speed_when_blank: this._anyBlankMinSpeed,
164
- avg_speed_when_blank: this._anyBlankSpeedSum / this._anyBlankCount,
165
- avg_blankness_when_any_blank: this._fractionBlankSum / this._anyBlankCount,
166
- fraction_any_blank: this._anyBlankCount / this._sampleCounts.all,
167
- all_samples_timespan_sec: (performanceNow() - this._samplesStartTime) / 1000.0,
168
- fill_rate_sample_counts: {...this._sampleCounts},
169
- compute_time: performanceNow() - start,
170
- };
171
- const info = {event, aggregate};
172
- _listeners.forEach((listener) => listener(info));
173
- return info;
174
- }
175
- return null;
176
- }
177
- }
178
-
179
- module.exports = FillRateHelper;
package/FlatList.js DELETED
@@ -1,494 +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
- * @providesModule FlatList
10
- * @flow
11
- */
12
- 'use strict';
13
-
14
- const MetroListView = require('MetroListView'); // Used as a fallback legacy option
15
- const React = require('React');
16
- const View = require('View');
17
- const VirtualizedList = require('VirtualizedList');
18
-
19
- const invariant = require('fbjs/lib/invariant');
20
-
21
- import type {StyleObj} from 'StyleSheetTypes';
22
- import type {ViewabilityConfig, ViewToken} from './ViewabilityHelper';
23
- import type {Props as VirtualizedListProps} from 'VirtualizedList';
24
-
25
- type RequiredProps<ItemT> = {
26
- /**
27
- * Takes an item from `data` and renders it into the list. Example usage:
28
- *
29
- * <FlatList
30
- * ItemSeparatorComponent={Platform.OS !== 'android' && ({highlighted}) => (
31
- * <View style={[style.separator, highlighted && {marginLeft: 0}]} />
32
- * )}
33
- * data={[{title: 'Title Text', key: 'item1'}]}
34
- * renderItem={({item, separators}) => (
35
- * <TouchableHighlight
36
- * onPress={() => this._onPress(item)}
37
- * onShowUnderlay={separators.highlight}
38
- * onHideUnderlay={separators.unhighlight}>
39
- * <View style={{backgroundColor: 'white'}}>
40
- * <Text>{item.title}}</Text>
41
- * </View>
42
- * </TouchableHighlight>
43
- * )}
44
- * />
45
- *
46
- * Provides additional metadata like `index` if you need it, as well as a more generic
47
- * `separators.updateProps` function which let's you set whatever props you want to change the
48
- * rendering of either the leading separator or trailing separator in case the more common
49
- * `highlight` and `unhighlight` (which set the `highlighted: boolean` prop) are insufficient for
50
- * your use-case.
51
- */
52
- renderItem: (info: {
53
- item: ItemT,
54
- index: number,
55
- separators: {
56
- highlight: () => void,
57
- unhighlight: () => void,
58
- updateProps: (select: 'leading' | 'trailing', newProps: Object) => void,
59
- },
60
- }) => ?React.Element<any>,
61
- /**
62
- * For simplicity, data is just a plain array. If you want to use something else, like an
63
- * immutable list, use the underlying `VirtualizedList` directly.
64
- */
65
- data: ?Array<ItemT>,
66
- };
67
- type OptionalProps<ItemT> = {
68
- /**
69
- * Rendered in between each item, but not at the top or bottom. By default, `highlighted` and
70
- * `leadingItem` props are provided. `renderItem` provides `separators.highlight`/`unhighlight`
71
- * which will update the `highlighted` prop, but you can also add custom props with
72
- * `separators.updateProps`.
73
- */
74
- ItemSeparatorComponent?: ?ReactClass<any>,
75
- /**
76
- * Rendered at the bottom of all the items. Can be a React Component Class, a render function, or
77
- * a rendered element.
78
- */
79
- ListFooterComponent?: ?(ReactClass<any> | React.Element<any>),
80
- /**
81
- * Rendered at the top of all the items. Can be a React Component Class, a render function, or
82
- * a rendered element.
83
- */
84
- ListHeaderComponent?: ?(ReactClass<any> | React.Element<any>),
85
- /**
86
- * Optional custom style for multi-item rows generated when numColumns > 1.
87
- */
88
- columnWrapperStyle?: StyleObj,
89
- /**
90
- * A marker property for telling the list to re-render (since it implements `PureComponent`). If
91
- * any of your `renderItem`, Header, Footer, etc. functions depend on anything outside of the
92
- * `data` prop, stick it here and treat it immutably.
93
- */
94
- extraData?: any,
95
- /**
96
- * `getItemLayout` is an optional optimizations that let us skip measurement of dynamic content if
97
- * you know the height of items a priori. `getItemLayout` is the most efficient, and is easy to
98
- * use if you have fixed height items, for example:
99
- *
100
- * getItemLayout={(data, index) => (
101
- * {length: ITEM_HEIGHT, offset: ITEM_HEIGHT * index, index}
102
- * )}
103
- *
104
- * Remember to include separator length (height or width) in your offset calculation if you
105
- * specify `ItemSeparatorComponent`.
106
- */
107
- getItemLayout?: (data: ?Array<ItemT>, index: number) =>
108
- {length: number, offset: number, index: number},
109
- /**
110
- * If true, renders items next to each other horizontally instead of stacked vertically.
111
- */
112
- horizontal?: ?boolean,
113
- /**
114
- * How many items to render in the initial batch. This should be enough to fill the screen but not
115
- * much more. Note these items will never be unmounted as part of the windowed rendering in order
116
- * to improve perceived performance of scroll-to-top actions.
117
- */
118
- initialNumToRender: number,
119
- /**
120
- * Used to extract a unique key for a given item at the specified index. Key is used for caching
121
- * and as the react key to track item re-ordering. The default extractor checks `item.key`, then
122
- * falls back to using the index, like React does.
123
- */
124
- keyExtractor: (item: ItemT, index: number) => string,
125
- /**
126
- * Multiple columns can only be rendered with `horizontal={false}` and will zig-zag like a
127
- * `flexWrap` layout. Items should all be the same height - masonry layouts are not supported.
128
- */
129
- numColumns: number,
130
- /**
131
- * Called once when the scroll position gets within `onEndReachedThreshold` of the rendered
132
- * content.
133
- */
134
- onEndReached?: ?(info: {distanceFromEnd: number}) => void,
135
- /**
136
- * How far from the end (in units of visible length of the list) the bottom edge of the
137
- * list must be from the end of the content to trigger the `onEndReached` callback.
138
- * Thus a value of 0.5 will trigger `onEndReached` when the end of the content is
139
- * within half the visible length of the list.
140
- */
141
- onEndReachedThreshold?: ?number,
142
- /**
143
- * If provided, a standard RefreshControl will be added for "Pull to Refresh" functionality. Make
144
- * sure to also set the `refreshing` prop correctly.
145
- */
146
- onRefresh?: ?() => void,
147
- /**
148
- * Called when the viewability of rows changes, as defined by the `viewabilityConfig` prop.
149
- */
150
- onViewableItemsChanged?: ?(info: {
151
- viewableItems: Array<ViewToken>,
152
- changed: Array<ViewToken>,
153
- }) => void,
154
- legacyImplementation?: ?boolean,
155
- /**
156
- * Set this true while waiting for new data from a refresh.
157
- */
158
- refreshing?: ?boolean,
159
- /**
160
- * Note: may have bugs (missing content) in some circumstances - use at your own risk.
161
- *
162
- * This may improve scroll performance for large lists.
163
- */
164
- removeClippedSubviews?: boolean,
165
- /**
166
- * See `ViewabilityHelper` for flow type and further documentation.
167
- */
168
- viewabilityConfig?: ViewabilityConfig,
169
- };
170
- type Props<ItemT> = RequiredProps<ItemT> & OptionalProps<ItemT> & VirtualizedListProps;
171
-
172
- const defaultProps = {
173
- ...VirtualizedList.defaultProps,
174
- getItem: undefined,
175
- getItemCount: undefined,
176
- numColumns: 1,
177
- };
178
- type DefaultProps = typeof defaultProps;
179
-
180
- /**
181
- * A performant interface for rendering simple, flat lists, supporting the most handy features:
182
- *
183
- * - Fully cross-platform.
184
- * - Optional horizontal mode.
185
- * - Configurable viewability callbacks.
186
- * - Header support.
187
- * - Footer support.
188
- * - Separator support.
189
- * - Pull to Refresh.
190
- * - Scroll loading.
191
- * - ScrollToIndex support.
192
- *
193
- * If you need section support, use [`<SectionList>`](docs/sectionlist.html).
194
- *
195
- * Minimal Example:
196
- *
197
- * <FlatList
198
- * data={[{key: 'a'}, {key: 'b'}]}
199
- * renderItem={({item}) => <Text>{item.key}</Text>}
200
- * />
201
- *
202
- * More complex example demonstrating `PureComponent` usage for perf optimization and avoiding bugs.
203
- *
204
- * - By binding the `onPressItem` handler, the props will remain `===` and `PureComponent` will
205
- * prevent wasteful re-renders unless the actual `id`, `selected`, or `title` props change, even
206
- * if the inner `SomeOtherWidget` has no such optimizations.
207
- * - By passing `extraData={this.state}` to `FlatList` we make sure `FlatList` itself will re-render
208
- * when the `state.selected` changes. Without setting this prop, `FlatList` would not know it
209
- * needs to re-render any items because it is also a `PureComponent` and the prop comparison will
210
- * not show any changes.
211
- * - `keyExtractor` tells the list to use the `id`s for the react keys.
212
- *
213
- *
214
- * class MyListItem extends React.PureComponent {
215
- * _onPress = () => {
216
- * this.props.onPressItem(this.props.id);
217
- * };
218
- *
219
- * render() {
220
- * return (
221
- * <SomeOtherWidget
222
- * {...this.props}
223
- * onPress={this._onPress}
224
- * />
225
- * )
226
- * }
227
- * }
228
- *
229
- * class MyList extends React.PureComponent {
230
- * state = {selected: (new Map(): Map<string, boolean>)};
231
- *
232
- * _keyExtractor = (item, index) => item.id;
233
- *
234
- * _onPressItem = (id: string) => {
235
- * // updater functions are preferred for transactional updates
236
- * this.setState((state) => {
237
- * // copy the map rather than modifying state.
238
- * const selected = new Map(state.selected);
239
- * selected.set(id, !state.get(id)); // toggle
240
- * return {selected};
241
- * });
242
- * };
243
- *
244
- * _renderItem = ({item}) => (
245
- * <MyListItem
246
- * id={item.id}
247
- * onPressItem={this._onPressItem}
248
- * selected={!!this.state.selected.get(item.id)}
249
- * title={item.title}
250
- * />
251
- * );
252
- *
253
- * render() {
254
- * return (
255
- * <FlatList
256
- * data={this.props.data}
257
- * extraData={this.state}
258
- * keyExtractor={this._keyExtractor}
259
- * renderItem={this._renderItem}
260
- * />
261
- * );
262
- * }
263
- * }
264
- *
265
- * This is a convenience wrapper around [`<VirtualizedList>`](docs/virtualizedlist.html),
266
- * and thus inherits it's props (as well as those of `ScrollView`) that aren't explicitly listed
267
- * here, along with the following caveats:
268
- *
269
- * - Internal state is not preserved when content scrolls out of the render window. Make sure all
270
- * your data is captured in the item data or external stores like Flux, Redux, or Relay.
271
- * - This is a `PureComponent` which means that it will not re-render if `props` remain shallow-
272
- * equal. Make sure that everything your `renderItem` function depends on is passed as a prop
273
- * (e.g. `extraData`) that is not `===` after updates, otherwise your UI may not update on
274
- * changes. This includes the `data` prop and parent component state.
275
- * - In order to constrain memory and enable smooth scrolling, content is rendered asynchronously
276
- * offscreen. This means it's possible to scroll faster than the fill rate ands momentarily see
277
- * blank content. This is a tradeoff that can be adjusted to suit the needs of each application,
278
- * and we are working on improving it behind the scenes.
279
- * - By default, the list looks for a `key` prop on each item and uses that for the React key.
280
- * Alternatively, you can provide a custom `keyExtractor` prop.
281
- *
282
- */
283
- class FlatList<ItemT> extends React.PureComponent<DefaultProps, Props<ItemT>, void> {
284
- static defaultProps: DefaultProps = defaultProps;
285
- props: Props<ItemT>;
286
- /**
287
- * Scrolls to the end of the content. May be janky without `getItemLayout` prop.
288
- */
289
- scrollToEnd(params?: ?{animated?: ?boolean}) {
290
- this._listRef.scrollToEnd(params);
291
- }
292
-
293
- /**
294
- * Scrolls to the item at a the specified index such that it is positioned in the viewable area
295
- * such that `viewPosition` 0 places it at the top, 1 at the bottom, and 0.5 centered in the
296
- * middle. `viewOffset` is a fixed number of pixels to offset the final target position.
297
- *
298
- * Note: cannot scroll to locations outside the render window without specifying the
299
- * `getItemLayout` prop.
300
- */
301
- scrollToIndex(params: {
302
- animated?: ?boolean, index: number, viewOffset?: number, viewPosition?: number,
303
- }) {
304
- this._listRef.scrollToIndex(params);
305
- }
306
-
307
- /**
308
- * Requires linear scan through data - use `scrollToIndex` instead if possible.
309
- *
310
- * Note: cannot scroll to locations outside the render window without specifying the
311
- * `getItemLayout` prop.
312
- */
313
- scrollToItem(params: {animated?: ?boolean, item: ItemT, viewPosition?: number}) {
314
- this._listRef.scrollToItem(params);
315
- }
316
-
317
- /**
318
- * Scroll to a specific content pixel offset, like a normal `ScrollView`.
319
- */
320
- scrollToOffset(params: {animated?: ?boolean, offset: number}) {
321
- this._listRef.scrollToOffset(params);
322
- }
323
-
324
- /**
325
- * Tells the list an interaction has occured, which should trigger viewability calculations, e.g.
326
- * if `waitForInteractions` is true and the user has not scrolled. This is typically called by
327
- * taps on items or by navigation actions.
328
- */
329
- recordInteraction() {
330
- this._listRef.recordInteraction();
331
- }
332
-
333
- /**
334
- * Provides a handle to the underlying scroll responder.
335
- */
336
- getScrollResponder() {
337
- if (this._listRef) {
338
- return this._listRef.getScrollResponder();
339
- }
340
- }
341
-
342
- getScrollableNode() {
343
- if (this._listRef) {
344
- return this._listRef.getScrollableNode();
345
- }
346
- }
347
-
348
- componentWillMount() {
349
- this._checkProps(this.props);
350
- }
351
-
352
- componentWillReceiveProps(nextProps: Props<ItemT>) {
353
- invariant(
354
- nextProps.numColumns === this.props.numColumns,
355
- 'Changing numColumns on the fly is not supported. Change the key prop on FlatList when ' +
356
- 'changing the number of columns to force a fresh render of the component.'
357
- );
358
- this._checkProps(nextProps);
359
- }
360
-
361
- _hasWarnedLegacy = false;
362
- _listRef: VirtualizedList;
363
-
364
- _captureRef = (ref) => { this._listRef = ref; };
365
-
366
- _checkProps(props: Props<ItemT>) {
367
- const {
368
- getItem,
369
- getItemCount,
370
- horizontal,
371
- legacyImplementation,
372
- numColumns,
373
- columnWrapperStyle,
374
- } = props;
375
- invariant(!getItem && !getItemCount, 'FlatList does not support custom data formats.');
376
- if (numColumns > 1) {
377
- invariant(!horizontal, 'numColumns does not support horizontal.');
378
- } else {
379
- invariant(!columnWrapperStyle, 'columnWrapperStyle not supported for single column lists');
380
- }
381
- if (legacyImplementation) {
382
- invariant(numColumns === 1, 'Legacy list does not support multiple columns.');
383
- // Warning: may not have full feature parity and is meant more for debugging and performance
384
- // comparison.
385
- if (!this._hasWarnedLegacy) {
386
- console.warn(
387
- 'FlatList: Using legacyImplementation - some features not supported and performance ' +
388
- 'may suffer'
389
- );
390
- this._hasWarnedLegacy = true;
391
- }
392
- }
393
- }
394
-
395
- _getItem = (data: Array<ItemT>, index: number) => {
396
- const {numColumns} = this.props;
397
- if (numColumns > 1) {
398
- const ret = [];
399
- for (let kk = 0; kk < numColumns; kk++) {
400
- const item = data[index * numColumns + kk];
401
- item && ret.push(item);
402
- }
403
- return ret;
404
- } else {
405
- return data[index];
406
- }
407
- };
408
-
409
- _getItemCount = (data: ?Array<ItemT>): number => {
410
- return data ? Math.ceil(data.length / this.props.numColumns) : 0;
411
- };
412
-
413
- _keyExtractor = (items: ItemT | Array<ItemT>, index: number) => {
414
- const {keyExtractor, numColumns} = this.props;
415
- if (numColumns > 1) {
416
- invariant(
417
- Array.isArray(items),
418
- 'FlatList: Encountered internal consistency error, expected each item to consist of an ' +
419
- 'array with 1-%s columns; instead, received a single item.',
420
- numColumns,
421
- );
422
- return items.map((it, kk) => keyExtractor(it, index * numColumns + kk)).join(':');
423
- } else {
424
- return keyExtractor(items, index);
425
- }
426
- };
427
-
428
- _pushMultiColumnViewable(arr: Array<ViewToken>, v: ViewToken): void {
429
- const {numColumns, keyExtractor} = this.props;
430
- v.item.forEach((item, ii) => {
431
- invariant(v.index != null, 'Missing index!');
432
- const index = v.index * numColumns + ii;
433
- arr.push({...v, item, key: keyExtractor(item, index), index});
434
- });
435
- }
436
-
437
- _onViewableItemsChanged = (info) => {
438
- const {numColumns, onViewableItemsChanged} = this.props;
439
- if (!onViewableItemsChanged) {
440
- return;
441
- }
442
- if (numColumns > 1) {
443
- const changed = [];
444
- const viewableItems = [];
445
- info.viewableItems.forEach((v) => this._pushMultiColumnViewable(viewableItems, v));
446
- info.changed.forEach((v) => this._pushMultiColumnViewable(changed, v));
447
- onViewableItemsChanged({viewableItems, changed});
448
- } else {
449
- onViewableItemsChanged(info);
450
- }
451
- };
452
-
453
- _renderItem = (info: Object) => {
454
- const {renderItem, numColumns, columnWrapperStyle} = this.props;
455
- if (numColumns > 1) {
456
- const {item, index} = info;
457
- invariant(Array.isArray(item), 'Expected array of items with numColumns > 1');
458
- return (
459
- <View style={[{flexDirection: 'row'}, columnWrapperStyle]}>
460
- {item.map((it, kk) => {
461
- const element = renderItem({
462
- item: it,
463
- index: index * numColumns + kk,
464
- separators: info.separators,
465
- });
466
- return element && React.cloneElement(element, {key: kk});
467
- })}
468
- </View>
469
- );
470
- } else {
471
- return renderItem(info);
472
- }
473
- };
474
-
475
- render() {
476
- if (this.props.legacyImplementation) {
477
- return <MetroListView {...this.props} items={this.props.data} ref={this._captureRef} />;
478
- } else {
479
- return (
480
- <VirtualizedList
481
- {...this.props}
482
- renderItem={this._renderItem}
483
- getItem={this._getItem}
484
- getItemCount={this._getItemCount}
485
- keyExtractor={this._keyExtractor}
486
- ref={this._captureRef}
487
- onViewableItemsChanged={this.props.onViewableItemsChanged && this._onViewableItemsChanged}
488
- />
489
- );
490
- }
491
- }
492
- }
493
-
494
- module.exports = FlatList;